diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt index 310687e89..f965463af 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt @@ -163,6 +163,11 @@ fun UpdateScreen( state = updatesListState, contentPadding = contentPaddingWithNavBar, ) { + if (presenter.lastUpdated > 0L) { + item(key = "last_updated") { + UpdatesLastUpdatedItem(presenter.lastUpdated) + } + } updatesUiItems( uiModels = presenter.uiModels, selectionMode = presenter.selectionMode, diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt index 7b64f1ed3..a9f1abfc9 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt @@ -1,7 +1,9 @@ package eu.kanade.presentation.updates +import android.text.format.DateUtils import androidx.compose.foundation.background import androidx.compose.foundation.combinedClickable +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -15,6 +17,7 @@ import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Bookmark import androidx.compose.material3.Icon +import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -30,6 +33,7 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import eu.kanade.domain.updates.model.UpdatesWithRelations @@ -43,6 +47,28 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.ui.recent.updates.UpdatesItem import java.text.DateFormat +import java.util.Date + +@Composable +fun UpdatesLastUpdatedItem( + lastUpdated: Long, +) { + val time = remember(lastUpdated) { + DateUtils.getRelativeTimeSpanString(lastUpdated, Date().time, DateUtils.MINUTE_IN_MILLIS) + } + + Box( + modifier = Modifier + .padding(horizontal = horizontalPadding, vertical = 8.dp), + ) { + Text( + text = stringResource(R.string.updates_last_update_info, time), + style = LocalTextStyle.current.copy( + fontStyle = FontStyle.Italic, + ), + ) + } +} fun LazyListScope.updatesUiItems( uiModels: List, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 6c80f1f70..c548c458a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -68,6 +68,7 @@ import logcat.LogPriority import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File +import java.util.Date import java.util.concurrent.CopyOnWriteArrayList import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicInteger @@ -225,6 +226,11 @@ class LibraryUpdateService( updateJob?.cancel() ioScope?.cancel() + // If this is a chapter update; set the last update time to now + if (target == Target.CHAPTERS) { + preferences.libraryUpdateLastTimestamp().set(Date().time) + } + // Update favorite manga val categoryId = intent.getLongExtra(KEY_CATEGORY, -1L) addMangaToQueue(categoryId) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index a9e68ae05..7549b121f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -219,6 +219,7 @@ class PreferencesHelper(val context: Context) { fun removeExcludeCategories() = flowPrefs.getStringSet("remove_exclude_categories", emptySet()) fun libraryUpdateInterval() = flowPrefs.getInt("pref_library_update_interval_key", 24) + fun libraryUpdateLastTimestamp() = flowPrefs.getLong("library_update_last_timestamp", 0L) fun libraryUpdateDeviceRestriction() = flowPrefs.getStringSet("library_update_restriction", setOf(DEVICE_ONLY_ON_WIFI)) fun libraryUpdateMangaRestriction() = flowPrefs.getStringSet("library_update_manga_restriction", setOf(MANGA_HAS_UNREAD, MANGA_NON_COMPLETED, MANGA_NON_READ)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index 67eb48a46..16a9b41b1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -52,11 +52,11 @@ class UpdatesPresenter( ) : BasePresenter(), UpdatesState by state { val isDownloadOnly: Boolean by preferences.downloadedOnly().asState() - val isIncognitoMode: Boolean by preferences.incognitoMode().asState() - val relativeTime: Int by preferences.relativeTime().asState() + val lastUpdated by preferences.libraryUpdateLastTimestamp().asState() + val relativeTime: Int by preferences.relativeTime().asState() val dateFormat: DateFormat by mutableStateOf(preferences.dateFormat()) private val _events: Channel = Channel(Int.MAX_VALUE) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e3c3c1c12..6b455b988 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -742,6 +742,7 @@ Updating library An update is already running Unable to open last read chapter + Library last updated: %1$s Ch. %1$s - %2$s