Minor cleanup

This commit is contained in:
arkon 2023-01-12 22:53:28 -05:00
parent 4d8289cd36
commit a2ee4e63ae
8 changed files with 43 additions and 45 deletions

View file

@ -37,7 +37,7 @@ fun NewUpdateScreen(
icon = Icons.Outlined.NewReleases, icon = Icons.Outlined.NewReleases,
headingText = stringResource(R.string.update_check_notification_update_available), headingText = stringResource(R.string.update_check_notification_update_available),
subtitleText = versionName, subtitleText = versionName,
acceptText = stringResource(id = R.string.update_check_confirm), acceptText = stringResource(R.string.update_check_confirm),
onAcceptClick = onAcceptUpdate, onAcceptClick = onAcceptUpdate,
rejectText = stringResource(R.string.action_not_now), rejectText = stringResource(R.string.action_not_now),
onRejectClick = onRejectUpdate, onRejectClick = onRejectUpdate,

View file

@ -44,13 +44,13 @@ class BackupRestoreService : Service() {
* @param uri path of Uri * @param uri path of Uri
*/ */
fun start(context: Context, uri: Uri) { fun start(context: Context, uri: Uri) {
if (!isRunning(context)) { if (isRunning(context)) return
val intent = Intent(context, BackupRestoreService::class.java).apply { val intent = Intent(context, BackupRestoreService::class.java).apply {
putExtra(BackupConst.EXTRA_URI, uri) putExtra(BackupConst.EXTRA_URI, uri)
} }
ContextCompat.startForegroundService(context, intent) ContextCompat.startForegroundService(context, intent)
} }
}
/** /**
* Stops the service. * Stops the service.

View file

@ -166,14 +166,14 @@ class AppUpdateService : Service() {
* @param url the url to the new update. * @param url the url to the new update.
*/ */
fun start(context: Context, url: String, title: String? = context.getString(R.string.app_name)) { fun start(context: Context, url: String, title: String? = context.getString(R.string.app_name)) {
if (!isRunning(context)) { if (isRunning(context)) return
val intent = Intent(context, AppUpdateService::class.java).apply { val intent = Intent(context, AppUpdateService::class.java).apply {
putExtra(EXTRA_DOWNLOAD_TITLE, title) putExtra(EXTRA_DOWNLOAD_TITLE, title)
putExtra(EXTRA_DOWNLOAD_URL, url) putExtra(EXTRA_DOWNLOAD_URL, url)
} }
ContextCompat.startForegroundService(context, intent) ContextCompat.startForegroundService(context, intent)
} }
}
/** /**
* Stops the service. * Stops the service.

View file

@ -50,7 +50,8 @@ internal class ExtensionInstallReceiver(private val listener: Listener) :
when (intent.action) { when (intent.action) {
Intent.ACTION_PACKAGE_ADDED -> { Intent.ACTION_PACKAGE_ADDED -> {
if (!isReplacing(intent)) { if (isReplacing(intent)) return
launchNow { launchNow {
when (val result = getExtensionFromIntent(context, intent)) { when (val result = getExtensionFromIntent(context, intent)) {
is LoadResult.Success -> listener.onExtensionInstalled(result.extension) is LoadResult.Success -> listener.onExtensionInstalled(result.extension)
@ -59,7 +60,6 @@ internal class ExtensionInstallReceiver(private val listener: Listener) :
} }
} }
} }
}
Intent.ACTION_PACKAGE_REPLACED -> { Intent.ACTION_PACKAGE_REPLACED -> {
launchNow { launchNow {
when (val result = getExtensionFromIntent(context, intent)) { when (val result = getExtensionFromIntent(context, intent)) {
@ -71,7 +71,8 @@ internal class ExtensionInstallReceiver(private val listener: Listener) :
} }
} }
Intent.ACTION_PACKAGE_REMOVED -> { Intent.ACTION_PACKAGE_REMOVED -> {
if (!isReplacing(intent)) { if (isReplacing(intent)) return
val pkgName = getPackageNameFromIntent(intent) val pkgName = getPackageNameFromIntent(intent)
if (pkgName != null) { if (pkgName != null) {
listener.onPackageUninstalled(pkgName) listener.onPackageUninstalled(pkgName)
@ -79,7 +80,6 @@ internal class ExtensionInstallReceiver(private val listener: Listener) :
} }
} }
} }
}
/** /**
* Returns true if this package is performing an update. * Returns true if this package is performing an update.

View file

@ -90,6 +90,7 @@ import eu.kanade.tachiyomi.util.view.setComposeContent
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -243,8 +244,8 @@ class MainActivity : BaseActivity() {
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
preferences.incognitoMode().changes() preferences.incognitoMode().changes()
.drop(1) .drop(1)
.filter { !it }
.onEach { .onEach {
if (!it) {
val currentScreen = navigator.lastItem val currentScreen = navigator.lastItem
if (currentScreen is BrowseSourceScreen || if (currentScreen is BrowseSourceScreen ||
(currentScreen is MangaScreen && currentScreen.fromSource) (currentScreen is MangaScreen && currentScreen.fromSource)
@ -252,7 +253,6 @@ class MainActivity : BaseActivity() {
navigator.popUntilRoot() navigator.popUntilRoot()
} }
} }
}
.launchIn(this) .launchIn(this)
} }

View file

@ -389,12 +389,12 @@ class MangaInfoScreenModel(
fun moveMangaToCategoriesAndAddToLibrary(manga: Manga, categories: List<Long>) { fun moveMangaToCategoriesAndAddToLibrary(manga: Manga, categories: List<Long>) {
moveMangaToCategory(categories) moveMangaToCategory(categories)
if (!manga.favorite) { if (manga.favorite) return
coroutineScope.launchIO { coroutineScope.launchIO {
updateManga.awaitUpdateFavorite(manga.id, true) updateManga.awaitUpdateFavorite(manga.id, true)
} }
} }
}
/** /**
* Move the given manga to categories. * Move the given manga to categories.

View file

@ -532,18 +532,15 @@ class ReaderViewModel(
* Saves this [readerChapter] last read history if incognito mode isn't on. * Saves this [readerChapter] last read history if incognito mode isn't on.
*/ */
private suspend fun saveChapterHistory(readerChapter: ReaderChapter) { private suspend fun saveChapterHistory(readerChapter: ReaderChapter) {
if (!incognitoMode) { if (incognitoMode) return
val chapterId = readerChapter.chapter.id!!
val readAt = Date()
val sessionReadDuration = chapterReadStartTime?.let { readAt.time - it } ?: 0
upsertHistory.await( val chapterId = readerChapter.chapter.id!!
HistoryUpdate(chapterId, readAt, sessionReadDuration), val endTime = Date()
).also { val sessionReadDuration = chapterReadStartTime?.let { endTime.time - it } ?: 0
upsertHistory.await(HistoryUpdate(chapterId, endTime, sessionReadDuration))
chapterReadStartTime = null chapterReadStartTime = null
} }
}
}
fun setReadStartTime() { fun setReadStartTime() {
chapterReadStartTime = Date().time chapterReadStartTime = Date().time

View file

@ -83,6 +83,7 @@ suspend fun Call.await(): Response {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
// Don't bother with resuming the continuation if it is already cancelled. // Don't bother with resuming the continuation if it is already cancelled.
if (continuation.isCancelled) return if (continuation.isCancelled) return
continuation.resumeWithException(e) continuation.resumeWithException(e)
} }
}, },