From 3423bbf67168859d53ed4543bd91cfc74f7fc4c0 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 20 Dec 2024 18:57:45 +0530 Subject: [PATCH 01/22] Added support for Android 15. --- build.gradle.kts | 1 + buildSrc/build.gradle.kts | 3 ++- buildSrc/src/main/kotlin/Config.kt | 6 +++--- buildSrc/src/main/kotlin/Libs.kt | 3 +++ buildSrc/src/main/kotlin/Versions.kt | 14 ++++++++------ .../src/main/kotlin/plugin/AllProjectConfigurer.kt | 11 ++++++----- .../main/kotlin/plugin/ConvenienceExtensions.kt | 3 +++ core/build.gradle.kts | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 792b02bbe..e5c5dbcd0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,7 @@ buildscript { dependencies { classpath(Libs.com_android_tools_build_gradle) classpath(Libs.kotlin_gradle_plugin) + classpath(Libs.kotlin_ksp) classpath(Libs.navigation_safe_args_gradle_plugin) classpath(Libs.keeper) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index b174f55a7..40967373a 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -11,8 +11,9 @@ repositories { } dependencies { - implementation("com.android.tools.build:gradle:8.1.3") + implementation("com.android.tools.build:gradle:8.4.0") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0") + implementation("com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:2.1.0-1.0.29") implementation("org.jacoco:org.jacoco.core:0.8.12") implementation("org.jlleitschuh.gradle:ktlint-gradle:10.3.0") implementation("com.google.apis:google-api-services-androidpublisher:v3-rev20230406-2.0.0") { diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index e6f6facfe..75eb961cf 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -22,11 +22,11 @@ object Config { // Here is a list of all Android versions with their corresponding API // levels: https://apilevels.com/ - const val compileSdk = 34 // SDK version used by Gradle to compile our app. + const val compileSdk = 35 // SDK version used by Gradle to compile our app. const val minSdk = 25 // Minimum SDK (Minimum Support Device) is 25 (Android 7.1 Nougat). - const val targetSdk = 34 // Target SDK (Maximum Support Device) is 34 (Android 14). + const val targetSdk = 35 // Target SDK (Maximum Support Device) is 34 (Android 14). - val javaVersion = JavaVersion.VERSION_1_8 + val javaVersion = JavaVersion.VERSION_17 // Version Information const val versionMajor = 3 // Major version component of the app's version name and version code. diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 232bb99d5..487895910 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -104,6 +104,9 @@ object Libs { const val kotlin_stdlib_jdk8: String = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:" + Versions.org_jetbrains_kotlin + const val kotlin_ksp: String = + "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:" + Versions.kotlin_ksp + /** * https://developer.android.com/topic/libraries/architecture/index.html */ diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index c23818e29..bb664ad7e 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -14,7 +14,7 @@ object Versions { const val document_file_version: String = "1.0.1" - const val org_jetbrains_kotlinx_kotlinx_coroutines: String = "1.8.1" + const val org_jetbrains_kotlinx_kotlinx_coroutines: String = "1.9.0" const val kotlinx_coroutines_rx3: String = "1.3.9" @@ -28,6 +28,8 @@ object Versions { const val org_jetbrains_kotlin: String = "2.0.0" + const val kotlin_ksp: String = "2.1.0-1.0.29" + const val androidx_navigation: String = "2.5.3" const val navigation_ui_ktx: String = "2.4.1" @@ -46,7 +48,7 @@ object Versions { const val android_arch_lifecycle_extensions: String = "1.1.1" - const val com_android_tools_build_gradle: String = "8.1.3" + const val com_android_tools_build_gradle: String = "8.4.0" const val de_fayard_buildsrcversions_gradle_plugin: String = "0.7.0" @@ -60,9 +62,9 @@ object Versions { const val swipe_refresh_layout: String = "1.1.0" - const val collection_ktx: String = "1.1.0" + const val collection_ktx: String = "1.4.5" - const val preference_ktx: String = "1.2.0" + const val preference_ktx: String = "1.2.1" const val junit_jupiter: String = "5.11.0" @@ -70,7 +72,7 @@ object Versions { const val core_testing: String = "2.2.0" - const val fragment_ktx: String = "1.2.5" + const val fragment_ktx: String = "1.8.5" const val testing_ktx: String = "1.3.0" @@ -86,7 +88,7 @@ object Versions { const val rxandroid: String = "2.1.1" - const val core_ktx: String = "1.9.0" + const val core_ktx: String = "1.15.0" const val libkiwix: String = "2.2.3" diff --git a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt index a87f9f4d3..f90c0f340 100644 --- a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt +++ b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt @@ -37,6 +37,7 @@ class AllProjectConfigurer { fun applyPlugins(target: Project) { target.plugins.apply("kotlin-android") target.plugins.apply("kotlin-kapt") + target.plugins.apply("com.google.devtools.ksp") target.plugins.apply("kotlin-parcelize") target.plugins.apply("jacoco") target.plugins.apply("org.jlleitschuh.gradle.ktlint") @@ -77,7 +78,7 @@ class AllProjectConfigurer { } target.tasks.withType(KotlinCompile::class.java) { compilerOptions { - jvmTarget.set(JvmTarget.JVM_1_8) + jvmTarget.set(JvmTarget.JVM_17) freeCompilerArgs.add("-Xjvm-default=all-compatibility") } } @@ -137,7 +138,7 @@ class AllProjectConfigurer { } fun configureCommonExtension(target: Project) { - target.configureExtension> { + target.configureExtension> { lint { abortOnError = true checkAllWarnings = true @@ -216,8 +217,8 @@ class AllProjectConfigurer { compileOnly(Libs.javax_annotation_api) implementation(Libs.dagger) implementation(Libs.dagger_android) - kapt(Libs.dagger_compiler) - kapt(Libs.dagger_android_processor) + annotationProcessor(Libs.dagger_compiler) + annotationProcessor(Libs.dagger_android_processor) implementation(Libs.core_ktx) implementation(Libs.fragment_ktx) implementation(Libs.collection_ktx) @@ -229,7 +230,7 @@ class AllProjectConfigurer { annotationProcessor(Libs.roomCompiler) implementation(Libs.roomRuntime) implementation(Libs.roomRxjava2) - kapt(Libs.roomCompiler) + ksp(Libs.roomCompiler) implementation(Libs.tracing) implementation(Libs.fetchOkhttp) } diff --git a/buildSrc/src/main/kotlin/plugin/ConvenienceExtensions.kt b/buildSrc/src/main/kotlin/plugin/ConvenienceExtensions.kt index 0a397888d..fb6f64721 100644 --- a/buildSrc/src/main/kotlin/plugin/ConvenienceExtensions.kt +++ b/buildSrc/src/main/kotlin/plugin/ConvenienceExtensions.kt @@ -48,6 +48,9 @@ internal fun DependencyHandlerScope.compileOnly(dependency: String) = internal fun DependencyHandlerScope.kapt(dependency: String) = addDependency("kapt", dependency) +internal fun DependencyHandlerScope.ksp(dependency: String) = + addDependency("ksp", dependency) + internal fun DependencyHandlerScope.testImplementation(dependency: String) = addDependency("testImplementation", dependency) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 1d61d4aee..ffa77eac9 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,3 +1,4 @@ +import com.android.build.gradle.internal.utils.isKotlinKaptPluginApplied import plugin.KiwixConfigurationPlugin buildscript { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f1aa9a835..d190455a7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Dec 19 16:13:45 IST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From 08c054586ae22bcbb157d6af54275a143a97e8e2 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 2 Jan 2025 12:04:54 +0530 Subject: [PATCH 02/22] Upgraded the dagger version to 2.53.1. * Upgraded the ksp version to `2.0.0-1.0.24`. * Upgraded the kotlin version to `2.0.0`. * Upgraded the objectbox version to `4.0.3`. * Removed the deprecated `runBlockingTest` from test cases which was giving compilation error because it is permanently removed in this version of kotlin. * Replaced some deprecated methods with new methods that is deprecated in latest version of gradle. * Fixed some string lint issues. --- .../kiwix/kiwixmobile/testutils/TestUtils.kt | 5 ---- .../zimManager/ZimManageViewModelTest.kt | 8 ++--- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Versions.kt | 2 +- .../kotlin/plugin/AllProjectConfigurer.kt | 6 ++-- core/build.gradle.kts | 1 - .../utils/storage/StorageDeviceUtils.kt | 4 +-- .../base/adapter/AdapterDelegateManager.kt | 2 +- .../kiwixmobile/core/error/ErrorActivity.kt | 7 ++--- .../core/main/CoreReaderFragment.kt | 4 +-- .../core/settings/CorePrefsFragment.kt | 2 +- .../core/utils/SharedPreferenceUtil.kt | 2 +- .../kiwixmobile/core/utils/files/FileUtils.kt | 3 +- core/src/main/res/values-qq/strings.xml | 2 +- .../core/dao/NewRecentSearchDaoTest.kt | 10 +++---- .../search/viewmodel/SearchViewModelTest.kt | 30 +++++++++---------- .../custom/main/CustomFileValidator.kt | 5 ++-- lintConfig.xml | 2 +- 18 files changed, 42 insertions(+), 55 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt index 3b7127692..c6c55613c 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt @@ -25,7 +25,6 @@ import android.content.pm.PackageManager import android.graphics.Bitmap import android.os.Build import android.os.Environment -import androidx.annotation.RequiresApi import androidx.core.content.ContextCompat import androidx.test.core.app.canTakeScreenshot import androidx.test.core.app.takeScreenshot @@ -91,10 +90,6 @@ object TestUtils { Manifest.permission.WRITE_EXTERNAL_STORAGE ) == PackageManager.PERMISSION_GRANTED - @RequiresApi(Build.VERSION_CODES.R) - private fun hasManageExternalStoragePermission(): Boolean = - Environment.isExternalStorageManager() - @JvmStatic fun hasStoragePermission() = Build.VERSION.SDK_INT > Build.VERSION_CODES.M && hasReadExternalStoragePermission() && hasWriteExternalStoragePermission() diff --git a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt index c4d3c09db..b2b1bd54d 100644 --- a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt +++ b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt @@ -51,6 +51,8 @@ import org.kiwix.kiwixmobile.core.utils.files.ScanningProgressListener import org.kiwix.kiwixmobile.core.zim_manager.ConnectivityBroadcastReceiver import org.kiwix.kiwixmobile.core.zim_manager.Language import org.kiwix.kiwixmobile.core.zim_manager.NetworkState +import org.kiwix.kiwixmobile.core.zim_manager.NetworkState.CONNECTED +import org.kiwix.kiwixmobile.core.zim_manager.NetworkState.NOT_CONNECTED import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.MULTI import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.NORMAL import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem @@ -58,8 +60,6 @@ import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDis import org.kiwix.kiwixmobile.zimManager.Fat32Checker.FileSystemState import org.kiwix.kiwixmobile.zimManager.Fat32Checker.FileSystemState.CanWrite4GbFile import org.kiwix.kiwixmobile.zimManager.Fat32Checker.FileSystemState.CannotWrite4GbFile -import org.kiwix.kiwixmobile.core.zim_manager.NetworkState.CONNECTED -import org.kiwix.kiwixmobile.core.zim_manager.NetworkState.NOT_CONNECTED import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel.FileSelectActions.MultiModeFinished import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel.FileSelectActions.RequestDeleteMultiSelection import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel.FileSelectActions.RequestMultiSelection @@ -139,7 +139,7 @@ class ZimManageViewModelTest { every { newLanguagesDao.languages() } returns languages every { fat32Checker.fileSystemStates } returns fileSystemStates every { connectivityBroadcastReceiver.networkStates } returns networkStates - every { application.registerReceiver(any(), any()) } returns mockk() + every { application.registerReceiver(any(), any(), any()) } returns mockk() every { dataSource.booksOnDiskAsListItems() } returns booksOnDiskListItems every { connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork) @@ -168,7 +168,7 @@ class ZimManageViewModelTest { @Test fun `registers broadcastReceiver in init`() { verify { - application.registerReceiver(connectivityBroadcastReceiver, any()) + application.registerReceiver(connectivityBroadcastReceiver, any(), any()) } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 40967373a..b8c6df09d 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -13,7 +13,7 @@ repositories { dependencies { implementation("com.android.tools.build:gradle:8.4.0") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0") - implementation("com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:2.1.0-1.0.29") + implementation("com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:2.0.0-1.0.24") implementation("org.jacoco:org.jacoco.core:0.8.12") implementation("org.jlleitschuh.gradle:ktlint-gradle:10.3.0") implementation("com.google.apis:google-api-services-androidpublisher:v3-rev20230406-2.0.0") { diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index bb664ad7e..3c02b8cf8 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -28,7 +28,7 @@ object Versions { const val org_jetbrains_kotlin: String = "2.0.0" - const val kotlin_ksp: String = "2.1.0-1.0.29" + const val kotlin_ksp: String = "2.0.0-1.0.24" const val androidx_navigation: String = "2.5.3" diff --git a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt index f90c0f340..13daa7d14 100644 --- a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt +++ b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt @@ -217,8 +217,8 @@ class AllProjectConfigurer { compileOnly(Libs.javax_annotation_api) implementation(Libs.dagger) implementation(Libs.dagger_android) - annotationProcessor(Libs.dagger_compiler) - annotationProcessor(Libs.dagger_android_processor) + kapt(Libs.dagger_compiler) + kapt(Libs.dagger_android_processor) implementation(Libs.core_ktx) implementation(Libs.fragment_ktx) implementation(Libs.collection_ktx) @@ -230,7 +230,7 @@ class AllProjectConfigurer { annotationProcessor(Libs.roomCompiler) implementation(Libs.roomRuntime) implementation(Libs.roomRxjava2) - ksp(Libs.roomCompiler) + kapt(Libs.roomCompiler) implementation(Libs.tracing) implementation(Libs.fetchOkhttp) } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ffa77eac9..1d61d4aee 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,4 +1,3 @@ -import com.android.build.gradle.internal.utils.isKotlinKaptPluginApplied import plugin.KiwixConfigurationPlugin buildscript { diff --git a/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt b/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt index e2b56964d..62ccb01af 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt @@ -21,12 +21,10 @@ package eu.mhutti1.utils.storage import android.content.Context import android.content.ContextWrapper import android.os.Environment -import androidx.core.content.ContextCompat import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import java.io.File import java.io.FileFilter import java.io.RandomAccessFile -import java.util.ArrayList object StorageDeviceUtils { @JvmStatic @@ -63,7 +61,7 @@ object StorageDeviceUtils { private fun externalFilesDirsDevices( context: Context, writable: Boolean - ) = ContextCompat.getExternalFilesDirs(context, "") + ) = context.getExternalFilesDirs("") .filterNotNull() .mapIndexed { index, dir -> StorageDevice(generalisePath(dir.path, writable), index == 0) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/AdapterDelegateManager.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/AdapterDelegateManager.kt index 82a657fa4..4b6d30687 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/AdapterDelegateManager.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/AdapterDelegateManager.kt @@ -45,7 +45,7 @@ class AdapterDelegateManager { private fun getDelegateIndexFor(item: T): Int { for (index in 0..delegates.size()) { val valueAt = delegates.valueAt(index) - if (valueAt?.isFor(item) == true) { + if (valueAt.isFor(item) == true) { return index } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt index 2cd0d1f1f..19817ef02 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt @@ -24,7 +24,6 @@ import android.os.Build import android.os.Bundle import android.os.Process import androidx.activity.result.contract.ActivityResultContracts -import androidx.core.content.ContextCompat import androidx.core.content.FileProvider import androidx.lifecycle.lifecycleScope import kotlinx.coroutines.launch @@ -101,7 +100,7 @@ open class ErrorActivity : BaseActivity() { val targetedIntents = createEmailIntents(emailIntent, activities) if (activities.isNotEmpty() && targetedIntents.isNotEmpty()) { val chooserIntent = - Intent.createChooser(targetedIntents.removeFirst(), "Send email...") + Intent.createChooser(targetedIntents.removeAt(0), "Send email...") chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedIntents.toTypedArray()) sendEmailLauncher.launch(chooserIntent) } else { @@ -245,7 +244,7 @@ open class ErrorActivity : BaseActivity() { """.trimIndent() private fun externalFileDetails(): String = - ContextCompat.getExternalFilesDirs(this, null).joinToString("\n") { it?.path ?: "null" } + getExternalFilesDirs(null).joinToString("\n") { it?.path ?: "null" } private fun safeContains(extras: Bundle): Boolean { return try { @@ -272,7 +271,7 @@ open class ErrorActivity : BaseActivity() { private val versionName: String @SuppressLint("WrongConstant") get() = packageManager - .getPackageInformation(packageName, ZERO).versionName + .getPackageInformation(packageName, ZERO).versionName.toString() private fun toStackTraceString(exception: Throwable): String = try { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index 055f1d909..5a353ce2f 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -1869,9 +1869,9 @@ abstract class CoreReaderFragment : } reopenBook() showTabSwitcher() - setUpWithTextToSpeech(tempWebViewListForUndo.last()) + setUpWithTextToSpeech(tempWebViewListForUndo[tempWebViewListForUndo.lastIndex]) updateBottomToolbarVisibility() - safelyAddWebView(tempWebViewListForUndo.last()) + safelyAddWebView(tempWebViewListForUndo[tempWebViewListForUndo.lastIndex]) } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.kt index ac8638fd1..8278b8128 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/settings/CorePrefsFragment.kt @@ -229,7 +229,7 @@ abstract class CorePrefsFragment : @Suppress("TooGenericExceptionThrown") get() = try { requireActivity().packageManager - .getPackageInformation(requireActivity().packageName, 0).versionName + .getPackageInformation(requireActivity().packageName, 0).versionName.toString() } catch (e: PackageManager.NameNotFoundException) { throw RuntimeException(e) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt index 1e261a2fa..5556425b9 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/SharedPreferenceUtil.kt @@ -129,7 +129,7 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) { get() = sharedPreferences.getInt(STORAGE_POSITION, 0) fun defaultStorage(): String = - getExternalFilesDirs(context, null)[0]?.path + context.getExternalFilesDirs(null)[0]?.path ?: context.filesDir.path // a workaround for emulators fun defaultPublicStorage(): String = diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt index db3621797..b4d482946 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt @@ -30,7 +30,6 @@ import android.os.storage.StorageManager import android.provider.DocumentsContract import android.provider.MediaStore import android.webkit.URLUtil -import androidx.core.content.ContextCompat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -583,7 +582,7 @@ object FileUtils { @JvmStatic fun getDemoFilePathForCustomApp(context: Context) = - "${ContextCompat.getExternalFilesDirs(context, null)[0]}/demo.zim" + "${context.getExternalFilesDirs(null)[0]}/demo.zim" @SuppressLint("Recycle") @JvmStatic diff --git a/core/src/main/res/values-qq/strings.xml b/core/src/main/res/values-qq/strings.xml index 81084bde6..d75566233 100644 --- a/core/src/main/res/values-qq/strings.xml +++ b/core/src/main/res/values-qq/strings.xml @@ -143,7 +143,7 @@ This is a descriptive message explaining where the Zim files are located after downloading. It is showing on the help screen. {{Identical|Storage}} This is showing on the preference settings screen, it shows the currently selected storage in which we are downloading the zim files, whether it is internal or external. - This refers to free (unused) storage space, ’’not’’ to free as in free of charge. + This refers to free (unused) storage space, ’’not’’ to free as in free of charge. Here %s will be replaced by the free space e.g. 20GB. This message appears in the “Android Toast” as an error message. When there are some files that could not be deleted, due to some reason. {{identical|pause}} {{identical|resume}} diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewRecentSearchDaoTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewRecentSearchDaoTest.kt index 3463ba837..44ddfc7a2 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewRecentSearchDaoTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/dao/NewRecentSearchDaoTest.kt @@ -25,7 +25,7 @@ import io.objectbox.Box import io.objectbox.query.Query import io.objectbox.query.QueryBuilder import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchEntity @@ -43,7 +43,7 @@ internal class NewRecentSearchDaoTest { @Nested inner class RecentSearchTests { @Test - fun `recentSearches searches by Id passed`() = runBlockingTest { + fun `recentSearches searches by Id passed`() = runTest { val zimId = "id" val queryResult = listOf(recentSearchEntity()) expectFromRecentSearches(queryResult, zimId) @@ -56,7 +56,7 @@ internal class NewRecentSearchDaoTest { } @Test - fun `recentSearches searches with blank Id if null passed`() = runBlockingTest { + fun `recentSearches searches with blank Id if null passed`() = runTest { val queryResult = listOf(recentSearchEntity()) expectFromRecentSearches(queryResult, "") newRecentSearchDao.recentSearches(null) @@ -68,7 +68,7 @@ internal class NewRecentSearchDaoTest { } @Test - fun `recentSearches searches returns distinct entities by searchTerm`() = runBlockingTest { + fun `recentSearches searches returns distinct entities by searchTerm`() = runTest { val queryResult = listOf(recentSearchEntity(), recentSearchEntity()) expectFromRecentSearches(queryResult, "") newRecentSearchDao.recentSearches("") @@ -80,7 +80,7 @@ internal class NewRecentSearchDaoTest { } @Test - fun `recentSearches searches returns a limitedNumber of entities`() = runBlockingTest { + fun `recentSearches searches returns a limitedNumber of entities`() = runTest { val searchResults: List = (0..200).map { recentSearchEntity(searchTerm = "$it") } expectFromRecentSearches(searchResults, "") diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchViewModelTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchViewModelTest.kt index b214e7190..e72e764ed 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchViewModelTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchViewModelTest.kt @@ -33,11 +33,9 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.test.TestCoroutineDispatcher -import kotlinx.coroutines.test.TestCoroutineScope +import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.resetMain -import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import org.assertj.core.api.Assertions.assertThat @@ -84,7 +82,7 @@ internal class SearchViewModelTest { private val zimReaderContainer: ZimReaderContainer = mockk() private val searchResultGenerator: SearchResultGenerator = mockk() private val zimFileReader: ZimFileReader = mockk() - private val testDispatcher = TestCoroutineDispatcher() + private val testDispatcher = StandardTestDispatcher() private val searchMutex: Mutex = mockk() lateinit var viewModel: SearchViewModel @@ -115,7 +113,7 @@ internal class SearchViewModelTest { @Nested inner class StateTests { @Test - fun `initial state is Initialising`() = runBlockingTest { + fun `initial state is Initialising`() = runTest { viewModel.state.test(this).assertValue( SearchState("", SearchResultsWithTerm("", null, searchMutex), emptyList(), FromWebView) ).finish() @@ -152,12 +150,12 @@ internal class SearchViewModelTest { inner class ActionMapping { @Test - fun `ExitedSearch offers PopFragmentBackstack`() = runBlockingTest { + fun `ExitedSearch offers PopFragmentBackstack`() = runTest { actionResultsInEffects(ExitedSearch, PopFragmentBackstack) } @Test - fun `OnItemClick offers Saves and Opens`() = runBlockingTest { + fun `OnItemClick offers Saves and Opens`() = runTest { val searchListItem = RecentSearchListItem("", "") actionResultsInEffects( OnItemClick(searchListItem), @@ -170,7 +168,7 @@ internal class SearchViewModelTest { } @Test - fun `OnOpenInNewTabClick offers Saves and Opens in new tab`() = runBlockingTest { + fun `OnOpenInNewTabClick offers Saves and Opens in new tab`() = runTest { val searchListItem = RecentSearchListItem("", "") actionResultsInEffects( OnOpenInNewTabClick(searchListItem), @@ -183,7 +181,7 @@ internal class SearchViewModelTest { } @Test - fun `OnItemLongClick offers Saves and Opens`() = runBlockingTest { + fun `OnItemLongClick offers Saves and Opens`() = runTest { val searchListItem = RecentSearchListItem("", "") actionResultsInEffects( OnItemLongClick(searchListItem), @@ -192,12 +190,12 @@ internal class SearchViewModelTest { } @Test - fun `ClickedSearchInText offers SearchInPreviousScreen`() = runBlockingTest { + fun `ClickedSearchInText offers SearchInPreviousScreen`() = runTest { actionResultsInEffects(ClickedSearchInText, SearchInPreviousScreen("")) } @Test - fun `ConfirmedDelete offers Delete and Toast`() = runBlockingTest { + fun `ConfirmedDelete offers Delete and Toast`() = runTest { val searchListItem = RecentSearchListItem("", "") actionResultsInEffects( ConfirmedDelete(searchListItem), @@ -207,7 +205,7 @@ internal class SearchViewModelTest { } @Test - fun `CreatedWithArguments offers SearchArgumentProcessing`() = runBlockingTest { + fun `CreatedWithArguments offers SearchArgumentProcessing`() = runTest { val bundle = mockk() actionResultsInEffects( CreatedWithArguments(bundle), @@ -216,7 +214,7 @@ internal class SearchViewModelTest { } @Test - fun `ReceivedPromptForSpeechInput offers StartSpeechInput`() = runBlockingTest { + fun `ReceivedPromptForSpeechInput offers StartSpeechInput`() = runTest { actionResultsInEffects( ReceivedPromptForSpeechInput, StartSpeechInput(viewModel.actions) @@ -224,7 +222,7 @@ internal class SearchViewModelTest { } @Test - fun `StartSpeechInputFailed offers ShowToast`() = runBlockingTest { + fun `StartSpeechInputFailed offers ShowToast`() = runTest { actionResultsInEffects( StartSpeechInputFailed, ShowToast(string.speech_not_supported) @@ -232,14 +230,14 @@ internal class SearchViewModelTest { } @Test - fun `ActivityResultReceived offers ProcessActivityResult`() = runBlockingTest { + fun `ActivityResultReceived offers ProcessActivityResult`() = runTest { actionResultsInEffects( ActivityResultReceived(0, 1, null), ProcessActivityResult(0, 1, null, viewModel.actions) ) } - private fun TestCoroutineScope.actionResultsInEffects( + private fun TestScope.actionResultsInEffects( action: Action, vararg effects: SideEffect<*> ) { diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomFileValidator.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomFileValidator.kt index 4fb5b1de8..7a4022594 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomFileValidator.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomFileValidator.kt @@ -22,7 +22,6 @@ import android.content.Context import android.content.pm.PackageManager import android.content.res.AssetFileDescriptor import android.content.res.AssetManager -import androidx.core.content.ContextCompat import org.kiwix.kiwixmobile.core.utils.files.Log import org.kiwix.kiwixmobile.custom.main.ValidationState.HasBothFiles import org.kiwix.kiwixmobile.custom.main.ValidationState.HasFile @@ -96,7 +95,7 @@ class CustomFileValidator @Inject constructor(private val context: Context) { private fun obbFiles() = scanDirs( - ContextCompat.getObbDirs(context).filterNotNull().filter(File::exists).toTypedArray(), + context.obbDirs.filterNotNull().filter(File::exists).toTypedArray(), "obb" ) @@ -105,7 +104,7 @@ class CustomFileValidator @Inject constructor(private val context: Context) { val directoryList = mutableListOf() // Get the external files directories for the app - ContextCompat.getExternalFilesDirs(context, null).filterNotNull() + context.getExternalFilesDirs(null).filterNotNull() .filter(File::exists) .forEach { dir -> // Check if the directory's parent is not null diff --git a/lintConfig.xml b/lintConfig.xml index 48d9225f6..cc5dd1156 100644 --- a/lintConfig.xml +++ b/lintConfig.xml @@ -1,6 +1,6 @@ - + From 4d8e168255b4a5f877f98a50e6b88f80c70020de Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Tue, 24 Dec 2024 18:28:56 +0530 Subject: [PATCH 03/22] Reverted the automated changes in project.xml file. --- .idea/codeStyles/Project.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index ec9393b3a..38c7a8fdb 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -20,9 +20,9 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -48,4 +48,7 @@ + + + From ccfc896f02b51853dde8aefd94af59638ea7f787 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 26 Dec 2024 16:16:31 +0530 Subject: [PATCH 06/22] Enabled EdgeToEdge mode in project to support latest windowInset API. --- .../main/res/layout/activity_kiwix_main.xml | 5 +---- app/src/main/res/layout/activity_language.xml | 11 +++++------ app/src/main/res/layout/activity_zim_host.xml | 1 - .../layout/fragment_destination_library.xml | 3 +-- .../layout/fragment_local_file_transfer.xml | 1 - buildSrc/src/main/kotlin/Libs.kt | 4 ++-- buildSrc/src/main/kotlin/Versions.kt | 2 ++ .../kotlin/plugin/AllProjectConfigurer.kt | 1 + .../kiwixmobile/core/base/BaseActivity.kt | 12 ++++++++++++ .../kiwixmobile/core/base/BaseFragment.kt | 14 ++++++++++++++ .../core/extensions/ActivityExtensions.kt | 19 +++++++++++++++++++ .../core/extensions/FragmentExtensions.kt | 11 +++++++++++ core/src/main/res/layout/drawer_right.xml | 1 - core/src/main/res/layout/fragment_help.xml | 1 - core/src/main/res/layout/fragment_page.xml | 3 +-- core/src/main/res/layout/fragment_reader.xml | 3 +-- core/src/main/res/layout/fragment_search.xml | 1 - core/src/main/res/layout/nav_main.xml | 1 - .../res/layout/reader_fragment_content.xml | 3 +-- core/src/main/res/layout/settings.xml | 3 +-- core/src/main/res/layout/tab_switcher.xml | 3 +-- core/src/main/res/values/themes.xml | 1 - .../main/res/layout/activity_custom_main.xml | 3 --- 23 files changed, 73 insertions(+), 34 deletions(-) diff --git a/app/src/main/res/layout/activity_kiwix_main.xml b/app/src/main/res/layout/activity_kiwix_main.xml index 9679f3981..111f83368 100644 --- a/app/src/main/res/layout/activity_kiwix_main.xml +++ b/app/src/main/res/layout/activity_kiwix_main.xml @@ -21,8 +21,7 @@ android:id="@+id/navigation_container" android:layout_width="match_parent" android:layout_height="match_parent" - android:contentDescription="@string/open_drawer" - android:fitsSystemWindows="true"> + android:contentDescription="@string/open_drawer"> @@ -62,7 +60,6 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="end" - android:fitsSystemWindows="true" app:headerLayout="@layout/drawer_right" /> diff --git a/app/src/main/res/layout/activity_language.xml b/app/src/main/res/layout/activity_language.xml index 00aed9c19..23bf4362b 100644 --- a/app/src/main/res/layout/activity_language.xml +++ b/app/src/main/res/layout/activity_language.xml @@ -1,24 +1,23 @@ + android:layout_width="match_parent" + android:layout_height="match_parent"> + app:layout_constraintTop_toBottomOf="@id/app_bar" + tools:listitem="@layout/item_language" /> diff --git a/app/src/main/res/layout/fragment_destination_library.xml b/app/src/main/res/layout/fragment_destination_library.xml index 31086b8dd..96a39dc76 100644 --- a/app/src/main/res/layout/fragment_destination_library.xml +++ b/app/src/main/res/layout/fragment_destination_library.xml @@ -21,8 +21,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - android:fitsSystemWindows="true"> + android:layout_height="match_parent"> diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 487895910..8de3a54d4 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -1,5 +1,3 @@ -import io.opencensus.trace.Tracing - /** * Generated by https://github.com/jmfayard/buildSrcVersions * @@ -308,6 +306,8 @@ object Libs { */ const val core_ktx: String = "androidx.core:core-ktx:" + Versions.core_ktx + const val androidx_activity: String = "androidx.activity:activity:" + Versions.androidx_activity + /** * https://github.com/kiwix/java-libkiwix */ diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index bced3b36c..c0cd580ed 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -90,6 +90,8 @@ object Versions { const val core_ktx: String = "1.15.0" + const val androidx_activity: String = "1.9.3" + const val libkiwix: String = "2.2.3" const val material: String = "1.12.0" diff --git a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt index 13daa7d14..f6502a999 100644 --- a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt +++ b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt @@ -233,6 +233,7 @@ class AllProjectConfigurer { kapt(Libs.roomCompiler) implementation(Libs.tracing) implementation(Libs.fetchOkhttp) + implementation(Libs.androidx_activity) } } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt index 718f6476c..6b1484435 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseActivity.kt @@ -17,8 +17,13 @@ */ package org.kiwix.kiwixmobile.core.base +import android.graphics.Color +import android.os.Build import android.os.Bundle +import androidx.activity.SystemBarStyle +import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity +import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.changeStatusBarAndNavigationBarColorInAndroid15AndAbove import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import javax.inject.Inject @@ -29,7 +34,14 @@ open class BaseActivity : AppCompatActivity() { lateinit var sharedPreferenceUtil: SharedPreferenceUtil override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.dark(Color.BLACK), + navigationBarStyle = SystemBarStyle.dark(Color.BLACK) + ) super.onCreate(savedInstanceState) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { + changeStatusBarAndNavigationBarColorInAndroid15AndAbove() + } LanguageUtils.handleLocaleChange(this, sharedPreferenceUtil) } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseFragment.kt index 77e18b557..4f6158936 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/base/BaseFragment.kt @@ -21,10 +21,14 @@ package org.kiwix.kiwixmobile.core.base import android.content.Context import android.os.Bundle import android.view.View +import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.core.extensions.enableEdgeToEdgeMode import org.kiwix.kiwixmobile.core.extensions.getToolbarNavigationIcon import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription @@ -46,7 +50,17 @@ abstract class BaseFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + enableEdgeToEdgeMode() setupToolbar() + this.view?.let { + ViewCompat.setOnApplyWindowInsetsListener(it) { view, windowInsets -> + val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) + val layoutParams = view.layoutParams as? ViewGroup.MarginLayoutParams + layoutParams?.topMargin = insets.top + view.layoutParams = layoutParams + WindowInsetsCompat.CONSUMED + } + } } // Setup toolbar to handle common back pressed event diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt index 7d4f2515c..f29d2d3c5 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/ActivityExtensions.kt @@ -29,6 +29,8 @@ import android.os.Bundle import android.os.Environment import android.view.Menu import android.view.MenuItem +import android.view.WindowInsetsController +import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.Toolbar @@ -199,4 +201,21 @@ object ActivityExtensions { val isWideEnough = configuration.smallestScreenWidthDp >= 600 return isLargeOrXLarge && isWideEnough } + + /** + * This method is for setting the statusBar color for Android 15 and above. + * Since in Android 15 the setStatusBarColor method is deprecated and not works anymore. + */ + @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) + fun Activity.changeStatusBarAndNavigationBarColorInAndroid15AndAbove() { + window?.apply { + // Set the white color to icon since the statusBar color is black. + decorView.windowInsetsController?.setSystemBarsAppearance( + 0, + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS + ) + insetsController?.hide(android.view.WindowInsets.Type.statusBars()) + insetsController?.show(android.view.WindowInsets.Type.statusBars()) + } + } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FragmentExtensions.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FragmentExtensions.kt index 2f7dd640c..f0f692ecc 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FragmentExtensions.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FragmentExtensions.kt @@ -19,10 +19,12 @@ package org.kiwix.kiwixmobile.core.extensions import android.content.Context +import android.os.Build import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.Toast import androidx.core.view.ViewCompat +import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModel @@ -55,3 +57,12 @@ fun View.closeKeyboard() { } val Fragment.coreMainActivity get() = activity as CoreMainActivity + +fun Fragment.enableEdgeToEdgeMode() { + activity?.window?.let { + WindowCompat.setDecorFitsSystemWindows( + it, + Build.VERSION.SDK_INT < Build.VERSION_CODES.Q + ) + } +} diff --git a/core/src/main/res/layout/drawer_right.xml b/core/src/main/res/layout/drawer_right.xml index e1170eccb..d2aa92e1a 100644 --- a/core/src/main/res/layout/drawer_right.xml +++ b/core/src/main/res/layout/drawer_right.xml @@ -4,5 +4,4 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" - android:fitsSystemWindows="true" android:focusable="true" /> diff --git a/core/src/main/res/layout/fragment_help.xml b/core/src/main/res/layout/fragment_help.xml index 158477da0..22f501d97 100644 --- a/core/src/main/res/layout/fragment_help.xml +++ b/core/src/main/res/layout/fragment_help.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true" tools:context=".help.HelpFragment"> diff --git a/core/src/main/res/layout/fragment_page.xml b/core/src/main/res/layout/fragment_page.xml index 9a47dc529..59d7c4430 100644 --- a/core/src/main/res/layout/fragment_page.xml +++ b/core/src/main/res/layout/fragment_page.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - android:fitsSystemWindows="true"> + android:layout_height="match_parent"> + android:layout_height="match_parent"> diff --git a/core/src/main/res/layout/reader_fragment_content.xml b/core/src/main/res/layout/reader_fragment_content.xml index b6a0ed7bc..93053de0b 100644 --- a/core/src/main/res/layout/reader_fragment_content.xml +++ b/core/src/main/res/layout/reader_fragment_content.xml @@ -26,8 +26,7 @@ + android:layout_height="match_parent"> + android:layout_height="match_parent"> + android:layout_height="match_parent"> diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt index b4163ad21..f9a41b7aa 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt @@ -85,8 +85,7 @@ class CustomMainActivity : CoreMainActivity() { super.onCreate(savedInstanceState) activityCustomMainBinding = ActivityCustomMainBinding.inflate(layoutInflater) setContentView(activityCustomMainBinding.root) - drawerNavView.applyEdgeToEdgeInsets() - readerTableOfContentsDrawer.applyEdgeToEdgeInsets() + activityCustomMainBinding.root.applyEdgeToEdgeInsets() if (savedInstanceState != null) { return } From 3b24308c9242e09da3756afbe96d9c614d450305 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 2 Jan 2025 17:28:29 +0530 Subject: [PATCH 18/22] Fixed: ZimManageViewModelTest, NewRecentSearchDaoTest, and SearchViewModelTest, etc, which were failing. --- .../zimManager/ZimManageViewModelTest.kt | 19 +++++- .../res/layout/dialog_navigation_history.xml | 3 +- .../search/viewmodel/SearchViewModelTest.kt | 58 +++++++++++++------ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt index b2b1bd54d..333c6b315 100644 --- a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt +++ b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt @@ -22,6 +22,7 @@ import android.app.Application import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.net.NetworkCapabilities.TRANSPORT_WIFI +import android.os.Build import com.jraska.livedata.test import io.mockk.clearAllMocks import io.mockk.every @@ -139,7 +140,12 @@ class ZimManageViewModelTest { every { newLanguagesDao.languages() } returns languages every { fat32Checker.fileSystemStates } returns fileSystemStates every { connectivityBroadcastReceiver.networkStates } returns networkStates - every { application.registerReceiver(any(), any(), any()) } returns mockk() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + every { application.registerReceiver(any(), any(), any()) } returns mockk() + } else { + @Suppress("UnspecifiedRegisterReceiverFlag") + every { application.registerReceiver(any(), any()) } returns mockk() + } every { dataSource.booksOnDiskAsListItems() } returns booksOnDiskListItems every { connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork) @@ -167,8 +173,15 @@ class ZimManageViewModelTest { inner class Context { @Test fun `registers broadcastReceiver in init`() { - verify { - application.registerReceiver(connectivityBroadcastReceiver, any(), any()) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + verify { + application.registerReceiver(connectivityBroadcastReceiver, any(), any()) + } + } else { + @Suppress("UnspecifiedRegisterReceiverFlag") + verify { + application.registerReceiver(connectivityBroadcastReceiver, any()) + } } } diff --git a/core/src/main/res/layout/dialog_navigation_history.xml b/core/src/main/res/layout/dialog_navigation_history.xml index c8f65ca30..153001b26 100644 --- a/core/src/main/res/layout/dialog_navigation_history.xml +++ b/core/src/main/res/layout/dialog_navigation_history.xml @@ -1,4 +1,5 @@ -