diff --git a/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt b/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt index 5b9c572c4..2b08f719b 100644 --- a/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt @@ -37,7 +37,7 @@ fun NewUpdateScreen( icon = Icons.Outlined.NewReleases, headingText = stringResource(R.string.update_check_notification_update_available), subtitleText = versionName, - acceptText = stringResource(id = R.string.update_check_confirm), + acceptText = stringResource(R.string.update_check_confirm), onAcceptClick = onAcceptUpdate, rejectText = stringResource(R.string.action_not_now), onRejectClick = onRejectUpdate, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt index 01e59f868..a9615e7bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt @@ -44,12 +44,12 @@ class BackupRestoreService : Service() { * @param uri path of Uri */ fun start(context: Context, uri: Uri) { - if (!isRunning(context)) { - val intent = Intent(context, BackupRestoreService::class.java).apply { - putExtra(BackupConst.EXTRA_URI, uri) - } - ContextCompat.startForegroundService(context, intent) + if (isRunning(context)) return + + val intent = Intent(context, BackupRestoreService::class.java).apply { + putExtra(BackupConst.EXTRA_URI, uri) } + ContextCompat.startForegroundService(context, intent) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt index b3d9bd8f2..ad1f5d557 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt @@ -166,13 +166,13 @@ class AppUpdateService : Service() { * @param url the url to the new update. */ fun start(context: Context, url: String, title: String? = context.getString(R.string.app_name)) { - if (!isRunning(context)) { - val intent = Intent(context, AppUpdateService::class.java).apply { - putExtra(EXTRA_DOWNLOAD_TITLE, title) - putExtra(EXTRA_DOWNLOAD_URL, url) - } - ContextCompat.startForegroundService(context, intent) + if (isRunning(context)) return + + val intent = Intent(context, AppUpdateService::class.java).apply { + putExtra(EXTRA_DOWNLOAD_TITLE, title) + putExtra(EXTRA_DOWNLOAD_URL, url) } + ContextCompat.startForegroundService(context, intent) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt index 892bb58e9..76c276dac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt @@ -50,13 +50,13 @@ internal class ExtensionInstallReceiver(private val listener: Listener) : when (intent.action) { Intent.ACTION_PACKAGE_ADDED -> { - if (!isReplacing(intent)) { - launchNow { - when (val result = getExtensionFromIntent(context, intent)) { - is LoadResult.Success -> listener.onExtensionInstalled(result.extension) - is LoadResult.Untrusted -> listener.onExtensionUntrusted(result.extension) - else -> {} - } + if (isReplacing(intent)) return + + launchNow { + when (val result = getExtensionFromIntent(context, intent)) { + is LoadResult.Success -> listener.onExtensionInstalled(result.extension) + is LoadResult.Untrusted -> listener.onExtensionUntrusted(result.extension) + else -> {} } } } @@ -71,11 +71,11 @@ internal class ExtensionInstallReceiver(private val listener: Listener) : } } Intent.ACTION_PACKAGE_REMOVED -> { - if (!isReplacing(intent)) { - val pkgName = getPackageNameFromIntent(intent) - if (pkgName != null) { - listener.onPackageUninstalled(pkgName) - } + if (isReplacing(intent)) return + + val pkgName = getPackageNameFromIntent(intent) + if (pkgName != null) { + listener.onPackageUninstalled(pkgName) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 9f57cffc4..de78bea61 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -90,6 +90,7 @@ import eu.kanade.tachiyomi.util.view.setComposeContent import kotlinx.coroutines.cancel import kotlinx.coroutines.delay import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch @@ -243,14 +244,13 @@ class MainActivity : BaseActivity() { LaunchedEffect(Unit) { preferences.incognitoMode().changes() .drop(1) + .filter { !it } .onEach { - if (!it) { - val currentScreen = navigator.lastItem - if (currentScreen is BrowseSourceScreen || - (currentScreen is MangaScreen && currentScreen.fromSource) - ) { - navigator.popUntilRoot() - } + val currentScreen = navigator.lastItem + if (currentScreen is BrowseSourceScreen || + (currentScreen is MangaScreen && currentScreen.fromSource) + ) { + navigator.popUntilRoot() } } .launchIn(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 412ecb298..f9c5acdfa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -389,10 +389,10 @@ class MangaInfoScreenModel( fun moveMangaToCategoriesAndAddToLibrary(manga: Manga, categories: List) { moveMangaToCategory(categories) - if (!manga.favorite) { - coroutineScope.launchIO { - updateManga.awaitUpdateFavorite(manga.id, true) - } + if (manga.favorite) return + + coroutineScope.launchIO { + updateManga.awaitUpdateFavorite(manga.id, true) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index d8c9c7896..70c527d15 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -532,17 +532,14 @@ class ReaderViewModel( * Saves this [readerChapter] last read history if incognito mode isn't on. */ private suspend fun saveChapterHistory(readerChapter: ReaderChapter) { - if (!incognitoMode) { - val chapterId = readerChapter.chapter.id!! - val readAt = Date() - val sessionReadDuration = chapterReadStartTime?.let { readAt.time - it } ?: 0 + if (incognitoMode) return - upsertHistory.await( - HistoryUpdate(chapterId, readAt, sessionReadDuration), - ).also { - chapterReadStartTime = null - } - } + val chapterId = readerChapter.chapter.id!! + val endTime = Date() + val sessionReadDuration = chapterReadStartTime?.let { endTime.time - it } ?: 0 + + upsertHistory.await(HistoryUpdate(chapterId, endTime, sessionReadDuration)) + chapterReadStartTime = null } fun setReadStartTime() { diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt b/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt index 255214725..1242de90a 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt @@ -83,6 +83,7 @@ suspend fun Call.await(): Response { override fun onFailure(call: Call, e: IOException) { // Don't bother with resuming the continuation if it is already cancelled. if (continuation.isCancelled) return + continuation.resumeWithException(e) } },