Option to show downloads button only for downloaded chapters

or for either unread or downloaded chapters
This commit is contained in:
Jays2Kings 2021-04-08 17:47:46 -04:00
parent 837a46e0dd
commit 8ace4ef557
5 changed files with 30 additions and 10 deletions

View File

@ -67,6 +67,8 @@ class RecentMangaAdapter(val delegate: RecentsInterface) :
enum class ShowRecentsDLs {
None,
OnlyUnread,
OnlyDownloaded,
UnreadOrDownloaded,
All,
}
}

View File

@ -7,9 +7,9 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga
import eu.kanade.tachiyomi.databinding.RecentMangaItemBinding
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
import eu.kanade.tachiyomi.util.isLocal
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
class RecentMangaHolder(
@ -25,11 +25,12 @@ class RecentMangaHolder(
}
fun bind(item: RecentMangaItem, showDLs: RecentMangaAdapter.ShowRecentsDLs, showRemoveHistory: Boolean, showTitleFirst: Boolean) {
binding.downloadButton.downloadButton.isVisible = item.mch.manga.source != LocalSource.ID && when (showDLs) {
binding.downloadButton.downloadButton.isVisible = when (showDLs) {
RecentMangaAdapter.ShowRecentsDLs.None -> false
RecentMangaAdapter.ShowRecentsDLs.OnlyUnread -> !item.chapter.read
RecentMangaAdapter.ShowRecentsDLs.OnlyUnread, RecentMangaAdapter.ShowRecentsDLs.UnreadOrDownloaded -> !item.chapter.read
RecentMangaAdapter.ShowRecentsDLs.OnlyDownloaded -> true
RecentMangaAdapter.ShowRecentsDLs.All -> true
}
} && !item.mch.manga.isLocal()
binding.removeHistory.isVisible = item.mch.history.id != null && showRemoveHistory
binding.title.apply {
@ -83,10 +84,13 @@ class RecentMangaHolder(
if ((itemView.context as? Activity)?.isDestroyed != true) {
binding.coverThumbnail.loadLibraryManga(item.mch.manga)
}
if (!item.mch.manga.isLocal()) {
notifyStatus(
if (adapter.isSelected(flexibleAdapterPosition)) Download.CHECKED else item.status,
item.progress
item.progress,
item.chapter.read
)
}
resetFrontView()
}
@ -100,8 +104,18 @@ class RecentMangaHolder(
return item.mch.history.id != null
}
fun notifyStatus(status: Int, progress: Int) =
fun notifyStatus(status: Int, progress: Int, isRead: Boolean) {
binding.downloadButton.downloadButton.setDownloadStatus(status, progress)
val isChapterRead =
if (adapter.showDownloads == RecentMangaAdapter.ShowRecentsDLs.UnreadOrDownloaded) isRead else false
binding.downloadButton.downloadButton.isVisible =
when (adapter.showDownloads) {
RecentMangaAdapter.ShowRecentsDLs.UnreadOrDownloaded,
RecentMangaAdapter.ShowRecentsDLs.OnlyDownloaded ->
status !in Download.CHECKED..Download.NOT_DOWNLOADED && !isChapterRead
else -> binding.downloadButton.downloadButton.isVisible
}
}
override fun getFrontView(): View {
return binding.frontView

View File

@ -386,7 +386,7 @@ class RecentsController(bundle: Bundle? = null) :
binding.downloadBottomSheet.dlBottomSheet.onUpdateDownloadedPages(download)
val id = download.chapter.id ?: return
val holder = binding.recycler.findViewHolderForItemId(id) as? RecentMangaHolder ?: return
holder.notifyStatus(download.status, download.progress)
holder.notifyStatus(download.status, download.progress, download.chapter.read)
}
private fun refreshItem(chapterId: Long) {

View File

@ -65,6 +65,8 @@
<string-array name="show_recent_download">
<item>@string/never</item>
<item>@string/only_unread</item>
<item>@string/only_downloaded</item>
<item>@string/unread_or_downloaded</item>
<item>@string/always</item>
</string-array>

View File

@ -235,6 +235,8 @@
<string name="press_and_hold_to_also_reset">Press and hold can also reset chapter history</string>
<string name="show_download_button">Show download button</string>
<string name="only_unread">Only unread</string>
<string name="only_downloaded">Only downloaded</string>
<string name="unread_or_downloaded">Unread or downloaded</string>
<string name="show_reset_history_button">Show reset history button</string>
<string name="show_read_in_all">Show read in all</string>
<string name="show_title_first">Show title first</string>