Add last update time to Updates Tab (closes #5466)

Co-authored-by: datreesezcup <datreesezcup@users.noreply.github.com>
This commit is contained in:
arkon 2022-08-29 14:57:25 -04:00
parent 8a3a7418d0
commit 43c195e14a
6 changed files with 41 additions and 2 deletions

View File

@ -163,6 +163,11 @@ fun UpdateScreen(
state = updatesListState, state = updatesListState,
contentPadding = contentPaddingWithNavBar, contentPadding = contentPaddingWithNavBar,
) { ) {
if (presenter.lastUpdated > 0L) {
item(key = "last_updated") {
UpdatesLastUpdatedItem(presenter.lastUpdated)
}
}
updatesUiItems( updatesUiItems(
uiModels = presenter.uiModels, uiModels = presenter.uiModels,
selectionMode = presenter.selectionMode, selectionMode = presenter.selectionMode,

View File

@ -1,7 +1,9 @@
package eu.kanade.presentation.updates package eu.kanade.presentation.updates
import android.text.format.DateUtils
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer 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.Icons
import androidx.compose.material.icons.filled.Bookmark import androidx.compose.material.icons.filled.Bookmark
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable 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.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import eu.kanade.domain.updates.model.UpdatesWithRelations 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.data.download.model.Download
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesItem import eu.kanade.tachiyomi.ui.recent.updates.UpdatesItem
import java.text.DateFormat 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( fun LazyListScope.updatesUiItems(
uiModels: List<UpdatesUiModel>, uiModels: List<UpdatesUiModel>,

View File

@ -68,6 +68,7 @@ import logcat.LogPriority
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.File import java.io.File
import java.util.Date
import java.util.concurrent.CopyOnWriteArrayList import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
@ -225,6 +226,11 @@ class LibraryUpdateService(
updateJob?.cancel() updateJob?.cancel()
ioScope?.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 // Update favorite manga
val categoryId = intent.getLongExtra(KEY_CATEGORY, -1L) val categoryId = intent.getLongExtra(KEY_CATEGORY, -1L)
addMangaToQueue(categoryId) addMangaToQueue(categoryId)

View File

@ -219,6 +219,7 @@ class PreferencesHelper(val context: Context) {
fun removeExcludeCategories() = flowPrefs.getStringSet("remove_exclude_categories", emptySet()) fun removeExcludeCategories() = flowPrefs.getStringSet("remove_exclude_categories", emptySet())
fun libraryUpdateInterval() = flowPrefs.getInt("pref_library_update_interval_key", 24) 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 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)) fun libraryUpdateMangaRestriction() = flowPrefs.getStringSet("library_update_manga_restriction", setOf(MANGA_HAS_UNREAD, MANGA_NON_COMPLETED, MANGA_NON_READ))

View File

@ -52,11 +52,11 @@ class UpdatesPresenter(
) : BasePresenter<UpdatesController>(), UpdatesState by state { ) : BasePresenter<UpdatesController>(), UpdatesState by state {
val isDownloadOnly: Boolean by preferences.downloadedOnly().asState() val isDownloadOnly: Boolean by preferences.downloadedOnly().asState()
val isIncognitoMode: Boolean by preferences.incognitoMode().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()) val dateFormat: DateFormat by mutableStateOf(preferences.dateFormat())
private val _events: Channel<Event> = Channel(Int.MAX_VALUE) private val _events: Channel<Event> = Channel(Int.MAX_VALUE)

View File

@ -742,6 +742,7 @@
<string name="updating_library">Updating library</string> <string name="updating_library">Updating library</string>
<string name="update_already_running">An update is already running</string> <string name="update_already_running">An update is already running</string>
<string name="cant_open_last_read_chapter">Unable to open last read chapter</string> <string name="cant_open_last_read_chapter">Unable to open last read chapter</string>
<string name="updates_last_update_info">Library last updated: %1$s</string>
<!-- History fragment --> <!-- History fragment -->
<string name="recent_manga_time">Ch. %1$s - %2$s</string> <string name="recent_manga_time">Ch. %1$s - %2$s</string>