From 6a5c4a7992e9618acc9d468603c0464e2b7b4096 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 26 Jul 2024 18:56:48 +0530 Subject: [PATCH] Fixed some detekt and lint issues --- .../library/OnlineLibraryFragment.kt | 29 -------------- .../libraryView/AvailableSpaceCalculator.kt | 1 - .../zimManager/ZimManageViewModelTest.kt | 1 - .../kiwix/kiwixmobile/core/StorageObserver.kt | 1 - .../core/dao/entities/FetchDownloadEntity.kt | 10 ++--- .../core/data/KiwixRoomDatabase.kt | 1 + .../core/di/modules/ApplicationModule.kt | 5 ++- .../core/di/modules/DownloaderModule.kt | 10 +++-- .../core/downloader/DownloaderImpl.kt | 1 - .../downloadManager/DownloadManagerMonitor.kt | 40 ++++++++++++------- .../DownloadNotificationManager.kt | 16 ++++---- .../core/downloader/downloadManager/Error.kt | 2 + .../core/downloader/downloadManager/Status.kt | 2 + .../downloader/fetch/FetchDownloadMonitor.kt | 2 +- .../core/downloader/model/DownloadRequest.kt | 4 +- .../kiwixmobile/core/StorageObserverTest.kt | 1 - .../download/CustomDownloadViewModel.kt | 3 +- 17 files changed, 59 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt index b976d6f05b..d4757b6364 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragment.kt @@ -60,7 +60,6 @@ import org.kiwix.kiwixmobile.core.base.BaseFragment import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions import org.kiwix.kiwixmobile.core.downloader.Downloader import org.kiwix.kiwixmobile.core.downloader.downloadManager.Status -import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.hasNotificationPermission import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isManageExternalStoragePermissionGranted import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.navigate @@ -91,7 +90,6 @@ import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.SelectFolder import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog.YesNoDialog.WifiOnly import org.kiwix.kiwixmobile.core.utils.files.FileUtils.getPathFromUri import org.kiwix.kiwixmobile.databinding.FragmentDestinationDownloadBinding -import org.kiwix.kiwixmobile.zimManager.Fat32Checker import org.kiwix.kiwixmobile.zimManager.NetworkState import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel import org.kiwix.kiwixmobile.zimManager.libraryView.AvailableSpaceCalculator @@ -213,33 +211,6 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions { } } ) - // - val libraryBookEntity = LibraryNetworkEntity.Book().apply { - id = "6a5413cd-0d96-7288-9c1b-5beda035e472" - size = "170628" - url = "https://download.kiwix.org/zim/zimit/100r.co_en_all_2024-06.zim.meta4" - mediaCount = "1433" - articleCount = "320" - favicon = - "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAALYUlEQVR4nK2ae5SWVRXGf/PNDKDIcBdsRkFlZAAFCnAATVFMTEsxFbKsREGNMtRqebela1Wk5K2WeUsl1C62MlLCMitUQNAiUwHBTBQDlEuBBM7t7Y/nOZ09H9NKW5213vV93zPnss8++9l7n/0OwBTgLWADMAm1C4B3gL8AY4xdBTQBLwD1xm4B2oClQH+gBMwDCmAh0A3YB1hg7EH36Q8s9tjveq564HmgGfiasVHAWmAnMNPY8cCbwGbgTIBtnrwAngP2BXZ48gL4BTDAv5uN3QaM8Pd3/Xk5MNHfd/nzM34iNtF949jhnrPwGq1e8xFjbZZpX+APQd5tVf6SWqs7V/gBaAlYlbG0CECngLX5e5eAVXaApX5pbGvAqjrAKsJGyuVlErAMeAo43H+Ygo7z18BgY+cDq4CfA7XGLgfWAA8APZF5fAt4Bfiehd4bu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k9ONdaIqibLcWl+C5kUy5GtxTT5YfI1Mz23IhcYsa8gc4vYmX4idjRKGiM2jPZJZZuV9HDAtlu25QHbXH7bL4UnkThWJloClsY1+TMVXCETtpJscrs76NcU+sX/myjHCsTDjuTlTESKN8m+dia6x65FNyJQxG5C5EuB5VbyW/mUWqSI/Siy3+7kdwvzvGgt+d9tbvZcDchs30XFNJCfX4ssIhH2BMv6FjDlXw/HDkTdtlgLAAAAAElFTkSuQmCC" - title = "100 Rabbits" - description = "Research and test low-tech solutions, and document findings" - language = "eng" - creator = "-" - publisher = "openZIM" - bookName = "100r.co_en_all" - tags = "_ftindex:yes;preppers;_category:other;_pictures:yes;_videos:yes;_details:yes" - date = "2024-06-24" - faviconMimeType = "image/png" - } - onLibraryItemsChange( - arrayListOf( - LibraryListItem.BookItem( - libraryBookEntity, - Fat32Checker.FileSystemState.CanWrite4GbFile - ) - ) - ) } private fun setupMenu() { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt index aac5522778..f48d022f73 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt @@ -24,7 +24,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao -import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book import org.kiwix.kiwixmobile.core.settings.StorageCalculator 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 d4212491c8..4e8cec4c44 100644 --- a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt +++ b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt @@ -39,7 +39,6 @@ import org.junit.jupiter.api.extension.ExtendWith import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.StorageObserver import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao -import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao import org.kiwix.kiwixmobile.core.data.DataSource 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 121e27651b..3a67ac8c3d 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt @@ -23,7 +23,6 @@ import io.reactivex.functions.BiFunction import io.reactivex.schedulers.Schedulers import kotlinx.coroutines.runBlocking import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao -import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel import org.kiwix.kiwixmobile.core.reader.ZimFileReader diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadEntity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadEntity.kt index 825882da7e..b0200b2c90 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadEntity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadEntity.kt @@ -18,8 +18,6 @@ package org.kiwix.kiwixmobile.core.dao.entities import com.tonyodev.fetch2.Download -import com.tonyodev.fetch2.Error -import com.tonyodev.fetch2.Status import io.objectbox.annotation.Entity import io.objectbox.annotation.Id import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book @@ -32,10 +30,10 @@ data class FetchDownloadEntity( val etaInMilliSeconds: Long = -1L, val bytesDownloaded: Long = -1L, val totalSizeOfDownload: Long = -1L, - //@Convert(converter = StatusConverter::class, dbType = Int::class) - //val status: Status = Status.NONE, - //@Convert(converter = ErrorConverter::class, dbType = Int::class) - //val error: Error = Error.NONE, + // @Convert(converter = StatusConverter::class, dbType = Int::class) + // val status: Status = Status.NONE, + // @Convert(converter = ErrorConverter::class, dbType = Int::class) + // val error: Error = Error.NONE, val progress: Int = -1, val bookId: String, val title: String, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt index c144e5d18c..610fb56419 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/data/KiwixRoomDatabase.kt @@ -112,6 +112,7 @@ abstract class KiwixRoomDatabase : RoomDatabase() { } } + @Suppress("MagicNumber") private val MIGRATION_3_4 = object : Migration(3, 4) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL( diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt index c8c6f8da91..42d1f76797 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt @@ -95,8 +95,9 @@ class ApplicationModule { @Provides @Singleton - internal fun provideDownloadMonitor(downloadManagerMonitor: DownloadManagerMonitor) - : DownloadMonitor = downloadManagerMonitor + internal fun provideDownloadMonitor( + downloadManagerMonitor: DownloadManagerMonitor + ): DownloadMonitor = downloadManagerMonitor @Provides @Singleton diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt index 093f190090..6572ed0d95 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt @@ -117,8 +117,9 @@ object DownloaderModule { @Provides @Singleton - fun provideDownloadManagerCallback(downloadManagerMonitor: DownloadManagerMonitor) - : DownloadManagerBroadcastReceiver.Callback = downloadManagerMonitor + fun provideDownloadManagerCallback( + downloadManagerMonitor: DownloadManagerMonitor + ): DownloadManagerBroadcastReceiver.Callback = downloadManagerMonitor @Provides @Singleton @@ -127,8 +128,9 @@ object DownloaderModule { @Provides @Singleton - fun providesDownloadNotificationActionsBroadcastReceiver(downloadManagerMonitor: DownloadManagerMonitor) - : DownloadNotificationActionsBroadcastReceiver = + fun providesDownloadNotificationActionsBroadcastReceiver( + downloadManagerMonitor: DownloadManagerMonitor + ): DownloadNotificationActionsBroadcastReceiver = DownloadNotificationActionsBroadcastReceiver(downloadManagerMonitor) @Provides diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt index 6a6f6d0c1a..18e216eb11 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt @@ -21,7 +21,6 @@ package org.kiwix.kiwixmobile.core.downloader import android.annotation.SuppressLint import io.reactivex.Observable import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao -import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.data.remote.KiwixService import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadManagerMonitor.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadManagerMonitor.kt index bbb2b8fb95..0b68f044e5 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadManagerMonitor.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadManagerMonitor.kt @@ -39,6 +39,11 @@ import org.kiwix.kiwixmobile.core.downloader.model.DownloadState import java.util.concurrent.TimeUnit import javax.inject.Inject +const val ZERO = 0 +const val HUNDERED = 100 +const val THOUSAND = 1000 +const val DEFAULT_INT_VALUE = -1 + class DownloadManagerMonitor @Inject constructor( private val downloadManager: DownloadManager, private val downloadRoomDao: DownloadRoomDao, @@ -66,6 +71,7 @@ class DownloadManagerMonitor @Inject constructor( } } + @Suppress("MagicNumber") private fun startMonitoringDownloads() { // we have to disable this when no downloads is ongoing // and should re-enable when download started. @@ -183,6 +189,7 @@ class DownloadManagerMonitor @Inject constructor( } } + @Suppress("LongParameterList") private fun handleFailedDownload( downloadId: Long, reason: Int, @@ -261,7 +268,11 @@ class DownloadManagerMonitor @Inject constructor( } private fun calculateProgress(bytesDownloaded: Int, totalBytes: Int): Int = - if (totalBytes > 0) ((bytesDownloaded / totalBytes.toDouble()) * 100).toInt() else 0 + if (totalBytes > ZERO) { + (bytesDownloaded / totalBytes.toDouble()).times(HUNDERED).toInt() + } else { + ZERO + } private fun calculateETA(downloadedFileId: Long, bytesDownloaded: Int, totalBytes: Int): Long { val currentTime = System.currentTimeMillis() @@ -270,16 +281,16 @@ class DownloadManagerMonitor @Inject constructor( } val elapsedTime = currentTime - downloadInfo.startTime - val downloadSpeed = if (elapsedTime > 0) { - (bytesDownloaded - downloadInfo.initialBytesDownloaded) / (elapsedTime / 1000.0) + val downloadSpeed = if (elapsedTime > ZERO) { + (bytesDownloaded - downloadInfo.initialBytesDownloaded) / (elapsedTime / THOUSAND.toFloat()) } else { - 0.0 + ZERO.toFloat() } - return if (downloadSpeed > 0) { - ((totalBytes - bytesDownloaded) / downloadSpeed).toLong() * 1000 + return if (downloadSpeed > ZERO) { + ((totalBytes - bytesDownloaded) / downloadSpeed).toLong() * THOUSAND } else { - 0L + ZERO.toLong() } } @@ -298,14 +309,15 @@ class DownloadManagerMonitor @Inject constructor( } } + @Suppress("LongParameterList") private fun updateDownloadStatus( downloadId: Long, status: Status, error: Error, - progress: Int = -1, - etaInMilliSeconds: Long = -1L, - bytesDownloaded: Int = -1, - totalSizeOfDownload: Int = -1 + progress: Int = DEFAULT_INT_VALUE, + etaInMilliSeconds: Long = DEFAULT_INT_VALUE.toLong(), + bytesDownloaded: Int = DEFAULT_INT_VALUE, + totalSizeOfDownload: Int = DEFAULT_INT_VALUE ) { synchronized(lock) { updater.onNext { @@ -313,14 +325,14 @@ class DownloadManagerMonitor @Inject constructor( val downloadModel = DownloadModel(downloadEntity).apply { state = status this.error = error - if (progress > 0) { + if (progress > ZERO) { this.progress = progress } this.etaInMilliSeconds = etaInMilliSeconds - if (bytesDownloaded != -1) { + if (bytesDownloaded != DEFAULT_INT_VALUE) { this.bytesDownloaded = bytesDownloaded.toLong() } - if (totalSizeOfDownload != -1) { + if (totalSizeOfDownload != DEFAULT_INT_VALUE) { this.totalSizeOfDownload = totalSizeOfDownload.toLong() } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadNotificationManager.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadNotificationManager.kt index ad70cfcef1..638b42dc49 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadNotificationManager.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadNotificationManager.kt @@ -56,7 +56,7 @@ class DownloadNotificationManager @Inject constructor( if (shouldUpdateNotification(downloadNotificationModel)) { createNotificationChannel() val notificationBuilder = getNotificationBuilder(downloadNotificationModel.downloadId) - val smallIcon = if (downloadNotificationModel.progress != 100) { + val smallIcon = if (downloadNotificationModel.progress != HUNDERED) { android.R.drawable.stat_sys_download } else { android.R.drawable.stat_sys_download_done @@ -69,9 +69,9 @@ class DownloadNotificationManager @Inject constructor( .setOngoing(downloadNotificationModel.isOnGoingNotification) .setGroupSummary(false) if (downloadNotificationModel.isFailed || downloadNotificationModel.isCompleted) { - notificationBuilder.setProgress(0, 0, false) + notificationBuilder.setProgress(ZERO, ZERO, false) } else { - notificationBuilder.setProgress(100, downloadNotificationModel.progress, false) + notificationBuilder.setProgress(HUNDERED, downloadNotificationModel.progress, false) } when { downloadNotificationModel.isDownloading -> @@ -132,7 +132,7 @@ class DownloadNotificationManager @Inject constructor( val pendingIntent = PendingIntent.getActivity( context, - 0, + ZERO, internal, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT ) @@ -150,7 +150,7 @@ class DownloadNotificationManager @Inject constructor( notificationBuilder .setGroup("$notificationId") .setStyle(null) - .setProgress(0, 0, false) + .setProgress(ZERO, ZERO, false) .setContentTitle(null) .setContentText(null) .setContentIntent(null) @@ -203,9 +203,11 @@ class DownloadNotificationManager @Inject constructor( downloadNotificationModel.isPaused -> context.getString(R.string.paused_state) downloadNotificationModel.isQueued -> context.getString(R.string.pending_state) - downloadNotificationModel.etaInMilliSeconds <= 0 -> context.getString(R.string.running_state) + downloadNotificationModel.etaInMilliSeconds <= ZERO -> + context.getString(R.string.running_state) + else -> Seconds( - downloadNotificationModel.etaInMilliSeconds / 1000L + downloadNotificationModel.etaInMilliSeconds / THOUSAND.toLong() ).toHumanReadableTime() } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Error.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Error.kt index 596095f245..f165738714 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Error.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Error.kt @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.core.downloader.downloadManager +@Suppress("MagicNumber") enum class Error(val value: Int) { UNKNOWN(-1), NONE(0), @@ -35,6 +36,7 @@ enum class Error(val value: Int) { ERROR_UNHANDLED_HTTP_CODE(12); companion object { + @Suppress("ComplexMethod", "MagicNumber") @JvmStatic fun valueOf(value: Int): Error { return when (value) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Status.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Status.kt index 113ff3263f..da7d922b16 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Status.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/Status.kt @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.core.downloader.downloadManager +@Suppress("MagicNumber") enum class Status(val value: Int) { NONE(0), QUEUED(1), @@ -32,6 +33,7 @@ enum class Status(val value: Int) { companion object { + @Suppress("MagicNumber") @JvmStatic fun valueOf(value: Int): Status { return when (value) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt index 5882d6c353..59c7bb9aef 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt @@ -97,7 +97,7 @@ class FetchDownloadMonitor @Inject constructor(fetch: Fetch, fetchDownloadDao: F } private fun update(download: Download) { - //updater.onNext { fetchDownloadDao.update(download) } + // updater.onNext { fetchDownloadDao.update(download) } } private fun delete(download: Download) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadRequest.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadRequest.kt index 9e91097141..7693f30159 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadRequest.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadRequest.kt @@ -29,7 +29,9 @@ data class DownloadRequest(val urlString: String, val notificationTitle: String) fun getDestinationFile(sharedPreferenceUtil: SharedPreferenceUtil): File { val file = - File("${sharedPreferenceUtil.prefStorage}/Kiwix/${StorageUtils.getFileNameFromUrl(urlString)}") + File( + "${sharedPreferenceUtil.prefStorage}/Kiwix/${StorageUtils.getFileNameFromUrl(urlString)}" + ) return file } } diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt index 235b508e9c..beee136801 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt @@ -29,7 +29,6 @@ import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao -import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel import org.kiwix.kiwixmobile.core.reader.ZimFileReader diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt index 760f2a412e..05b990819f 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt @@ -24,7 +24,6 @@ import io.reactivex.disposables.CompositeDisposable import io.reactivex.processors.PublishProcessor import org.kiwix.kiwixmobile.core.base.SideEffect import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao -import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem import org.kiwix.kiwixmobile.core.downloader.model.DownloadState.Failed import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload @@ -87,6 +86,7 @@ class CustomDownloadViewModel @Inject constructor( DownloadRequired -> if (action.downloads.isNotEmpty()) DownloadInProgress(action.downloads) else state + is DownloadInProgress -> if (action.downloads.isNotEmpty()) if (action.downloads[0].downloadState is Failed) @@ -95,6 +95,7 @@ class CustomDownloadViewModel @Inject constructor( DownloadInProgress(action.downloads) else DownloadComplete.also { _effects.offer(navigateToCustomReader) } + DownloadComplete -> state } }