mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Abstract out library last updated timespan text
So we can reuse it for showing last automatic backup time.
This commit is contained in:
parent
ce5e10be95
commit
298c49f3ab
4 changed files with 21 additions and 21 deletions
|
@ -109,9 +109,7 @@ fun UpdateScreen(
|
|||
FastScrollLazyColumn(
|
||||
contentPadding = contentPadding,
|
||||
) {
|
||||
if (lastUpdated > 0L) {
|
||||
updatesLastUpdatedItem(lastUpdated)
|
||||
}
|
||||
updatesLastUpdatedItem(lastUpdated)
|
||||
|
||||
updatesUiItems(
|
||||
uiModels = state.getUiModel(context, relativeTime),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package eu.kanade.presentation.updates
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
@ -27,7 +26,6 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
|
@ -39,6 +37,7 @@ import eu.kanade.presentation.manga.components.ChapterDownloadAction
|
|||
import eu.kanade.presentation.manga.components.ChapterDownloadIndicator
|
||||
import eu.kanade.presentation.manga.components.DotSeparatorText
|
||||
import eu.kanade.presentation.manga.components.MangaCover
|
||||
import eu.kanade.presentation.util.relativeTimeSpanString
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.ui.updates.UpdatesItem
|
||||
|
@ -47,33 +46,18 @@ import tachiyomi.presentation.core.components.ListGroupHeader
|
|||
import tachiyomi.presentation.core.components.material.ReadItemAlpha
|
||||
import tachiyomi.presentation.core.components.material.padding
|
||||
import tachiyomi.presentation.core.util.selectedBackground
|
||||
import java.util.Date
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
internal fun LazyListScope.updatesLastUpdatedItem(
|
||||
lastUpdated: Long,
|
||||
) {
|
||||
item(key = "updates-lastUpdated") {
|
||||
val time = remember(lastUpdated) {
|
||||
val now = Date().time
|
||||
if (now - lastUpdated < 1.minutes.inWholeMilliseconds) {
|
||||
null
|
||||
} else {
|
||||
DateUtils.getRelativeTimeSpanString(lastUpdated, now, DateUtils.MINUTE_IN_MILLIS)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.animateItemPlacement()
|
||||
.padding(horizontal = MaterialTheme.padding.medium, vertical = MaterialTheme.padding.small),
|
||||
) {
|
||||
Text(
|
||||
text = if (time.isNullOrEmpty()) {
|
||||
stringResource(R.string.updates_last_update_info, stringResource(R.string.updates_last_update_info_just_now))
|
||||
} else {
|
||||
stringResource(R.string.updates_last_update_info, time)
|
||||
},
|
||||
text = stringResource(R.string.updates_last_update_info, relativeTimeSpanString(lastUpdated)),
|
||||
fontStyle = FontStyle.Italic,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
package eu.kanade.presentation.util
|
||||
|
||||
import android.content.Context
|
||||
import android.text.format.DateUtils
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import eu.kanade.tachiyomi.R
|
||||
import java.util.Date
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
fun Duration.toDurationString(context: Context, fallback: String): String {
|
||||
return toComponents { days, hours, minutes, seconds, _ ->
|
||||
|
@ -14,3 +20,14 @@ fun Duration.toDurationString(context: Context, fallback: String): String {
|
|||
}.joinToString(" ").ifBlank { fallback }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun relativeTimeSpanString(epochMillis: Long): String {
|
||||
val now = Date().time
|
||||
return when {
|
||||
epochMillis <= 0L -> stringResource(R.string.relative_time_span_never)
|
||||
now - epochMillis < 1.minutes.inWholeMilliseconds -> stringResource(R.string.updates_last_update_info_just_now)
|
||||
else -> DateUtils.getRelativeTimeSpanString(epochMillis, now, DateUtils.MINUTE_IN_MILLIS).toString()
|
||||
}
|
||||
}
|
|
@ -782,6 +782,7 @@
|
|||
<string name="cant_open_last_read_chapter">Unable to open last read chapter</string>
|
||||
<string name="updates_last_update_info">Library last updated: %s</string>
|
||||
<string name="updates_last_update_info_just_now">Just now</string>
|
||||
<string name="relative_time_span_never">Never</string>
|
||||
|
||||
<!-- History -->
|
||||
<string name="recent_manga_time">Ch. %1$s - %2$s</string>
|
||||
|
|
Loading…
Reference in a new issue