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 <--
|
// SY <--
|
||||||
// KMK -->
|
// KMK -->
|
||||||
status = state.manga.status,
|
status = state.manga.status,
|
||||||
|
interval = state.manga.fetchInterval,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1000,6 +1001,7 @@ private fun MangaScreenLargeImpl(
|
||||||
// SY <--
|
// SY <--
|
||||||
// KMK -->
|
// KMK -->
|
||||||
status = state.manga.status,
|
status = state.manga.status,
|
||||||
|
interval = state.manga.fetchInterval,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
)
|
)
|
||||||
// SY -->
|
// SY -->
|
||||||
|
|
|
||||||
|
|
@ -117,20 +117,38 @@ fun SetIntervalDialog(
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
val size = DpSize(width = maxWidth / 2, height = 128.dp)
|
val size = DpSize(width = maxWidth / 2, height = 128.dp)
|
||||||
val items = (0..FetchInterval.MAX_INTERVAL)
|
val items =
|
||||||
.map {
|
// KMK -->
|
||||||
if (it == 0) {
|
(
|
||||||
stringResource(MR.strings.label_default)
|
listOf(stringResource(MR.strings.action_disable)) +
|
||||||
} else {
|
// KMK <--
|
||||||
it.toString()
|
(0..FetchInterval.MAX_INTERVAL)
|
||||||
}
|
.map {
|
||||||
}
|
if (it == 0) {
|
||||||
.toImmutableList()
|
stringResource(MR.strings.label_default)
|
||||||
|
} else {
|
||||||
|
it.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.toImmutableList()
|
||||||
WheelTextPicker(
|
WheelTextPicker(
|
||||||
items = items,
|
items = items,
|
||||||
size = size,
|
size = size,
|
||||||
startIndex = selectedInterval,
|
startIndex = (
|
||||||
onSelectionChanged = { selectedInterval = it },
|
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.automirrored.outlined.CallMerge
|
||||||
import androidx.compose.material.icons.filled.Brush
|
import androidx.compose.material.icons.filled.Brush
|
||||||
import androidx.compose.material.icons.filled.Favorite
|
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.HourglassEmpty
|
||||||
import androidx.compose.material.icons.filled.PersonOutline
|
import androidx.compose.material.icons.filled.PersonOutline
|
||||||
import androidx.compose.material.icons.filled.Warning
|
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.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
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 eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||||
import tachiyomi.domain.library.service.LibraryPreferences
|
import tachiyomi.domain.library.service.LibraryPreferences
|
||||||
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED
|
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED
|
||||||
|
import tachiyomi.domain.manga.interactor.FetchInterval
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.i18n.kmk.KMR
|
import tachiyomi.i18n.kmk.KMR
|
||||||
|
|
@ -205,21 +208,31 @@ fun MangaActionRow(
|
||||||
// SY <--
|
// SY <--
|
||||||
// KMK -->
|
// KMK -->
|
||||||
status: Long,
|
status: Long,
|
||||||
|
interval: Int,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
// KMK -->
|
// KMK -->
|
||||||
val libraryPreferences: LibraryPreferences = Injekt.get()
|
val libraryPreferences: LibraryPreferences = Injekt.get()
|
||||||
val restrictions = libraryPreferences.autoUpdateMangaRestrictions().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 <--
|
// KMK <--
|
||||||
val defaultActionButtonColor = MaterialTheme.colorScheme.onSurface.copy(alpha = DISABLED_ALPHA)
|
val defaultActionButtonColor = MaterialTheme.colorScheme.onSurface.copy(alpha = DISABLED_ALPHA)
|
||||||
|
|
||||||
// TODO: show something better when using custom interval
|
// TODO: show something better when using custom interval
|
||||||
val nextUpdateDays = remember(nextUpdate) {
|
val nextUpdateDays = remember(nextUpdate, selectedInterval, notSkipCompleted) {
|
||||||
return@remember if (nextUpdate != null && isSkipCompleted) {
|
return@remember if (nextUpdate != null &&
|
||||||
|
// KMK -->
|
||||||
|
notSkipCompleted
|
||||||
|
// KMK <--
|
||||||
|
) {
|
||||||
val now = Instant.now()
|
val now = Instant.now()
|
||||||
now.until(nextUpdate, ChronoUnit.DAYS).toInt().coerceAtLeast(0)
|
now.until(nextUpdate, ChronoUnit.DAYS).toInt().coerceAtLeast(0)
|
||||||
|
// KMK -->
|
||||||
|
.takeIf { selectedInterval != FetchInterval.MANUAL_DISABLE }
|
||||||
|
?: FetchInterval.MANUAL_DISABLE
|
||||||
|
// KMK <--
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
@ -241,13 +254,20 @@ fun MangaActionRow(
|
||||||
title = when (nextUpdateDays) {
|
title = when (nextUpdateDays) {
|
||||||
null -> stringResource(MR.strings.not_applicable)
|
null -> stringResource(MR.strings.not_applicable)
|
||||||
0 -> stringResource(MR.strings.manga_interval_expected_update_soon)
|
0 -> stringResource(MR.strings.manga_interval_expected_update_soon)
|
||||||
|
// KMK -->
|
||||||
|
FetchInterval.MANUAL_DISABLE -> stringResource(MR.strings.disabled)
|
||||||
|
// KMK <--
|
||||||
else -> pluralStringResource(
|
else -> pluralStringResource(
|
||||||
MR.plurals.day,
|
MR.plurals.day,
|
||||||
count = nextUpdateDays,
|
count = nextUpdateDays,
|
||||||
nextUpdateDays,
|
nextUpdateDays,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
icon = Icons.Default.HourglassEmpty,
|
icon = Icons.Default.HourglassEmpty
|
||||||
|
// KMK -->
|
||||||
|
.takeIf { nextUpdateDays != FetchInterval.MANUAL_DISABLE }
|
||||||
|
?: Icons.Default.HourglassDisabled,
|
||||||
|
// KMK <--
|
||||||
color = if (isUserIntervalMode ||
|
color = if (isUserIntervalMode ||
|
||||||
// KMK -->
|
// KMK -->
|
||||||
nextUpdateDays?.let { it <= 1 } == true
|
nextUpdateDays?.let { it <= 1 } == true
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class FetchInterval(
|
||||||
interval.absoluteValue.takeIf { interval < 0 }
|
interval.absoluteValue.takeIf { interval < 0 }
|
||||||
?: increaseInterval(interval, timeSinceLatest, increaseWhenOver = 10),
|
?: 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 {
|
private fun increaseInterval(delta: Int, timeSinceLatest: Int, increaseWhenOver: Int): Int {
|
||||||
|
|
@ -126,5 +126,9 @@ class FetchInterval(
|
||||||
const val MAX_INTERVAL = 28
|
const val MAX_INTERVAL = 28
|
||||||
|
|
||||||
private const val GRACE_PERIOD = 1L
|
private const val GRACE_PERIOD = 1L
|
||||||
|
|
||||||
|
// KMK -->
|
||||||
|
const val MANUAL_DISABLE = 99999 // 274 years in future
|
||||||
|
// KMK <--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue