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.
This commit is contained in:
MohitMaliFtechiz 2025-01-02 12:04:54 +05:30 committed by Kelson
parent 3423bbf671
commit 08c054586a
18 changed files with 42 additions and 55 deletions

View File

@ -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()

View File

@ -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())
}
}

View File

@ -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") {

View File

@ -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"

View File

@ -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)
}

View File

@ -1,4 +1,3 @@
import com.android.build.gradle.internal.utils.isKotlinKaptPluginApplied
import plugin.KiwixConfigurationPlugin
buildscript {

View File

@ -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) }

View File

@ -45,7 +45,7 @@ class AdapterDelegateManager<T> {
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
}
}

View File

@ -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 {

View File

@ -1869,9 +1869,9 @@ abstract class CoreReaderFragment :
}
reopenBook()
showTabSwitcher()
setUpWithTextToSpeech(tempWebViewListForUndo.last())
setUpWithTextToSpeech(tempWebViewListForUndo[tempWebViewListForUndo.lastIndex])
updateBottomToolbarVisibility()
safelyAddWebView(tempWebViewListForUndo.last())
safelyAddWebView(tempWebViewListForUndo[tempWebViewListForUndo.lastIndex])
}
}

View File

@ -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)
}

View File

@ -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 =

View File

@ -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

View File

@ -143,7 +143,7 @@
<string name="help_11">This is a descriptive message explaining where the Zim files are located after downloading. It is showing on the help screen.</string>
<string name="pref_storage">{{Identical|Storage}}</string>
<string name="pref_current_folder">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.</string>
<string name="pref_free_storage">This refers to free (unused) storage space, not to free as in free of charge.</string>
<string name="pref_free_storage">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.</string>
<string name="delete_zim_failed">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.</string>
<string name="tts_pause">{{identical|pause}}</string>
<string name="tts_resume">{{identical|resume}}</string>

View File

@ -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>(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>(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(), 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<RecentSearchEntity> =
(0..200).map { recentSearchEntity(searchTerm = "$it") }
expectFromRecentSearches(searchResults, "")

View File

@ -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<Bundle>()
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<*>
) {

View File

@ -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<File>()
// 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

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="TypographyQuotes">
<issue id="TypographyQuotes" severity="warning">
<ignore path="**-qq/**.xml" />
<ignore path="**-iw/**.xml" />
</issue>