Use duration overload for time related methods
This commit is contained in:
@@ -58,8 +58,6 @@ import tachiyomi.presentation.core.util.runOnEnterKeyPressed
|
||||
import tachiyomi.presentation.core.util.secondaryItemAlpha
|
||||
import tachiyomi.presentation.core.util.showSoftKeyboard
|
||||
|
||||
const val SEARCH_DEBOUNCE_MILLIS = 250L
|
||||
|
||||
@Composable
|
||||
fun AppBar(
|
||||
title: String?,
|
||||
|
||||
@@ -91,7 +91,7 @@ class DownloadCache(
|
||||
|
||||
private val _isInitializing = MutableStateFlow(false)
|
||||
val isInitializing = _isInitializing
|
||||
.debounce(1000L) // Don't notify if it finishes quickly enough
|
||||
.debounce(1.seconds) // Don't notify if it finishes quickly enough
|
||||
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
|
||||
|
||||
private val diskCacheFile: File
|
||||
@@ -433,7 +433,7 @@ class DownloadCache(
|
||||
private fun updateDiskCache() {
|
||||
updateDiskCacheJob?.cancel()
|
||||
updateDiskCacheJob = scope.launchIO {
|
||||
delay(1000)
|
||||
delay(1.seconds)
|
||||
ensureActive()
|
||||
val bytes = ProtoBuf.encodeToByteArray(rootDownloadsDir)
|
||||
ensureActive()
|
||||
|
||||
@@ -60,6 +60,7 @@ import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
/**
|
||||
* This class is the one in charge of downloading chapters.
|
||||
@@ -502,7 +503,7 @@ class Downloader(
|
||||
// Retry 3 times, waiting 2, 4 and 8 seconds between attempts.
|
||||
.retryWhen { _, attempt ->
|
||||
if (attempt < 3) {
|
||||
delay((2L shl attempt.toInt()) * 1000)
|
||||
delay((2L shl attempt.toInt()).seconds)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
@@ -17,6 +17,7 @@ import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
data class Download(
|
||||
val source: HttpSource,
|
||||
@@ -47,7 +48,7 @@ data class Download(
|
||||
if (pages == null) {
|
||||
emit(0)
|
||||
while (pages == null) {
|
||||
delay(50)
|
||||
delay(50.milliseconds)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ data class Download(
|
||||
emitAll(combine(progressFlows) { it.average().toInt() })
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.debounce(50)
|
||||
.debounce(50.milliseconds)
|
||||
|
||||
val progress: Int
|
||||
get() {
|
||||
|
||||
@@ -8,7 +8,6 @@ import dev.icerock.moko.resources.StringResource
|
||||
import eu.kanade.domain.base.BasePreferences
|
||||
import eu.kanade.domain.extension.interactor.GetExtensionsByType
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.presentation.components.SEARCH_DEBOUNCE_MILLIS
|
||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||
@@ -56,7 +55,7 @@ class ExtensionsScreenModel(
|
||||
combine(
|
||||
state.map { it.searchQuery }
|
||||
.distinctUntilChanged()
|
||||
.debounce(SEARCH_DEBOUNCE_MILLIS)
|
||||
.debounce(0.25.seconds)
|
||||
.map { searchQueryPredicate(it ?: "") },
|
||||
currentDownloads,
|
||||
getExtensions.subscribe(),
|
||||
|
||||
@@ -23,6 +23,7 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
class DownloadQueueScreenModel(
|
||||
private val downloadManager: DownloadManager = Injekt.get(),
|
||||
@@ -212,13 +213,13 @@ class DownloadQueueScreenModel(
|
||||
private fun launchProgressJob(download: Download) {
|
||||
val job = screenModelScope.launch {
|
||||
while (download.pages == null) {
|
||||
delay(50)
|
||||
delay(50.milliseconds)
|
||||
}
|
||||
|
||||
val progressFlows = download.pages!!.map(Page::progressFlow)
|
||||
combine(progressFlows, Array<Int>::sum)
|
||||
.distinctUntilChanged()
|
||||
.debounce(50)
|
||||
.debounce(50.milliseconds)
|
||||
.collectLatest {
|
||||
onUpdateProgress(download)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import eu.kanade.core.util.fastFilterNot
|
||||
import eu.kanade.domain.base.BasePreferences
|
||||
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
import eu.kanade.presentation.components.SEARCH_DEBOUNCE_MILLIS
|
||||
import eu.kanade.presentation.library.components.LibraryToolbarTitle
|
||||
import eu.kanade.presentation.manga.DownloadAction
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
@@ -65,6 +64,7 @@ import tachiyomi.source.local.isLocal
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlin.random.Random
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
class LibraryScreenModel(
|
||||
private val getLibraryManga: GetLibraryManga = Injekt.get(),
|
||||
@@ -91,7 +91,7 @@ class LibraryScreenModel(
|
||||
}
|
||||
screenModelScope.launchIO {
|
||||
combine(
|
||||
state.map { it.searchQuery }.distinctUntilChanged().debounce(SEARCH_DEBOUNCE_MILLIS),
|
||||
state.map { it.searchQuery }.distinctUntilChanged().debounce(0.25.seconds),
|
||||
getCategories.subscribe(),
|
||||
getFavoritesFlow(),
|
||||
combine(getTracksPerManga.subscribe(), getTrackingFiltersFlow(), ::Pair),
|
||||
|
||||
@@ -105,6 +105,7 @@ import tachiyomi.presentation.core.util.collectAsState
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.ByteArrayOutputStream
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
class ReaderActivity : BaseActivity() {
|
||||
|
||||
@@ -947,7 +948,7 @@ class ReaderActivity : BaseActivity() {
|
||||
private fun setCustomBrightness(enabled: Boolean) {
|
||||
if (enabled) {
|
||||
readerPreferences.customBrightnessValue.changes()
|
||||
.sample(100)
|
||||
.sample(0.1.seconds)
|
||||
.onEach(::setCustomBrightnessValue)
|
||||
.launchIn(lifecycleScope)
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.work.WorkManager
|
||||
import kotlinx.coroutines.delay
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.common.util.system.logcat
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
val Context.workManager: WorkManager
|
||||
get() = WorkManager.getInstance(this)
|
||||
@@ -28,7 +29,7 @@ fun WorkManager.isRunning(tag: String): Boolean {
|
||||
suspend fun CoroutineWorker.setForegroundSafely() {
|
||||
try {
|
||||
setForeground(getForegroundInfo())
|
||||
delay(500)
|
||||
delay(0.5.seconds)
|
||||
} catch (e: IllegalStateException) {
|
||||
logcat(LogPriority.ERROR, e) { "Not allowed to set foreground job" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user