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.secondaryItemAlpha
|
||||||
import tachiyomi.presentation.core.util.showSoftKeyboard
|
import tachiyomi.presentation.core.util.showSoftKeyboard
|
||||||
|
|
||||||
const val SEARCH_DEBOUNCE_MILLIS = 250L
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AppBar(
|
fun AppBar(
|
||||||
title: String?,
|
title: String?,
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class DownloadCache(
|
|||||||
|
|
||||||
private val _isInitializing = MutableStateFlow(false)
|
private val _isInitializing = MutableStateFlow(false)
|
||||||
val isInitializing = _isInitializing
|
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)
|
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
|
||||||
|
|
||||||
private val diskCacheFile: File
|
private val diskCacheFile: File
|
||||||
@@ -433,7 +433,7 @@ class DownloadCache(
|
|||||||
private fun updateDiskCache() {
|
private fun updateDiskCache() {
|
||||||
updateDiskCacheJob?.cancel()
|
updateDiskCacheJob?.cancel()
|
||||||
updateDiskCacheJob = scope.launchIO {
|
updateDiskCacheJob = scope.launchIO {
|
||||||
delay(1000)
|
delay(1.seconds)
|
||||||
ensureActive()
|
ensureActive()
|
||||||
val bytes = ProtoBuf.encodeToByteArray(rootDownloadsDir)
|
val bytes = ProtoBuf.encodeToByteArray(rootDownloadsDir)
|
||||||
ensureActive()
|
ensureActive()
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ import uy.kohesive.injekt.Injekt
|
|||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is the one in charge of downloading chapters.
|
* 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.
|
// Retry 3 times, waiting 2, 4 and 8 seconds between attempts.
|
||||||
.retryWhen { _, attempt ->
|
.retryWhen { _, attempt ->
|
||||||
if (attempt < 3) {
|
if (attempt < 3) {
|
||||||
delay((2L shl attempt.toInt()) * 1000)
|
delay((2L shl attempt.toInt()).seconds)
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import tachiyomi.domain.manga.model.Manga
|
|||||||
import tachiyomi.domain.source.service.SourceManager
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
data class Download(
|
data class Download(
|
||||||
val source: HttpSource,
|
val source: HttpSource,
|
||||||
@@ -47,7 +48,7 @@ data class Download(
|
|||||||
if (pages == null) {
|
if (pages == null) {
|
||||||
emit(0)
|
emit(0)
|
||||||
while (pages == null) {
|
while (pages == null) {
|
||||||
delay(50)
|
delay(50.milliseconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ data class Download(
|
|||||||
emitAll(combine(progressFlows) { it.average().toInt() })
|
emitAll(combine(progressFlows) { it.average().toInt() })
|
||||||
}
|
}
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.debounce(50)
|
.debounce(50.milliseconds)
|
||||||
|
|
||||||
val progress: Int
|
val progress: Int
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import dev.icerock.moko.resources.StringResource
|
|||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
import eu.kanade.domain.extension.interactor.GetExtensionsByType
|
import eu.kanade.domain.extension.interactor.GetExtensionsByType
|
||||||
import eu.kanade.domain.source.service.SourcePreferences
|
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.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||||
@@ -56,7 +55,7 @@ class ExtensionsScreenModel(
|
|||||||
combine(
|
combine(
|
||||||
state.map { it.searchQuery }
|
state.map { it.searchQuery }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.debounce(SEARCH_DEBOUNCE_MILLIS)
|
.debounce(0.25.seconds)
|
||||||
.map { searchQueryPredicate(it ?: "") },
|
.map { searchQueryPredicate(it ?: "") },
|
||||||
currentDownloads,
|
currentDownloads,
|
||||||
getExtensions.subscribe(),
|
getExtensions.subscribe(),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import kotlinx.coroutines.flow.update
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
class DownloadQueueScreenModel(
|
class DownloadQueueScreenModel(
|
||||||
private val downloadManager: DownloadManager = Injekt.get(),
|
private val downloadManager: DownloadManager = Injekt.get(),
|
||||||
@@ -212,13 +213,13 @@ class DownloadQueueScreenModel(
|
|||||||
private fun launchProgressJob(download: Download) {
|
private fun launchProgressJob(download: Download) {
|
||||||
val job = screenModelScope.launch {
|
val job = screenModelScope.launch {
|
||||||
while (download.pages == null) {
|
while (download.pages == null) {
|
||||||
delay(50)
|
delay(50.milliseconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
val progressFlows = download.pages!!.map(Page::progressFlow)
|
val progressFlows = download.pages!!.map(Page::progressFlow)
|
||||||
combine(progressFlows, Array<Int>::sum)
|
combine(progressFlows, Array<Int>::sum)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.debounce(50)
|
.debounce(50.milliseconds)
|
||||||
.collectLatest {
|
.collectLatest {
|
||||||
onUpdateProgress(download)
|
onUpdateProgress(download)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import eu.kanade.core.util.fastFilterNot
|
|||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
||||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
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.library.components.LibraryToolbarTitle
|
||||||
import eu.kanade.presentation.manga.DownloadAction
|
import eu.kanade.presentation.manga.DownloadAction
|
||||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
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.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
class LibraryScreenModel(
|
class LibraryScreenModel(
|
||||||
private val getLibraryManga: GetLibraryManga = Injekt.get(),
|
private val getLibraryManga: GetLibraryManga = Injekt.get(),
|
||||||
@@ -91,7 +91,7 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
screenModelScope.launchIO {
|
screenModelScope.launchIO {
|
||||||
combine(
|
combine(
|
||||||
state.map { it.searchQuery }.distinctUntilChanged().debounce(SEARCH_DEBOUNCE_MILLIS),
|
state.map { it.searchQuery }.distinctUntilChanged().debounce(0.25.seconds),
|
||||||
getCategories.subscribe(),
|
getCategories.subscribe(),
|
||||||
getFavoritesFlow(),
|
getFavoritesFlow(),
|
||||||
combine(getTracksPerManga.subscribe(), getTrackingFiltersFlow(), ::Pair),
|
combine(getTracksPerManga.subscribe(), getTrackingFiltersFlow(), ::Pair),
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ import tachiyomi.presentation.core.util.collectAsState
|
|||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
class ReaderActivity : BaseActivity() {
|
class ReaderActivity : BaseActivity() {
|
||||||
|
|
||||||
@@ -947,7 +948,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
private fun setCustomBrightness(enabled: Boolean) {
|
private fun setCustomBrightness(enabled: Boolean) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
readerPreferences.customBrightnessValue.changes()
|
readerPreferences.customBrightnessValue.changes()
|
||||||
.sample(100)
|
.sample(0.1.seconds)
|
||||||
.onEach(::setCustomBrightnessValue)
|
.onEach(::setCustomBrightnessValue)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.work.WorkManager
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
val Context.workManager: WorkManager
|
val Context.workManager: WorkManager
|
||||||
get() = WorkManager.getInstance(this)
|
get() = WorkManager.getInstance(this)
|
||||||
@@ -28,7 +29,7 @@ fun WorkManager.isRunning(tag: String): Boolean {
|
|||||||
suspend fun CoroutineWorker.setForegroundSafely() {
|
suspend fun CoroutineWorker.setForegroundSafely() {
|
||||||
try {
|
try {
|
||||||
setForeground(getForegroundInfo())
|
setForeground(getForegroundInfo())
|
||||||
delay(500)
|
delay(0.5.seconds)
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: IllegalStateException) {
|
||||||
logcat(LogPriority.ERROR, e) { "Not allowed to set foreground job" }
|
logcat(LogPriority.ERROR, e) { "Not allowed to set foreground job" }
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-5
@@ -56,6 +56,7 @@ import kotlin.math.abs
|
|||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws vertical fast scroller to a lazy list
|
* Draws vertical fast scroller to a lazy list
|
||||||
@@ -174,11 +175,11 @@ fun VerticalFastScroller(
|
|||||||
val isThumbVisible = alpha.value > 0f
|
val isThumbVisible = alpha.value > 0f
|
||||||
LaunchedEffect(scrolled, alpha) {
|
LaunchedEffect(scrolled, alpha) {
|
||||||
scrolled
|
scrolled
|
||||||
.sample(100)
|
.sample(0.1.seconds)
|
||||||
.collectLatest {
|
.collectLatest {
|
||||||
if (thumbAllowed()) {
|
if (thumbAllowed()) {
|
||||||
alpha.snapTo(1f)
|
alpha.snapTo(1f)
|
||||||
delay(ScrollBarVisibilityDurationMillis)
|
delay(ScrollBarVisibilityDuration)
|
||||||
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
||||||
} else {
|
} else {
|
||||||
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
||||||
@@ -364,11 +365,11 @@ fun VerticalGridFastScroller(
|
|||||||
val isThumbVisible = alpha.value > 0f
|
val isThumbVisible = alpha.value > 0f
|
||||||
LaunchedEffect(scrolled, alpha) {
|
LaunchedEffect(scrolled, alpha) {
|
||||||
scrolled
|
scrolled
|
||||||
.sample(100)
|
.sample(0.1.seconds)
|
||||||
.collectLatest {
|
.collectLatest {
|
||||||
if (thumbAllowed()) {
|
if (thumbAllowed()) {
|
||||||
alpha.snapTo(1f)
|
alpha.snapTo(1f)
|
||||||
delay(ScrollBarVisibilityDurationMillis)
|
delay(ScrollBarVisibilityDuration)
|
||||||
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
||||||
} else {
|
} else {
|
||||||
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
||||||
@@ -463,7 +464,7 @@ object Scroller {
|
|||||||
private val ThumbLength = 48.dp
|
private val ThumbLength = 48.dp
|
||||||
private val ThumbThickness = 12.dp
|
private val ThumbThickness = 12.dp
|
||||||
private val ThumbShape = RoundedCornerShape(ThumbThickness / 2)
|
private val ThumbShape = RoundedCornerShape(ThumbThickness / 2)
|
||||||
private val ScrollBarVisibilityDurationMillis = 2000L
|
private val ScrollBarVisibilityDuration = 2.seconds
|
||||||
private val ImmediateFadeOutAnimationSpec = tween<Float>(
|
private val ImmediateFadeOutAnimationSpec = tween<Float>(
|
||||||
durationMillis = ViewConfiguration.getScrollBarFadeDuration(),
|
durationMillis = ViewConfiguration.getScrollBarFadeDuration(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ import kotlinx.coroutines.flow.MutableSharedFlow
|
|||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.sample
|
import kotlinx.coroutines.flow.sample
|
||||||
import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX
|
import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws horizontal scrollbar to a LazyList.
|
* Draws horizontal scrollbar to a LazyList.
|
||||||
@@ -216,10 +218,10 @@ private fun Modifier.drawScrollbar(
|
|||||||
val alpha = remember { Animatable(0f) }
|
val alpha = remember { Animatable(0f) }
|
||||||
LaunchedEffect(scrolled, alpha) {
|
LaunchedEffect(scrolled, alpha) {
|
||||||
scrolled
|
scrolled
|
||||||
.sample(100)
|
.sample(0.1.seconds)
|
||||||
.collectLatest {
|
.collectLatest {
|
||||||
alpha.snapTo(1f)
|
alpha.snapTo(1f)
|
||||||
delay(ScrollBarVisibilityDurationMillis)
|
delay(ScrollBarVisibilityDurationMillis.milliseconds)
|
||||||
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
alpha.animateTo(0f, animationSpec = ImmediateFadeOutAnimationSpec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user