diff --git a/app/src/main/java/org/kiwix/kiwixmobile/intro/CustomPageIndicator.kt b/app/src/main/java/org/kiwix/kiwixmobile/intro/CustomPageIndicator.kt index 1abe931ab..8c3e7591c 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/intro/CustomPageIndicator.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/intro/CustomPageIndicator.kt @@ -171,7 +171,6 @@ class CustomPageIndicator @JvmOverloads constructor( val left = paddingLeft val top = paddingTop val right = width - paddingRight - val bottom = height - paddingBottom val requiredWidth = getRequiredWidth() val startLeft = left + (right - left - requiredWidth) / 2 + dotRadius dotCenterX = FloatArray(pageCount) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt b/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt index 548704548..9444d4596 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/language/viewmodel/SaveLanguagesAndFinish.kt @@ -17,7 +17,6 @@ */ package org.kiwix.kiwixmobile.language.viewmodel -import android.annotation.SuppressLint import androidx.appcompat.app.AppCompatActivity import io.reactivex.Flowable import io.reactivex.android.schedulers.AndroidSchedulers @@ -26,7 +25,7 @@ import org.kiwix.kiwixmobile.core.base.SideEffect import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao import org.kiwix.kiwixmobile.core.zim_manager.Language -@SuppressLint("CheckResult") +@Suppress("IgnoredReturnValue") data class SaveLanguagesAndFinish( val languages: List, val languageDao: NewLanguagesDao diff --git a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/PeerGroupHandshake.kt b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/PeerGroupHandshake.kt index c708fab40..6f7735e04 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/PeerGroupHandshake.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/PeerGroupHandshake.kt @@ -44,6 +44,8 @@ import java.net.Socket */ abstract class PeerGroupHandshake(private var groupInfo: WifiP2pInfo) { private val handshakeMessage = "Request Kiwix File Sharing" + + @Suppress("InjectDispatcher") suspend fun handshake(): InetAddress? = withContext(Dispatchers.IO) { Log.d(TAG, "Handshake in progress") diff --git a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/ReceiverDevice.kt b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/ReceiverDevice.kt index ff98cc03c..663f43221 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/ReceiverDevice.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/ReceiverDevice.kt @@ -38,6 +38,7 @@ import java.net.ServerSocket * many times as the no. of files). */ internal class ReceiverDevice(private val wifiDirectManager: WifiDirectManager) { + @Suppress("InjectDispatcher") suspend fun receive(): Boolean { return try { withContext(Dispatchers.IO) { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/SenderDevice.kt b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/SenderDevice.kt index 9978eee6d..4a55860e2 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/SenderDevice.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/SenderDevice.kt @@ -48,6 +48,7 @@ internal class SenderDevice( private val wifiDirectManager: WifiDirectManager, private val fileReceiverDeviceAddress: InetAddress ) { + @Suppress("InjectDispatcher") suspend fun send(fileItems: List) = withContext(Dispatchers.IO) { // Delay trying to connect with receiver, to allow slow receiver devices to setup server diff --git a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/adapter/WifiPeerListAdapter.kt b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/adapter/WifiPeerListAdapter.kt index 28dfc1dc7..8b73a061d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/adapter/WifiPeerListAdapter.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/localFileTransfer/adapter/WifiPeerListAdapter.kt @@ -22,5 +22,5 @@ import org.kiwix.kiwixmobile.core.base.adapter.BaseDelegateAdapter internal class WifiPeerListAdapter(wifiP2pDelegate: WifiP2pDelegate) : BaseDelegateAdapter(wifiP2pDelegate) { - override fun getIdFor(item: WifiP2pDevice) = item.deviceAddress.hashCode().toLong() ?: 0L + override fun getIdFor(item: WifiP2pDevice) = item.deviceAddress.hashCode().toLong() } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/CopyMoveFileHandler.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/CopyMoveFileHandler.kt index aa7a33375..93b02801c 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/CopyMoveFileHandler.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/CopyMoveFileHandler.kt @@ -449,6 +449,7 @@ class CopyMoveFileHandler @Inject constructor( } } + @Suppress("InjectDispatcher") suspend fun deleteSourceFile(uri: Uri) = withContext(Dispatchers.IO) { try { DocumentsContract.deleteDocument(activity.applicationContext.contentResolver, uri) @@ -458,7 +459,7 @@ class CopyMoveFileHandler @Inject constructor( } } - @Suppress("MagicNumber") + @Suppress("MagicNumber", "InjectDispatcher") private suspend fun copyFile(sourceUri: Uri, destinationFile: File) = withContext(Dispatchers.IO) { val contentResolver = activity.contentResolver diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt index 172ea79dd..c35a9f20a 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt @@ -484,6 +484,7 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal } } + @Suppress("InjectDispatcher") private fun navigateToReaderFragment(file: File) { if (!file.canRead()) { activity.toast(string.unable_to_read_zim_file) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt index 749d21687..adaeff922 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt @@ -43,7 +43,7 @@ class KiwixServer @Inject constructor( private val context: Context, private val zimReaderContainer: ZimReaderContainer ) { - @Suppress("NestedBlockDepth") + @Suppress("NestedBlockDepth", "InjectDispatcher") suspend fun createKiwixServer(selectedBooksPath: ArrayList): KiwixServer = withContext(Dispatchers.IO) { val kiwixLibrary = Library() diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt index df6a145a2..68014cb46 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt @@ -73,7 +73,7 @@ class HotspotService : super.onDestroy() } - @Suppress("NestedBlockDepth") + @Suppress("NestedBlockDepth", "InjectDispatcher") override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { when (intent.action) { ACTION_START_SERVER -> { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt index a0c9c5135..5966efc4b 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt @@ -17,7 +17,6 @@ */ package org.kiwix.kiwixmobile.zimManager -import android.annotation.SuppressLint import android.os.Build import android.os.FileObserver import io.reactivex.Flowable @@ -34,7 +33,7 @@ import org.kiwix.kiwixmobile.zimManager.FileSystemCapability.CAN_WRITE_4GB import org.kiwix.kiwixmobile.zimManager.FileSystemCapability.INCONCLUSIVE import java.io.File -@SuppressLint("CheckResult") +@Suppress("IgnoredReturnValue") class Fat32Checker constructor( sharedPreferenceUtil: SharedPreferenceUtil, private val fileSystemCheckers: List diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/DeleteFiles.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/DeleteFiles.kt index 817a745be..74a750e62 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/DeleteFiles.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/DeleteFiles.kt @@ -45,6 +45,7 @@ data class DeleteFiles(private val booksOnDiskListItems: List) : @Inject lateinit var zimReaderContainer: ZimReaderContainer + @Suppress("InjectDispatcher") override fun invokeWith(activity: AppCompatActivity) { (activity as BaseActivity).cachedComponent.inject(this) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/OpenFileWithNavigation.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/OpenFileWithNavigation.kt index 58731ac8c..574410fa4 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/OpenFileWithNavigation.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/fileselectView/effects/OpenFileWithNavigation.kt @@ -31,6 +31,7 @@ import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDis import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader +@Suppress("InjectDispatcher") data class OpenFileWithNavigation(private val bookOnDisk: BooksOnDiskListItem.BookOnDisk) : SideEffect { override fun invokeWith(activity: AppCompatActivity) { 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 bcbce257a..06666576b 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt @@ -22,6 +22,7 @@ import android.content.Context import android.content.ContextWrapper import android.os.Build import android.os.Environment +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil @@ -31,10 +32,12 @@ import java.io.RandomAccessFile object StorageDeviceUtils { @JvmStatic - suspend fun getWritableStorage(context: Context) = - withContext(Dispatchers.IO) { - validate(externalMediaFilesDirsDevices(context), true) - } + suspend fun getWritableStorage( + context: Context, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ) = withContext(dispatcher) { + validate(externalMediaFilesDirsDevices(context), true) + } @JvmStatic fun getReadableStorage(context: Context): List { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt index f12ef0f09..6bcc99466 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt @@ -22,6 +22,7 @@ import io.reactivex.Flowable import io.reactivex.Single import io.reactivex.functions.BiFunction import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -43,13 +44,14 @@ class StorageObserver @Inject constructor( private val libkiwixBookmarks: LibkiwixBookmarks ) { fun getBooksOnFileSystem( - scanningProgressListener: ScanningProgressListener + scanningProgressListener: ScanningProgressListener, + dispatcher: CoroutineDispatcher = Dispatchers.IO ): Flowable> { return scanFiles(scanningProgressListener) .withLatestFrom(downloadRoomDao.downloads(), BiFunction(::toFilesThatAreNotDownloading)) .flatMapSingle { files -> Single.create { emitter -> - CoroutineScope(Dispatchers.IO).launch { + CoroutineScope(dispatcher).launch { try { emitter.onSuccess(files.mapNotNull { convertToBookOnDisk(it) }) } catch (ignore: Exception) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt index c4613f28c..547288a1a 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt @@ -26,6 +26,7 @@ import io.reactivex.BackpressureStrategy.LATEST import io.reactivex.Flowable import io.reactivex.schedulers.Schedulers import io.reactivex.subjects.BehaviorSubject +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -219,10 +220,13 @@ class LibkiwixBookmarks @Inject constructor( return libraryBooksList.any { it == bookId } } - fun deleteBookmarks(bookmarks: List) { + fun deleteBookmarks( + bookmarks: List, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ) { bookmarks.map { library.removeBookmark(it.zimId, it.bookmarkUrl) } .also { - CoroutineScope(Dispatchers.IO).launch { + CoroutineScope(dispatcher).launch { writeBookMarksAndSaveLibraryToFile() updateFlowableBookmarkList() } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NewBookDao.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NewBookDao.kt index 3421dd7c2..495f20e19 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NewBookDao.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NewBookDao.kt @@ -22,6 +22,7 @@ import io.objectbox.kotlin.inValues import io.objectbox.kotlin.query import io.objectbox.query.QueryBuilder import io.reactivex.rxjava3.core.Completable +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -55,10 +56,10 @@ class NewBookDao @Inject constructor(private val box: Box) { .toList() .toFlowable() .flatMap { booksList -> - completableFromCoroutine { + completableFromCoroutine(block = { removeBooksThatAreInTrashFolder(booksList) removeBooksThatDoNotExist(booksList.toMutableList()) - } + }) .andThen(io.reactivex.rxjava3.core.Flowable.just(booksList)) } } @@ -80,10 +81,13 @@ class NewBookDao @Inject constructor(private val box: Box) { } .map { it.map(::BookOnDisk) } - private fun completableFromCoroutine(block: suspend () -> Unit): Completable { + private fun completableFromCoroutine( + block: suspend () -> Unit, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ): Completable { return Completable.defer { Completable.create { emitter -> - CoroutineScope(Dispatchers.IO).launch { + CoroutineScope(dispatcher).launch { try { block() emitter.onComplete() diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NotesRoomDao.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NotesRoomDao.kt index 0eba0aaab..0df91e5f1 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NotesRoomDao.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/NotesRoomDao.kt @@ -23,6 +23,7 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import io.reactivex.Flowable +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -88,8 +89,11 @@ abstract class NotesRoomDao : PageDao { * the associated file should also be removed from storage, * as it is no longer needed. */ - private fun removeNoteFileFromStorage(noteFilePath: String) { - CoroutineScope(Dispatchers.IO).launch { + private fun removeNoteFileFromStorage( + noteFilePath: String, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ) { + CoroutineScope(dispatcher).launch { val noteFile = File(noteFilePath) if (noteFile.isFileExist()) { noteFile.deleteFile() diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt index 866b996e7..6c64661ec 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt @@ -58,6 +58,7 @@ import com.tonyodev.fetch2.R.drawable import com.tonyodev.fetch2.R.string import com.tonyodev.fetch2.Status import com.tonyodev.fetch2.util.DEFAULT_NOTIFICATION_TIMEOUT_AFTER_RESET +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -209,14 +210,19 @@ class FetchDownloadNotificationManager @Inject constructor( } } - fun showDownloadPauseNotification(fetch: Fetch, download: Download) { - CoroutineScope(Dispatchers.IO).launch { + fun showDownloadPauseNotification( + fetch: Fetch, + download: Download, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ) { + CoroutineScope(dispatcher).launch { val notificationBuilder = getNotificationBuilder(download.id, download.id) val cancelNotification = getCancelNotification(fetch, download, notificationBuilder) downloadNotificationManager.notify(download.id, cancelNotification) } } + @Suppress("InjectDispatcher") fun getCancelNotification( fetch: Fetch, download: Download, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FileExtensions.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FileExtensions.kt index 203c83e00..5d100b33c 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FileExtensions.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/FileExtensions.kt @@ -18,16 +18,22 @@ package org.kiwix.kiwixmobile.core.extensions +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.File -suspend fun File.isFileExist(): Boolean = withContext(Dispatchers.IO) { exists() } +suspend fun File.isFileExist(dispatcher: CoroutineDispatcher = Dispatchers.IO): Boolean = + withContext(dispatcher) { exists() } -suspend fun File.freeSpace(): Long = withContext(Dispatchers.IO) { freeSpace } +suspend fun File.freeSpace(dispatcher: CoroutineDispatcher = Dispatchers.IO): Long = + withContext(dispatcher) { freeSpace } -suspend fun File.totalSpace(): Long = withContext(Dispatchers.IO) { totalSpace } +suspend fun File.totalSpace(dispatcher: CoroutineDispatcher = Dispatchers.IO): Long = + withContext(dispatcher) { totalSpace } -suspend fun File.canReadFile(): Boolean = withContext(Dispatchers.IO) { canRead() } +suspend fun File.canReadFile(dispatcher: CoroutineDispatcher = Dispatchers.IO): Boolean = + withContext(dispatcher) { canRead() } -suspend fun File.deleteFile(): Boolean = withContext(Dispatchers.IO) { delete() } +suspend fun File.deleteFile(dispatcher: CoroutineDispatcher = Dispatchers.IO): Boolean = + withContext(dispatcher) { delete() } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt index 3c988febe..0e287e387 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt @@ -112,6 +112,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { @Inject lateinit var downloadMonitor: DownloadMonitor + @Suppress("InjectDispatcher") override fun onCreate(savedInstanceState: Bundle?) { setTheme(R.style.KiwixTheme) super.onCreate(savedInstanceState) 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 10b98b57f..931c956bc 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 @@ -1008,6 +1008,7 @@ abstract class CoreReaderFragment : loadUrlWithCurrentWebview(navigationHistoryListItem.pageUrl) } + @Suppress("InjectDispatcher") override fun clearHistory() { getCurrentWebView()?.clearHistory() CoroutineScope(Dispatchers.IO).launch { @@ -2497,6 +2498,7 @@ abstract class CoreReaderFragment : * openSearch("", isOpenedFromTabView = isInTabSwitcher, false) * } */ + @Suppress("InjectDispatcher") private fun saveTabStates(onComplete: () -> Unit = {}) { CoroutineScope(Dispatchers.Main).launch { savingTabsMutex.withLock { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/viewmodel/effects/DeletePageItems.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/viewmodel/effects/DeletePageItems.kt index 12dab8688..d39f878a2 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/viewmodel/effects/DeletePageItems.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/viewmodel/effects/DeletePageItems.kt @@ -27,6 +27,7 @@ import org.kiwix.kiwixmobile.core.dao.PageDao import org.kiwix.kiwixmobile.core.page.adapter.Page import org.kiwix.kiwixmobile.core.page.viewmodel.PageState +@Suppress("InjectDispatcher") data class DeletePageItems( private val state: PageState<*>, private val pageDao: PageDao, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimFileReader.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimFileReader.kt index fbc68a3b3..287f8f6b6 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimFileReader.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimFileReader.kt @@ -25,6 +25,7 @@ import androidx.core.net.toUri import eu.mhutti1.utils.storage.KB import io.reactivex.Completable import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.kiwix.kiwixmobile.core.CoreApp @@ -67,6 +68,7 @@ class ZimFileReader constructor( class Impl @Inject constructor( private val darkModeConfig: DarkModeConfig ) : Factory { + @Suppress("InjectDispatcher") override suspend fun create(zimReaderSource: ZimReaderSource): ZimFileReader? = withContext(Dispatchers.IO) { // Bug Fix #3805 try { @@ -192,12 +194,15 @@ class ZimFileReader constructor( } @Suppress("UnreachableCode") - suspend fun load(uri: String): InputStream? = - withContext(Dispatchers.IO) { + suspend fun load( + uri: String, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ): InputStream? = + withContext(dispatcher) { val extension = uri.substringAfterLast(".") if (assetExtensions.any { it == extension }) { try { - return@withContext loadAsset(uri) + return@withContext loadAsset(uri, dispatcher) } catch (ioException: IOException) { Log.e(TAG, "failed to write video for $uri", ioException) } @@ -273,8 +278,12 @@ class ZimFileReader constructor( throw IOException("Could not open pipe for $uri", ioException) } - private suspend fun loadAsset(uri: String): InputStream? = - withContext(Dispatchers.IO) { + @Suppress("InjectDispatcher") + private suspend fun loadAsset( + uri: String, + dispatcher: CoroutineDispatcher + ): InputStream? = + withContext(dispatcher) { val item = try { jniKiwixReader.getEntryByPath(uri.filePath).getItem(true) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimReaderContainer.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimReaderContainer.kt index 348100579..0d285a0ee 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimReaderContainer.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimReaderContainer.kt @@ -34,6 +34,7 @@ class ZimReaderContainer @Inject constructor(private val zimFileReaderFactory: F field = value } + @Suppress("InjectDispatcher") suspend fun setZimReaderSource(zimReaderSource: ZimReaderSource?) { if (zimReaderSource == zimFileReader?.zimReaderSource) { return diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/search/SearchFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/search/SearchFragment.kt index b80d662e7..524454a43 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/search/SearchFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/search/SearchFragment.kt @@ -305,6 +305,7 @@ class SearchFragment : BaseFragment() { it.value.equals(query, ignoreCase = true) } + @Suppress("InjectDispatcher") suspend fun render(state: SearchState) { renderingJob?.apply { // cancel the children job. Since we are getting the result on IO thread diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchResultGenerator.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchResultGenerator.kt index 9b58356be..5ec467f0b 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchResultGenerator.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchResultGenerator.kt @@ -33,6 +33,7 @@ interface SearchResultGenerator { } class ZimSearchResultGenerator @Inject constructor() : SearchResultGenerator { + @Suppress("InjectDispatcher") override suspend fun generateSearchResults(searchTerm: String, zimFileReader: ZimFileReader?) = withContext(Dispatchers.IO) { if (searchTerm.isNotEmpty()) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/DeleteRecentSearch.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/DeleteRecentSearch.kt index 83afdc5db..e27ed00c1 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/DeleteRecentSearch.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/DeleteRecentSearch.kt @@ -26,6 +26,7 @@ import org.kiwix.kiwixmobile.core.base.SideEffect import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem +@Suppress("InjectDispatcher") data class DeleteRecentSearch( private val searchListItem: SearchListItem, private val recentSearchRoomDao: RecentSearchRoomDao, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SaveSearchToRecents.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SaveSearchToRecents.kt index f31903b98..3d26a5d08 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SaveSearchToRecents.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SaveSearchToRecents.kt @@ -27,6 +27,7 @@ import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao import org.kiwix.kiwixmobile.core.reader.addContentPrefix import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem +@Suppress("InjectDispatcher") data class SaveSearchToRecents( private val recentSearchRoomDao: RecentSearchRoomDao, private val searchListItem: SearchListItem, 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 64945417b..2c291c151 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 @@ -32,6 +32,7 @@ import android.provider.DocumentsContract import android.provider.MediaStore import android.webkit.URLUtil import androidx.annotation.RequiresApi +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -65,8 +66,11 @@ object FileUtils { @JvmStatic @Synchronized - fun deleteCachedFiles(context: Context) { - CoroutineScope(Dispatchers.IO).launch { + fun deleteCachedFiles( + context: Context, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ) { + CoroutineScope(dispatcher).launch { getFileCacheDir(context)?.deleteRecursively() } } @@ -84,7 +88,8 @@ object FileUtils { fileloop@ while (alphabetFirst <= 'z') { var alphabetSecond = 'a' while (alphabetSecond <= 'z') { - val chunkPath = filePath.substring(0, filePath.length - 2) + alphabetFirst + alphabetSecond + val chunkPath = + filePath.substring(0, filePath.length - 2) + alphabetFirst + alphabetSecond val fileChunk = File(chunkPath) if (fileChunk.isFileExist()) { fileChunk.deleteFile() 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 5bcac1079..46cb171ee 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 @@ -129,6 +129,7 @@ class CustomFileValidator @Inject constructor(private val context: Context) { } } + @Suppress("UseOrEmpty") private fun scanDirs(dirs: Array?, extensionToMatch: String): List = dirs?.filterNotNull()?.fold(listOf()) { acc, dir -> acc + dir.walk().filter { it.extension.startsWith(extensionToMatch) }.toList()