mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Add library last updated timestamp to updates
This commit is contained in:
parent
4e085295ab
commit
da73eee943
6 changed files with 67 additions and 6 deletions
|
@ -57,6 +57,7 @@ import timber.log.Timber
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.File
|
||||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
|
@ -237,6 +238,8 @@ class LibraryUpdateService(
|
|||
}
|
||||
if (target == Target.CHAPTERS) {
|
||||
listener?.onUpdateManga(Manga.create(STARTING_UPDATE_SOURCE))
|
||||
// If this is a chapter update, set the last update time to now
|
||||
preferences.libraryUpdateLastTimestamp().set(Date().time)
|
||||
}
|
||||
job = GlobalScope.launch(handler) {
|
||||
when (target) {
|
||||
|
|
|
@ -261,6 +261,8 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 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))
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.recents
|
|||
import android.text.format.DateUtils
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
|
@ -11,6 +12,8 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
|||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.spToPx
|
||||
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
||||
import java.util.Date
|
||||
|
||||
class DateItem(val date: Date, val addedString: Boolean = false) : AbstractHeaderItem<DateItem.Holder>() {
|
||||
|
@ -20,7 +23,7 @@ class DateItem(val date: Date, val addedString: Boolean = false) : AbstractHeade
|
|||
}
|
||||
|
||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): Holder {
|
||||
return Holder(view, adapter)
|
||||
return Holder(view, adapter as RecentMangaAdapter)
|
||||
}
|
||||
|
||||
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, holder: Holder, position: Int, payloads: MutableList<Any?>?) {
|
||||
|
@ -43,17 +46,34 @@ class DateItem(val date: Date, val addedString: Boolean = false) : AbstractHeade
|
|||
return date.hashCode()
|
||||
}
|
||||
|
||||
class Holder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) : FlexibleViewHolder(view, adapter, true) {
|
||||
class Holder(view: View, val adapter: RecentMangaAdapter) : FlexibleViewHolder(view, adapter, true) {
|
||||
|
||||
private val now = Date().time
|
||||
|
||||
private val sectionText: TextView = view.findViewById(R.id.section_text)
|
||||
private val lastUpdatedText: TextView = view.findViewById(R.id.last_updated_text)
|
||||
|
||||
fun bind(item: DateItem) {
|
||||
sectionText.updatePadding(top = (if (bindingAdapterPosition == 0) 4 else 18).dpToPx)
|
||||
val dateString = DateUtils.getRelativeTimeSpanString(item.date.time, now, DateUtils.DAY_IN_MILLIS)
|
||||
sectionText.text =
|
||||
if (item.addedString) itemView.context.getString(R.string.fetched_, dateString) else dateString
|
||||
lastUpdatedText.isVisible = false
|
||||
if (bindingAdapterPosition == 0) {
|
||||
sectionText.updatePadding(
|
||||
top = if (adapter.lastUpdatedTime > 0L) {
|
||||
lastUpdatedText.isVisible = true
|
||||
lastUpdatedText.text = lastUpdatedText.context.timeSpanFromNow(
|
||||
R.string.updates_last_update_info,
|
||||
adapter.lastUpdatedTime,
|
||||
)
|
||||
18.spToPx + 8.dpToPx
|
||||
} else {
|
||||
4.dpToPx
|
||||
},
|
||||
)
|
||||
} else {
|
||||
sectionText.updatePadding(18.dpToPx)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(view: View?): Boolean {
|
||||
|
|
|
@ -31,6 +31,7 @@ class RecentMangaAdapter(val delegate: RecentsInterface) :
|
|||
var uniformCovers = preferences.uniformGrid().get()
|
||||
var showOutline = preferences.outlineOnCovers().get()
|
||||
var sortByFetched = preferences.sortFetchedTime().get()
|
||||
var lastUpdatedTime = preferences.libraryUpdateLastTimestamp().get()
|
||||
private var collapseGroupedUpdates = preferences.collapseGroupedUpdates().get()
|
||||
private var collapseGroupedHistory = preferences.collapseGroupedHistory().get()
|
||||
val collapseGrouped: Boolean
|
||||
|
@ -69,6 +70,12 @@ class RecentMangaAdapter(val delegate: RecentsInterface) :
|
|||
(recyclerView.findViewHolderForAdapterPosition(i) as? RecentMangaHolder)?.updateCards()
|
||||
}
|
||||
}
|
||||
preferences.libraryUpdateLastTimestamp().asFlow().onEach {
|
||||
lastUpdatedTime = it
|
||||
if (viewType.isUpdates) {
|
||||
notifyItemChanged(0)
|
||||
}
|
||||
}.launchIn(delegate.scope())
|
||||
}
|
||||
|
||||
fun getItemByChapterId(id: Long): RecentMangaItem? {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:background="?attr/colorSurface"
|
||||
android:gravity="center_vertical"
|
||||
app:cardCornerRadius="0dp">
|
||||
|
@ -11,9 +12,14 @@
|
|||
android:id="@+id/section_text"
|
||||
style="?textAppearanceTitleLarge"
|
||||
android:textSize="20sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:paddingTop="18dp"
|
||||
android:paddingBottom="4dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:text="Fetched yesterday"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:textColor="?attr/actionBarTintColor"
|
||||
|
@ -21,4 +27,26 @@
|
|||
android:layout_gravity="center_vertical"
|
||||
android:maxLines="1"/>
|
||||
|
||||
</FrameLayout>
|
||||
<TextView
|
||||
android:id="@+id/last_updated_text"
|
||||
style="?textAppearanceBodySmall"
|
||||
android:textStyle="italic"
|
||||
android:textAlignment="textEnd"
|
||||
tools:text="Library last updated: Yesterday"
|
||||
android:layout_width="0dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:textColor="?attr/actionBarTintColor"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="end|top"
|
||||
app:layout_constraintBottom_toBottomOf="@id/section_text"
|
||||
android:maxLines="1"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
@ -257,6 +257,7 @@
|
|||
<string name="updated_">Updated %1$s</string>
|
||||
<string name="added_">Added %1$s</string>
|
||||
<string name="fetched_">Fetched %1$s</string>
|
||||
<string name="updates_last_update_info">Library last updated: %s</string>
|
||||
<string name="view_history">View history</string>
|
||||
<string name="view_all_updates">View all updates</string>
|
||||
<string name="show_more_chapters">Show more chapters</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue