From b53d571a1c6cf441ddd89e05179f7049f0789f95 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 19 Apr 2020 18:22:12 -0400 Subject: [PATCH] Add option to hide start reading button --- .../data/preference/PreferencesHelper.kt | 2 ++ .../ui/library/DisplayBottomSheet.kt | 3 ++ .../tachiyomi/ui/library/LibraryGridHolder.kt | 3 +- .../tachiyomi/ui/library/LibraryHolder.kt | 6 ++++ .../tachiyomi/ui/library/LibraryItem.kt | 32 +++++++++++++------ .../tachiyomi/ui/library/LibraryListHolder.kt | 5 ++- .../tachiyomi/ui/library/LibraryPresenter.kt | 19 ++--------- .../main/res/layout/display_bottom_sheet.xml | 8 +++++ app/src/main/res/values/strings.xml | 1 + 9 files changed, 48 insertions(+), 31 deletions(-) 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 0823a6b165..04ff9ec2ff 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 @@ -253,6 +253,8 @@ class PreferencesHelper(val context: Context) { fun unreadBadgeType() = rxPrefs.getInteger("unread_badge_type", 2) + fun hideStartReadingButton() = rxPrefs.getBoolean("hide_reading_button", false) + fun hideFiltersAtStart() = rxPrefs.getBoolean("hide_filters_at_start", false) fun alwaysShowChapterTransition() = rxPrefs.getBoolean(Keys.alwaysShowChapterTransition, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt index 18083c1727..b8f54d0c3f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt @@ -98,6 +98,9 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee unread_badge_group.bindToPreference(preferences.unreadBadgeType()) { controller.presenter.requestUnreadBadgesUpdate() } + hide_reading.bindToPreference(preferences.hideStartReadingButton()) { + controller.reattachAdapter() + } hide_filters.bindToPreference(preferences.hideFiltersAtStart()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 6482139f33..0a4969a23e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -59,8 +59,7 @@ class LibraryGridHolder( compact_title.text = title.text setUnreadBadge(badge_view, item) - play_layout.visibility = if (item.manga.unread > 0 && item.unreadType > 0) - View.VISIBLE else View.GONE + setReadingButton(item) // Update the cover. if (item.manga.thumbnail_url == null) GlideApp.with(view.context).clear(cover_thumbnail) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt index 22011109a5..1b8b2cc245 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.library import android.view.View import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder +import kotlinx.android.synthetic.main.manga_grid_item.* /** * Generic class used to hold the displayed data of a manga in the library. @@ -40,6 +41,11 @@ abstract class LibraryHolder( item.chapterCount > -1) } + fun setReadingButton(item: LibraryItem) { + play_layout.visibility = if (item.manga.unread > 0 && item.unreadType > 0 && !item.hideReadingButton) + View.VISIBLE else View.GONE + } + /** * Called when an item is released. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index ee54c8b3af..841a4b7ff4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -9,27 +9,27 @@ import android.widget.ImageView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView -import com.f2prateek.rx.preferences.Preference import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractSectionableItem import eu.davidea.flexibleadapter.items.IFilterable import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.manga_grid_item.view.* +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy class LibraryItem( val manga: LibraryManga, - private val libraryLayout: Preference, - private val fixedSize: Preference, - private val showFastScroll: Preference, - header: LibraryHeaderItem + header: LibraryHeaderItem, + private val preferences: PreferencesHelper = Injekt.get() ) : AbstractSectionableItem(header), IFilterable { @@ -37,8 +37,20 @@ class LibraryItem( var unreadType = 2 var chapterCount = -1 + private val showFastScroll: Boolean + get() = preferences.alwaysShowSeeker().getOrDefault() + + private val uniformSize: Boolean + get() = preferences.uniformGrid().getOrDefault() + + private val libraryLayout: Int + get() = preferences.libraryLayout().getOrDefault() + + val hideReadingButton: Boolean + get() = preferences.hideStartReadingButton().getOrDefault() + override fun getLayoutRes(): Int { - return if (libraryLayout.getOrDefault() == 0 || manga.isBlank()) + return if (libraryLayout == 0 || manga.isBlank()) R.layout.manga_list_item else R.layout.manga_grid_item @@ -47,10 +59,10 @@ class LibraryItem( override fun createViewHolder(view: View, adapter: FlexibleAdapter>): LibraryHolder { val parent = adapter.recyclerView return if (parent is AutofitRecyclerView) { - val libraryLayout = libraryLayout.getOrDefault() - val isFixedSize = fixedSize.getOrDefault() + val libraryLayout = libraryLayout + val isFixedSize = uniformSize if (libraryLayout == 0 || manga.isBlank()) { - LibraryListHolder(view, adapter as LibraryCategoryAdapter, showFastScroll.getOrDefault()) + LibraryListHolder(view, adapter as LibraryCategoryAdapter, showFastScroll) } else { view.apply { val coverHeight = (parent.itemWidth / 3f * 4f).toInt() @@ -95,7 +107,7 @@ class LibraryItem( ) } } else { - LibraryListHolder(view, adapter as LibraryCategoryAdapter, showFastScroll.getOrDefault()) + LibraryListHolder(view, adapter as LibraryCategoryAdapter, showFastScroll) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 2ddcebf2e0..fda3c3ddee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -33,6 +33,7 @@ class LibraryListHolder( ) : LibraryHolder(view, adapter) { init { + play_layout.setOnClickListener { playButtonClicked() } badge_view?.updateLayoutParams { marginEnd = (if (padEnd) 22 else 12).dpToPx } @@ -74,9 +75,7 @@ class LibraryListHolder( subtitle.visibility = if (!item.manga.author.isNullOrBlank()) View.VISIBLE else View.GONE - play_layout.visibility = if (item.manga.unread > 0 && item.unreadType > 0) - View.VISIBLE else View.GONE - play_layout.setOnClickListener { playButtonClicked() } + setReadingButton(item) // Update the cover. if (item.manga.thumbnail_url == null) Glide.with(view.context).clear(cover_thumbnail) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 84a56c9103..4f6b0ebb8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -400,7 +400,6 @@ class LibraryPresenter( */ private fun getLibraryFromDB(): List { val categories = db.getCategories().executeAsBlocking().toMutableList() - val libraryLayout = preferences.libraryLayout() val showCategories = !preferences.hideCategories().getOrDefault() var libraryManga = db.getLibraryMangas().executeAsBlocking() val seekPref = preferences.alwaysShowSeeker() @@ -421,7 +420,7 @@ class LibraryPresenter( val headerItem = (if (!showCategories) catItemAll else headerItems[it.category]) ?: return@mapNotNull null categorySet.add(it.category) - LibraryItem(it, libraryLayout, preferences.uniformGrid(), seekPref, headerItem) + LibraryItem(it, headerItem) }.toMutableList() val categoriesHidden = preferences.collapsedCategories().getOrDefault().mapNotNull { @@ -434,13 +433,7 @@ class LibraryPresenter( if (catId > 0 && !categorySet.contains(catId)) { val headerItem = headerItems[catId] if (headerItem != null) items.add( - LibraryItem( - LibraryManga.createBlank(catId), - libraryLayout, - preferences.uniformGrid(), - preferences.alwaysShowSeeker(), - headerItem - ) + LibraryItem(LibraryManga.createBlank(catId), headerItem) ) } else if (catId in categoriesHidden) { val mangaToRemove = items.filter { it.manga.category == catId } @@ -450,13 +443,7 @@ class LibraryPresenter( items.removeAll(mangaToRemove) val headerItem = headerItems[catId] if (headerItem != null) items.add( - LibraryItem( - LibraryManga.createHide(catId, mergedTitle), - libraryLayout, - preferences.uniformGrid(), - preferences.alwaysShowSeeker(), - headerItem - ) + LibraryItem(LibraryManga.createHide(catId, mergedTitle), headerItem) ) } } diff --git a/app/src/main/res/layout/display_bottom_sheet.xml b/app/src/main/res/layout/display_bottom_sheet.xml index 45e5c002f6..46272cbba8 100644 --- a/app/src/main/res/layout/display_bottom_sheet.xml +++ b/app/src/main/res/layout/display_bottom_sheet.xml @@ -135,6 +135,14 @@ android:text="@string/show_count" /> + + Compact Grid Start with filters hidden Download badges + Hide start reading button Always show library fast scroll Unread badges Uniform covers