disable smart-update for individual & fix custom interval (#318)
* set custom disabled interval * fix wrong calculation of nextUpdate when setting custom fetchInterval --------- Co-authored-by: Cuong-Tran <cuongtran.tm@gmail.com>
This commit is contained in:
parent
6c9dfb82f4
commit
ba43e5584c
4 changed files with 60 additions and 16 deletions
|
|
@ -595,6 +595,7 @@ private fun MangaScreenSmallImpl(
|
|||
// SY <--
|
||||
// KMK -->
|
||||
status = state.manga.status,
|
||||
interval = state.manga.fetchInterval,
|
||||
// KMK <--
|
||||
)
|
||||
}
|
||||
|
|
@ -1000,6 +1001,7 @@ private fun MangaScreenLargeImpl(
|
|||
// SY <--
|
||||
// KMK -->
|
||||
status = state.manga.status,
|
||||
interval = state.manga.fetchInterval,
|
||||
// KMK <--
|
||||
)
|
||||
// SY -->
|
||||
|
|
|
|||
|
|
@ -117,20 +117,38 @@ fun SetIntervalDialog(
|
|||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
val size = DpSize(width = maxWidth / 2, height = 128.dp)
|
||||
val items = (0..FetchInterval.MAX_INTERVAL)
|
||||
.map {
|
||||
if (it == 0) {
|
||||
stringResource(MR.strings.label_default)
|
||||
} else {
|
||||
it.toString()
|
||||
}
|
||||
}
|
||||
.toImmutableList()
|
||||
val items =
|
||||
// KMK -->
|
||||
(
|
||||
listOf(stringResource(MR.strings.action_disable)) +
|
||||
// KMK <--
|
||||
(0..FetchInterval.MAX_INTERVAL)
|
||||
.map {
|
||||
if (it == 0) {
|
||||
stringResource(MR.strings.label_default)
|
||||
} else {
|
||||
it.toString()
|
||||
}
|
||||
}
|
||||
)
|
||||
.toImmutableList()
|
||||
WheelTextPicker(
|
||||
items = items,
|
||||
size = size,
|
||||
startIndex = selectedInterval,
|
||||
onSelectionChanged = { selectedInterval = it },
|
||||
startIndex = (
|
||||
selectedInterval +
|
||||
// KMK -->
|
||||
1
|
||||
).takeIf { selectedInterval != FetchInterval.MANUAL_DISABLE } ?: 0,
|
||||
// KMK <--
|
||||
onSelectionChanged = { idx ->
|
||||
selectedInterval = (
|
||||
idx -
|
||||
// KMK -->
|
||||
1
|
||||
).takeIf { idx != 0 } ?: FetchInterval.MANUAL_DISABLE
|
||||
// KMK <--
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import androidx.compose.material.icons.Icons
|
|||
import androidx.compose.material.icons.automirrored.outlined.CallMerge
|
||||
import androidx.compose.material.icons.filled.Brush
|
||||
import androidx.compose.material.icons.filled.Favorite
|
||||
import androidx.compose.material.icons.filled.HourglassDisabled
|
||||
import androidx.compose.material.icons.filled.HourglassEmpty
|
||||
import androidx.compose.material.icons.filled.PersonOutline
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
|
|
@ -51,6 +52,7 @@ import androidx.compose.material3.Text
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
|
|
@ -83,6 +85,7 @@ import eu.kanade.tachiyomi.source.model.SManga
|
|||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED
|
||||
import tachiyomi.domain.manga.interactor.FetchInterval
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.i18n.MR
|
||||
import tachiyomi.i18n.kmk.KMR
|
||||
|
|
@ -205,21 +208,31 @@ fun MangaActionRow(
|
|||
// SY <--
|
||||
// KMK -->
|
||||
status: Long,
|
||||
interval: Int,
|
||||
// KMK <--
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
// KMK -->
|
||||
val libraryPreferences: LibraryPreferences = Injekt.get()
|
||||
val restrictions = libraryPreferences.autoUpdateMangaRestrictions().get()
|
||||
val isSkipCompleted = MANGA_NON_COMPLETED !in restrictions || status != SManga.COMPLETED.toLong()
|
||||
val notSkipCompleted = MANGA_NON_COMPLETED !in restrictions || status != SManga.COMPLETED.toLong()
|
||||
val selectedInterval by remember(interval) { mutableIntStateOf(if (interval < 0) -interval else 0) }
|
||||
// KMK <--
|
||||
val defaultActionButtonColor = MaterialTheme.colorScheme.onSurface.copy(alpha = DISABLED_ALPHA)
|
||||
|
||||
// TODO: show something better when using custom interval
|
||||
val nextUpdateDays = remember(nextUpdate) {
|
||||
return@remember if (nextUpdate != null && isSkipCompleted) {
|
||||
val nextUpdateDays = remember(nextUpdate, selectedInterval, notSkipCompleted) {
|
||||
return@remember if (nextUpdate != null &&
|
||||
// KMK -->
|
||||
notSkipCompleted
|
||||
// KMK <--
|
||||
) {
|
||||
val now = Instant.now()
|
||||
now.until(nextUpdate, ChronoUnit.DAYS).toInt().coerceAtLeast(0)
|
||||
// KMK -->
|
||||
.takeIf { selectedInterval != FetchInterval.MANUAL_DISABLE }
|
||||
?: FetchInterval.MANUAL_DISABLE
|
||||
// KMK <--
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
@ -241,13 +254,20 @@ fun MangaActionRow(
|
|||
title = when (nextUpdateDays) {
|
||||
null -> stringResource(MR.strings.not_applicable)
|
||||
0 -> stringResource(MR.strings.manga_interval_expected_update_soon)
|
||||
// KMK -->
|
||||
FetchInterval.MANUAL_DISABLE -> stringResource(MR.strings.disabled)
|
||||
// KMK <--
|
||||
else -> pluralStringResource(
|
||||
MR.plurals.day,
|
||||
count = nextUpdateDays,
|
||||
nextUpdateDays,
|
||||
)
|
||||
},
|
||||
icon = Icons.Default.HourglassEmpty,
|
||||
icon = Icons.Default.HourglassEmpty
|
||||
// KMK -->
|
||||
.takeIf { nextUpdateDays != FetchInterval.MANUAL_DISABLE }
|
||||
?: Icons.Default.HourglassDisabled,
|
||||
// KMK <--
|
||||
color = if (isUserIntervalMode ||
|
||||
// KMK -->
|
||||
nextUpdateDays?.let { it <= 1 } == true
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class FetchInterval(
|
|||
interval.absoluteValue.takeIf { interval < 0 }
|
||||
?: increaseInterval(interval, timeSinceLatest, increaseWhenOver = 10),
|
||||
)
|
||||
return latestDate.plusDays((cycle + 1) * interval.toLong()).toEpochSecond(dateTime.offset) * 1000
|
||||
return latestDate.plusDays((cycle + 1) * interval.absoluteValue.toLong()).toEpochSecond(dateTime.offset) * 1000
|
||||
}
|
||||
|
||||
private fun increaseInterval(delta: Int, timeSinceLatest: Int, increaseWhenOver: Int): Int {
|
||||
|
|
@ -126,5 +126,9 @@ class FetchInterval(
|
|||
const val MAX_INTERVAL = 28
|
||||
|
||||
private const val GRACE_PERIOD = 1L
|
||||
|
||||
// KMK -->
|
||||
const val MANUAL_DISABLE = 99999 // 274 years in future
|
||||
// KMK <--
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue