Show next expected update in interval dialog

Related: #9793
This commit is contained in:
arkon 2023-12-30 19:15:52 -05:00
parent 3d0d5c0472
commit 54f4711f7b
4 changed files with 59 additions and 25 deletions

View file

@ -13,9 +13,11 @@ import java.util.Date
@Composable @Composable
fun relativeDateText( fun relativeDateText(
date: Long, dateEpochMillis: Long,
): String { ): String {
return relativeDateText(date = Date(date).takeIf { date > 0L }) return relativeDateText(
date = Date(dateEpochMillis).takeIf { dateEpochMillis > 0L },
)
} }
@Composable @Composable
@ -30,9 +32,9 @@ fun relativeDateText(
return date return date
?.toRelativeString( ?.toRelativeString(
context, context = context,
relativeTime, relative = relativeTime,
dateFormat, dateFormat = dateFormat,
) )
?: stringResource(MR.strings.not_applicable) ?: stringResource(MR.strings.not_applicable)
} }

View file

@ -1,6 +1,7 @@
package eu.kanade.presentation.manga.components package eu.kanade.presentation.manga.components
import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -8,6 +9,7 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -18,7 +20,10 @@ import kotlinx.collections.immutable.toImmutableList
import tachiyomi.domain.manga.interactor.FetchInterval import tachiyomi.domain.manga.interactor.FetchInterval
import tachiyomi.i18n.MR import tachiyomi.i18n.MR
import tachiyomi.presentation.core.components.WheelTextPicker import tachiyomi.presentation.core.components.WheelTextPicker
import tachiyomi.presentation.core.i18n.pluralStringResource
import tachiyomi.presentation.core.i18n.stringResource import tachiyomi.presentation.core.i18n.stringResource
import java.time.Instant
import java.time.temporal.ChronoUnit
@Composable @Composable
fun DeleteChaptersDialog( fun DeleteChaptersDialog(
@ -54,15 +59,38 @@ fun DeleteChaptersDialog(
@Composable @Composable
fun SetIntervalDialog( fun SetIntervalDialog(
interval: Int, interval: Int,
nextUpdate: Long,
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
onValueChanged: (Int) -> Unit, onValueChanged: (Int) -> Unit,
) { ) {
var selectedInterval by rememberSaveable { mutableIntStateOf(if (interval < 0) -interval else 0) } var selectedInterval by rememberSaveable { mutableIntStateOf(if (interval < 0) -interval else 0) }
val nextUpdateDays = remember(nextUpdate) {
val now = Instant.now()
val nextUpdateInstant = Instant.ofEpochMilli(nextUpdate)
now.until(nextUpdateInstant, ChronoUnit.DAYS)
}
AlertDialog( AlertDialog(
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
title = { Text(text = stringResource(MR.strings.manga_modify_calculated_interval_title)) }, title = { Text(stringResource(MR.strings.manga_modify_calculated_interval_title)) },
text = { text = {
Column {
// TODO: figure out why nextUpdate is a weird number sometimes
if (nextUpdateDays >= 0) {
Text(
stringResource(
MR.strings.manga_interval_expected_update,
pluralStringResource(
MR.plurals.day,
count = nextUpdateDays.toInt(),
nextUpdateDays,
),
),
)
}
BoxWithConstraints( BoxWithConstraints(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
@ -84,6 +112,7 @@ fun SetIntervalDialog(
onSelectionChanged = { selectedInterval = it }, onSelectionChanged = { selectedInterval = it },
) )
} }
}
}, },
dismissButton = { dismissButton = {
TextButton(onClick = onDismissRequest) { TextButton(onClick = onDismissRequest) {

View file

@ -243,6 +243,7 @@ class MangaScreen(
is MangaScreenModel.Dialog.SetFetchInterval -> { is MangaScreenModel.Dialog.SetFetchInterval -> {
SetIntervalDialog( SetIntervalDialog(
interval = dialog.manga.fetchInterval, interval = dialog.manga.fetchInterval,
nextUpdate = dialog.manga.nextUpdate,
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
onValueChanged = { screenModel.setFetchInterval(dialog.manga, it) }, onValueChanged = { screenModel.setFetchInterval(dialog.manga, it) },
) )

View file

@ -669,6 +669,8 @@
<string name="display_mode_chapter">Chapter %1$s</string> <string name="display_mode_chapter">Chapter %1$s</string>
<string name="manga_display_interval_title">Estimate every</string> <string name="manga_display_interval_title">Estimate every</string>
<string name="manga_display_modified_interval_title">Set to update every</string> <string name="manga_display_modified_interval_title">Set to update every</string>
<!-- "... around 2 days" -->
<string name="manga_interval_expected_update">Next update expected in around %s</string>
<string name="manga_modify_calculated_interval_title">Customize interval</string> <string name="manga_modify_calculated_interval_title">Customize interval</string>
<string name="chapter_downloading_progress">Downloading (%1$d/%2$d)</string> <string name="chapter_downloading_progress">Downloading (%1$d/%2$d)</string>
<string name="chapter_error">Error</string> <string name="chapter_error">Error</string>