From 5c868d784679b55e413366c5d4bdea75253bf8f4 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 22 Oct 2022 19:57:55 -0400 Subject: [PATCH] Use kotlin.time extensions in some more places --- .../presentation/category/components/CategoryDialogs.kt | 5 +++-- .../presentation/components/MangaBottomActionMenu.kt | 5 +++-- .../presentation/library/components/LibraryContent.kt | 3 ++- .../kanade/presentation/more/settings/PreferenceScreen.kt | 3 ++- .../more/settings/widget/BasePreferenceWidget.kt | 3 ++- .../java/eu/kanade/presentation/updates/UpdatesScreen.kt | 3 ++- .../eu/kanade/tachiyomi/data/download/DownloadCache.kt | 7 ++++--- .../main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 3 ++- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt b/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt index 9efa490a23..f26ef4e4eb 100644 --- a/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt +++ b/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.res.stringResource import eu.kanade.domain.category.model.Category import eu.kanade.tachiyomi.R import kotlinx.coroutines.delay +import kotlin.time.Duration.Companion.seconds @Composable fun CategoryCreateDialog( @@ -58,7 +59,7 @@ fun CategoryCreateDialog( LaunchedEffect(focusRequester) { // TODO: https://issuetracker.google.com/issues/204502668 - delay(100) + delay(0.1.seconds) focusRequester.requestFocus() } } @@ -106,7 +107,7 @@ fun CategoryRenameDialog( LaunchedEffect(focusRequester) { // TODO: https://issuetracker.google.com/issues/204502668 - delay(100) + delay(0.1.seconds) focusRequester.requestFocus() } } diff --git a/app/src/main/java/eu/kanade/presentation/components/MangaBottomActionMenu.kt b/app/src/main/java/eu/kanade/presentation/components/MangaBottomActionMenu.kt index 2623a2dff4..573e02114a 100644 --- a/app/src/main/java/eu/kanade/presentation/components/MangaBottomActionMenu.kt +++ b/app/src/main/java/eu/kanade/presentation/components/MangaBottomActionMenu.kt @@ -53,6 +53,7 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch +import kotlin.time.Duration.Companion.seconds @Composable fun MangaBottomActionMenu( @@ -85,7 +86,7 @@ fun MangaBottomActionMenu( (0 until 7).forEach { i -> confirm[i] = i == toConfirmIndex } resetJob?.cancel() resetJob = scope.launch { - delay(1000) + delay(1.seconds) if (isActive) confirm[toConfirmIndex] = false } } @@ -232,7 +233,7 @@ fun LibraryBottomActionMenu( (0 until 5).forEach { i -> confirm[i] = i == toConfirmIndex } resetJob?.cancel() resetJob = scope.launch { - delay(1000) + delay(1.seconds) if (isActive) confirm[toConfirmIndex] = false } } diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt index fd969b910b..d03aa85057 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt @@ -25,6 +25,7 @@ import eu.kanade.presentation.library.LibraryState import eu.kanade.tachiyomi.ui.library.LibraryItem import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlin.time.Duration.Companion.seconds @Composable fun LibraryContent( @@ -95,7 +96,7 @@ fun LibraryContent( scope.launch { // Fake refresh status but hide it after a second as it's a long running task isRefreshing = true - delay(1000) + delay(1.seconds) isRefreshing = false } }, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScreen.kt index 0cce2ed918..46466f6b89 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceScreen.kt @@ -15,6 +15,7 @@ import eu.kanade.presentation.components.ScrollbarLazyColumn import eu.kanade.presentation.more.settings.screen.SearchableSettings import eu.kanade.presentation.more.settings.widget.PreferenceGroupHeader import kotlinx.coroutines.delay +import kotlin.time.Duration.Companion.seconds /** * Preference Screen composable which contains a list of [Preference] items @@ -33,7 +34,7 @@ fun PreferenceScreen( LaunchedEffect(Unit) { val i = items.findHighlightedIndex(highlightKey) if (i >= 0) { - delay(500) + delay(0.5.seconds) state.animateScrollToItem(i) } SearchableSettings.highlightKey = null diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt index 37b6d8d9c8..b7ffe63c37 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import eu.kanade.presentation.more.settings.LocalPreferenceHighlighted import kotlinx.coroutines.delay +import kotlin.time.Duration.Companion.seconds @Composable internal fun BasePreferenceWidget( @@ -89,7 +90,7 @@ internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier = comp LaunchedEffect(Unit) { if (highlighted) { highlightFlag = true - delay(3000) + delay(3.seconds) highlightFlag = false } } diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt index 3d3413783e..2a94356932 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt @@ -48,6 +48,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import java.util.Date +import kotlin.time.Duration.Companion.seconds @Composable fun UpdateScreen( @@ -135,7 +136,7 @@ private fun UpdateScreenContent( scope.launch { // Fake refresh status but hide it after a second as it's a long running task isRefreshing = true - delay(1000) + delay(1.seconds) isRefreshing = false } }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index 089d1e4e28..195ae46054 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -25,6 +25,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.TimeUnit +import kotlin.time.Duration.Companion.seconds /** * Cache where we dump the downloads directory from the filesystem. This class is needed because @@ -243,13 +244,13 @@ class DownloadCache( var sources = getSources() // Try to wait until extensions and sources have loaded - withTimeout(30000L) { + withTimeout(30.seconds) { while (!extensionManager.isInitialized) { - delay(2000L) + delay(2.seconds) } while (sources.isEmpty()) { - delay(2000L) + delay(2.seconds) sources = getSources() } } 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 a627afcdf4..6bb4c33701 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 @@ -78,6 +78,7 @@ import logcat.LogPriority import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy +import kotlin.time.Duration.Companion.seconds class MainActivity : BaseActivity() { @@ -550,7 +551,7 @@ class MainActivity : BaseActivity() { private suspend fun resetExitConfirmation() { isConfirmingExit = true val toast = toast(R.string.confirm_exit, Toast.LENGTH_LONG) - delay(2000) + delay(2.seconds) toast.cancel() isConfirmingExit = false }