From 7ad228d19f5d93a6c25d1228bd2ae0e425a4de4a Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sun, 11 Jul 2021 17:49:02 -0400 Subject: [PATCH] Set default for chapter filtering + hide title This flag is different from the one that saves sorting so theres 2 flags for local sort and local filter Recents now also now shows only chapter number if titles are hidden --- .../tachiyomi/data/database/models/Manga.kt | 37 ++++++++ .../data/preference/PreferenceKeys.kt | 2 +- .../data/preference/PreferencesHelper.kt | 19 +--- .../ui/manga/MangaDetailsPresenter.kt | 95 +++++++++++++++---- .../ui/manga/chapter/ChapterFilterLayout.kt | 34 ++++++- .../ui/manga/chapter/ChapterHolder.kt | 11 +-- .../manga/chapter/ChaptersSortBottomSheet.kt | 51 +++++++--- .../ui/reader/chapter/ReaderChapterItem.kt | 15 +-- .../ui/recents/RecentMangaAdapter.kt | 2 +- .../tachiyomi/ui/recents/RecentMangaHolder.kt | 8 +- .../tachiyomi/util/chapter/ChapterFilter.kt | 12 +-- .../main/res/layout/chapter_filter_layout.xml | 49 ++++++++-- .../res/layout/chapter_sort_bottom_sheet.xml | 12 +-- 13 files changed, 256 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index 09660caf87..98621072c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.database.models import android.content.Context import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.ui.reader.settings.OrientationType @@ -40,6 +41,9 @@ interface Manga : SManga { fun setSortToGlobal() = setChapterFlags(CHAPTER_SORT_FILTER_GLOBAL, CHAPTER_SORT_LOCAL_MASK) + fun setFilterToGlobal() = setChapterFlags(CHAPTER_SORT_FILTER_GLOBAL, CHAPTER_FILTER_LOCAL_MASK) + fun setFilterToLocal() = setChapterFlags(CHAPTER_FILTER_LOCAL, CHAPTER_FILTER_LOCAL_MASK) + private fun setChapterFlags(flag: Int, mask: Int) { chapter_flags = chapter_flags and mask.inv() or (flag and mask) } @@ -49,9 +53,12 @@ interface Manga : SManga { } fun sortDescending(): Boolean = chapter_flags and CHAPTER_SORT_MASK == CHAPTER_SORT_DESC + fun hideChapterTitles(): Boolean = displayMode == CHAPTER_DISPLAY_NUMBER fun usesLocalSort(): Boolean = chapter_flags and CHAPTER_SORT_LOCAL_MASK == CHAPTER_SORT_LOCAL + fun usesLocalFilter(): Boolean = chapter_flags and CHAPTER_FILTER_LOCAL_MASK == CHAPTER_FILTER_LOCAL + fun sortDescending(defaultDesc: Boolean): Boolean { return if (usesLocalSort()) sortDescending() else defaultDesc } @@ -60,6 +67,34 @@ interface Manga : SManga { return if (usesLocalSort()) sorting else defaultOrder } + fun readFilter(preferences: PreferencesHelper): Int = + readFilter(preferences.filterChapterByRead().get()) + + fun readFilter(defaultFilter: Int): Int { + return if (usesLocalFilter()) readFilter else defaultFilter + } + + fun downloadedFilter(preferences: PreferencesHelper): Int = + downloadedFilter(preferences.filterChapterByDownloaded().get()) + + fun downloadedFilter(defaultFilter: Int): Int { + return if (usesLocalFilter()) downloadedFilter else defaultFilter + } + + fun bookmarkedFilter(preferences: PreferencesHelper): Int = + bookmarkedFilter(preferences.filterChapterByBookmarked().get()) + + fun bookmarkedFilter(defaultFilter: Int): Int { + return if (usesLocalFilter()) bookmarkedFilter else defaultFilter + } + + fun hideChapterTitle(preferences: PreferencesHelper): Boolean = + hideChapterTitle(preferences.hideChapterTitlesByDefault().get()) + + fun hideChapterTitle(default: Boolean): Boolean { + return if (usesLocalFilter()) hideChapterTitles() else default + } + fun showChapterTitle(defaultShow: Boolean): Boolean = chapter_flags and CHAPTER_DISPLAY_MASK == CHAPTER_DISPLAY_NUMBER fun seriesType(context: Context, sourceManager: SourceManager? = null): String { @@ -242,6 +277,8 @@ interface Manga : SManga { const val CHAPTER_SORT_FILTER_GLOBAL = 0x00000000 const val CHAPTER_SORT_LOCAL = 0x00001000 const val CHAPTER_SORT_LOCAL_MASK = 0x00001000 + const val CHAPTER_FILTER_LOCAL = 0x00002000 + const val CHAPTER_FILTER_LOCAL_MASK = 0x00002000 const val CHAPTER_SHOW_UNREAD = 0x00000002 const val CHAPTER_SHOW_READ = 0x00000004 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index a056bfad3a..b9e03faf36 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -239,7 +239,7 @@ object PreferenceKeys { const val defaultChapterSortByAscendingOrDescending = "default_chapter_sort_by_ascending_or_descending" - const val defaultChapterDisplayByNameOrNumber = "default_chapter_display_by_name_or_number" + const val hideChapterTitles = "hide_chapter_titles" fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId" 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 eb8d051bb0..086c2008ef 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 @@ -424,28 +424,17 @@ class PreferencesHelper(val context: Context) { fun incognitoMode() = flowPrefs.getBoolean(Keys.incognitoMode, false) - fun filterChapterByRead() = prefs.getInt(Keys.defaultChapterFilterByRead, Manga.SHOW_ALL) + fun filterChapterByRead() = flowPrefs.getInt(Keys.defaultChapterFilterByRead, Manga.SHOW_ALL) - fun filterChapterByDownloaded() = prefs.getInt(Keys.defaultChapterFilterByDownloaded, Manga.SHOW_ALL) + fun filterChapterByDownloaded() = flowPrefs.getInt(Keys.defaultChapterFilterByDownloaded, Manga.SHOW_ALL) - fun filterChapterByBookmarked() = prefs.getInt(Keys.defaultChapterFilterByBookmarked, Manga.SHOW_ALL) + fun filterChapterByBookmarked() = flowPrefs.getInt(Keys.defaultChapterFilterByBookmarked, Manga.SHOW_ALL) fun sortChapterOrder() = flowPrefs.getInt(Keys.defaultChapterSortBySourceOrNumber, Manga.CHAPTER_SORTING_SOURCE) - fun displayChapterByNameOrNumber() = prefs.getInt(Keys.defaultChapterDisplayByNameOrNumber, Manga.CHAPTER_DISPLAY_NAME) + fun hideChapterTitlesByDefault() = flowPrefs.getBoolean(Keys.hideChapterTitles, false) fun chaptersDescAsDefault() = rxPrefs.getBoolean("chapters_desc_as_default", true) fun sortChapterByAscendingOrDescending() = prefs.getInt(Keys.defaultChapterSortByAscendingOrDescending, Manga.CHAPTER_SORT_DESC) - - fun setChapterSettingsDefault(manga: Manga) { - prefs.edit { - putInt(Keys.defaultChapterFilterByRead, manga.readFilter) - putInt(Keys.defaultChapterFilterByDownloaded, manga.downloadedFilter) - putInt(Keys.defaultChapterFilterByBookmarked, manga.bookmarkedFilter) - putInt(Keys.defaultChapterSortBySourceOrNumber, manga.sorting) - putInt(Keys.defaultChapterDisplayByNameOrNumber, manga.displayMode) - putInt(Keys.defaultChapterSortByAscendingOrDescending, if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC) - } - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index 390a9ee308..e62b708ba5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -211,16 +211,6 @@ class MangaDetailsPresenter( return model } - /** - * Sets the active display mode. - * @param hide set title to hidden - */ - fun hideTitle(hide: Boolean) { - manga.displayMode = if (hide) Manga.CHAPTER_DISPLAY_NUMBER else Manga.CHAPTER_DISPLAY_NAME - db.updateChapterFlags(manga).executeAsBlocking() - controller.refreshAdapter() - } - /** * Whether the sorting method is descending or ascending. */ @@ -507,6 +497,13 @@ class MangaDetailsPresenter( asyncUpdateMangaAndChapters() } + fun setGlobalChapterSort(sort: Int, descend: Boolean) { + preferences.sortChapterOrder().set(sort) + preferences.chaptersDescAsDefault().set(descend) + manga.setSortToGlobal() + asyncUpdateMangaAndChapters() + } + private fun globalSort(): Boolean = preferences.chaptersDescAsDefault().getOrDefault() private fun globalSorting(): Int = preferences.sortChapterOrder().get() @@ -515,11 +512,13 @@ class MangaDetailsPresenter( return (manga.sortDescending() == globalSort() && manga.sorting == globalSorting()) || !manga.usesLocalSort() } - fun setGlobalChapterSort(sort: Int, descend: Boolean) { - preferences.sortChapterOrder().set(sort) - preferences.chaptersDescAsDefault().set(descend) - manga.setSortToGlobal() - asyncUpdateMangaAndChapters() + fun mangaFilterMatchesDefault(): Boolean { + return ( + manga.readFilter == preferences.filterChapterByRead().get() && + manga.downloadedFilter == preferences.filterChapterByDownloaded().get() && + manga.bookmarkedFilter == preferences.filterChapterByBookmarked().get() && + manga.hideChapterTitles() == preferences.hideChapterTitlesByDefault().get() + ) || !manga.usesLocalFilter() } fun resetSortingToDefault() { @@ -550,6 +549,60 @@ class MangaDetailsPresenter( TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED else -> Manga.SHOW_ALL } + manga.setFilterToLocal() + if (mangaFilterMatchesDefault()) { + manga.setFilterToGlobal() + } + asyncUpdateMangaAndChapters() + } + + /** + * Sets the active display mode. + * @param hide set title to hidden + */ + fun hideTitle(hide: Boolean) { + manga.displayMode = if (hide) Manga.CHAPTER_DISPLAY_NUMBER else Manga.CHAPTER_DISPLAY_NAME + db.updateChapterFlags(manga).executeAsBlocking() + manga.setFilterToLocal() + if (mangaFilterMatchesDefault()) { + manga.setFilterToGlobal() + } + controller.refreshAdapter() + } + + fun resetFilterToDefault() { + manga.setFilterToGlobal() + asyncUpdateMangaAndChapters() + } + + fun setGlobalChapterFilters( + unread: TriStateCheckBox.State, + downloaded: TriStateCheckBox.State, + bookmarked: TriStateCheckBox.State + ) { + preferences.filterChapterByRead().set( + when (unread) { + TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_UNREAD + TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_READ + else -> Manga.SHOW_ALL + } + ) + preferences.filterChapterByDownloaded().set( + when (downloaded) { + TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_DOWNLOADED + TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_DOWNLOADED + else -> Manga.SHOW_ALL + } + ) + preferences.filterChapterByBookmarked().set( + when (bookmarked) { + TriStateCheckBox.State.CHECKED -> Manga.CHAPTER_SHOW_BOOKMARKED + TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED + else -> Manga.SHOW_ALL + } + ) + preferences.hideChapterTitlesByDefault().set(manga.hideChapterTitles()) + manga.setFilterToGlobal() asyncUpdateMangaAndChapters() } @@ -563,12 +616,12 @@ class MangaDetailsPresenter( fun currentFilters(): String { val filtersId = mutableListOf() - filtersId.add(if (manga.readFilter == Manga.CHAPTER_SHOW_READ) R.string.read else null) - filtersId.add(if (manga.readFilter == Manga.CHAPTER_SHOW_UNREAD) R.string.unread else null) - filtersId.add(if (manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED) R.string.downloaded else null) - filtersId.add(if (manga.downloadedFilter == Manga.CHAPTER_SHOW_NOT_DOWNLOADED) R.string.not_downloaded else null) - filtersId.add(if (manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED) R.string.bookmarked else null) - filtersId.add(if (manga.bookmarkedFilter == Manga.CHAPTER_SHOW_NOT_BOOKMARKED) R.string.not_bookmarked else null) + filtersId.add(if (manga.readFilter(preferences) == Manga.CHAPTER_SHOW_READ) R.string.read else null) + filtersId.add(if (manga.readFilter(preferences) == Manga.CHAPTER_SHOW_UNREAD) R.string.unread else null) + filtersId.add(if (manga.downloadedFilter(preferences) == Manga.CHAPTER_SHOW_DOWNLOADED) R.string.downloaded else null) + filtersId.add(if (manga.downloadedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_DOWNLOADED) R.string.not_downloaded else null) + filtersId.add(if (manga.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_BOOKMARKED) R.string.bookmarked else null) + filtersId.add(if (manga.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_BOOKMARKED) R.string.not_bookmarked else null) return filtersId.filterNotNull().joinToString(", ") { preferences.context.getString(it) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterFilterLayout.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterFilterLayout.kt index 805bd40907..5a6fb1fdfb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterFilterLayout.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterFilterLayout.kt @@ -4,6 +4,7 @@ import android.content.Context import android.util.AttributeSet import android.widget.LinearLayout import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.ChapterFilterLayoutBinding import eu.kanade.tachiyomi.widget.TriStateCheckBox @@ -11,6 +12,7 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att LinearLayout(context, attrs) { lateinit var binding: ChapterFilterLayoutBinding + private var mOnCheckedChangeListener: OnCheckedChangeListener? = null override fun onFinishInflate() { super.onFinishInflate() @@ -41,20 +43,21 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att ) { binding.showAll.animateDrawableToState(TriStateCheckBox.State.CHECKED) } + mOnCheckedChangeListener?.onCheckedChanged(this) } - fun setCheckboxes(manga: Manga) { - binding.showUnread.state = when (manga.readFilter) { + fun setCheckboxes(manga: Manga, preferences: PreferencesHelper) { + binding.showUnread.state = when (manga.readFilter(preferences)) { Manga.CHAPTER_SHOW_UNREAD -> TriStateCheckBox.State.CHECKED Manga.CHAPTER_SHOW_READ -> TriStateCheckBox.State.INVERSED else -> TriStateCheckBox.State.UNCHECKED } - binding.showDownload.state = when (manga.downloadedFilter) { + binding.showDownload.state = when (manga.downloadedFilter(preferences)) { Manga.CHAPTER_SHOW_DOWNLOADED -> TriStateCheckBox.State.CHECKED Manga.CHAPTER_SHOW_NOT_DOWNLOADED -> TriStateCheckBox.State.INVERSED else -> TriStateCheckBox.State.UNCHECKED } - binding.showBookmark.state = when (manga.bookmarkedFilter) { + binding.showBookmark.state = when (manga.bookmarkedFilter(preferences)) { Manga.CHAPTER_SHOW_BOOKMARKED -> TriStateCheckBox.State.CHECKED Manga.CHAPTER_SHOW_NOT_BOOKMARKED -> TriStateCheckBox.State.INVERSED else -> TriStateCheckBox.State.UNCHECKED @@ -64,4 +67,27 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att binding.showDownload.isUnchecked && binding.showBookmark.isUnchecked } + + /** + * Register a callback to be invoked when the checked state of this button + * changes. + * + * @param listener the callback to call on checked state change + */ + fun setOnCheckedChangeListener(listener: OnCheckedChangeListener?) { + mOnCheckedChangeListener = listener + } + + /** + * Interface definition for a callback to be invoked when one of the check states in this view + * changes + */ + fun interface OnCheckedChangeListener { + /** + * Called when the checked state of a compound button has changed. + * + * @param filterLayout The view containing the changed state + */ + fun onCheckedChanged(filterLayout: ChapterFilterLayout) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt index a45fc8a689..659b8ef9bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt @@ -33,13 +33,10 @@ class ChapterHolder( fun bind(item: ChapterItem, manga: Manga) { val chapter = item.chapter val isLocked = item.isLocked - binding.chapterTitle.text = when (manga.displayMode) { - Manga.CHAPTER_DISPLAY_NUMBER -> { - val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) - itemView.context.getString(R.string.chapter_, number) - } - else -> chapter.name - } + binding.chapterTitle.text = if (manga.hideChapterTitle(adapter.preferences)) { + val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) + itemView.context.getString(R.string.chapter_, number) + } else chapter.name localSource = manga.source == LocalSource.ID binding.downloadButton.downloadButton.isVisible = !localSource && !isLocked diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt index acb6ec918c..5ee48fb7e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt @@ -24,7 +24,7 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : override fun createBinding(inflater: LayoutInflater) = ChapterSortBottomSheetBinding.inflate(inflater) init { val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom - sheetBehavior.peekHeight = 415.dpToPx + height + sheetBehavior.peekHeight = 460.dpToPx + height sheetBehavior.addBottomSheetCallback( object : BottomSheetBehavior.BottomSheetCallback() { @@ -64,18 +64,12 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : // making the view gone somehow breaks the layout so lets make it invisible binding.pill.isInvisible = isScrollable } - - setOnDismissListener { - presenter.setFilters( - binding.chapterFilterLayout.showUnread.state, - binding.chapterFilterLayout.showDownload.state, - binding.chapterFilterLayout.showBookmark.state - ) - } } private fun initGeneralPreferences() { - binding.chapterFilterLayout.root.setCheckboxes(presenter.manga) + binding.chapterFilterLayout.root.setCheckboxes(presenter.manga, presenter.preferences) + checkIfFilterMatchesDefault(binding.chapterFilterLayout.root) + binding.chapterFilterLayout.root.setOnCheckedChangeListener(::setFilters) binding.byChapterNumber.state = SortTextView.State.NONE binding.byUploadDate.state = SortTextView.State.NONE @@ -98,7 +92,7 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : binding.byUploadDate.setOnSortChangeListener(::sortChanged) binding.bySource.setOnSortChangeListener(::sortChanged) - binding.hideTitles.isChecked = presenter.manga.displayMode != Manga.CHAPTER_DISPLAY_NAME + binding.hideTitles.isChecked = presenter.manga.hideChapterTitle(presenter.preferences) binding.setAsDefaultSort.setOnClickListener { presenter.setGlobalChapterSort( @@ -133,7 +127,42 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : binding.hideTitles.setOnCheckedChangeListener { _, isChecked -> presenter.hideTitle(isChecked) + checkIfFilterMatchesDefault(binding.chapterFilterLayout.root) } + + binding.chapterFilterLayout.setAsDefaultFilter.setOnClickListener { + presenter.setGlobalChapterFilters( + binding.chapterFilterLayout.showUnread.state, + binding.chapterFilterLayout.showDownload.state, + binding.chapterFilterLayout.showBookmark.state + ) + binding.chapterFilterLayout.setAsDefaultFilter.isInvisible = true + binding.chapterFilterLayout.resetAsDefaultFilter.isInvisible = true + } + + binding.chapterFilterLayout.resetAsDefaultFilter.setOnClickListener { + presenter.resetFilterToDefault() + + binding.chapterFilterLayout.root.setCheckboxes(presenter.manga, presenter.preferences) + binding.hideTitles.isChecked = presenter.manga.hideChapterTitle(presenter.preferences) + binding.chapterFilterLayout.setAsDefaultFilter.isInvisible = true + binding.chapterFilterLayout.resetAsDefaultFilter.isInvisible = true + } + } + + private fun setFilters(filterLayout: ChapterFilterLayout) { + presenter.setFilters( + binding.chapterFilterLayout.showUnread.state, + binding.chapterFilterLayout.showDownload.state, + binding.chapterFilterLayout.showBookmark.state + ) + checkIfFilterMatchesDefault(filterLayout) + } + + private fun checkIfFilterMatchesDefault(filterLayout: ChapterFilterLayout) { + val matches = presenter.mangaFilterMatchesDefault() + filterLayout.binding.setAsDefaultFilter.isInvisible = matches + filterLayout.binding.resetAsDefaultFilter.isInvisible = matches } private fun checkIfSortMatchesDefault() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt index cea8d22e34..4360fc849e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt @@ -8,8 +8,10 @@ import com.mikepenz.fastadapter.items.AbstractItem import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.ReaderChapterItemBinding import eu.kanade.tachiyomi.util.chapter.ChapterUtil +import uy.kohesive.injekt.injectLazy import java.text.DecimalFormat import java.text.DecimalFormatSymbols @@ -20,6 +22,8 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols().apply { decimalSeparator = '.' }) + val preferences: PreferencesHelper by injectLazy() + /** defines the type defining this item. must be unique. preferably an id */ override val type: Int = R.id.reader_chapter_layout @@ -40,13 +44,10 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter) - binding.chapterTitle.text = when (manga.displayMode) { - Manga.CHAPTER_DISPLAY_NUMBER -> { - val number = item.decimalFormat.format(item.chapter_number.toDouble()) - itemView.context.getString(R.string.chapter_, number) - } - else -> item.name - } + binding.chapterTitle.text = if (manga.hideChapterTitle(item.preferences)) { + val number = item.decimalFormat.format(item.chapter_number.toDouble()) + itemView.context.getString(R.string.chapter_, number) + } else item.name val statuses = mutableListOf() ChapterUtil.relativeDate(item)?.let { statuses.add(it) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaAdapter.kt index c87921c9ba..6ffd72098f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaAdapter.kt @@ -16,7 +16,7 @@ import java.text.DecimalFormatSymbols class RecentMangaAdapter(val delegate: RecentsInterface) : BaseChapterAdapter>(delegate) { - private val preferences: PreferencesHelper by injectLazy() + val preferences: PreferencesHelper by injectLazy() var showDownloads = preferences.showRecentsDownloads().get() var showRemoveHistory = preferences.showRecentsRemHistory().get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt index be90ccc149..b2293d4094 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt @@ -82,9 +82,13 @@ class RecentMangaHolder( } } binding.removeHistory.isVisible = item.mch.history.id != null && showRemoveHistory + val chapterName = if (item.mch.manga.hideChapterTitle(adapter.preferences)) { + val number = adapter.decimalFormat.format(item.chapter.chapter_number.toDouble()) + itemView.context.getString(R.string.chapter_, number) + } else item.chapter.name binding.title.apply { text = if (!showTitleFirst) { - item.chapter.name + chapterName } else { item.mch.manga.title } @@ -94,7 +98,7 @@ class RecentMangaHolder( text = if (!showTitleFirst) { item.mch.manga.title } else { - item.chapter.name + chapterName } setTextColor(ChapterUtil.readColor(context, item)) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilter.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilter.kt index 0bbf77039e..73826642e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilter.kt @@ -11,12 +11,12 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl // filters chapters based on the manga values fun filterChapters(chapters: List, manga: Manga): List { - val readEnabled = manga.readFilter == Manga.CHAPTER_SHOW_READ - val unreadEnabled = manga.readFilter == Manga.CHAPTER_SHOW_UNREAD - val downloadEnabled = manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED - val notDownloadEnabled = manga.downloadedFilter == Manga.CHAPTER_SHOW_NOT_DOWNLOADED - val bookmarkEnabled = manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED - val notBookmarkEnabled = manga.bookmarkedFilter == Manga.CHAPTER_SHOW_NOT_BOOKMARKED + val readEnabled = manga.readFilter(preferences) == Manga.CHAPTER_SHOW_READ + val unreadEnabled = manga.readFilter(preferences) == Manga.CHAPTER_SHOW_UNREAD + val downloadEnabled = manga.downloadedFilter(preferences) == Manga.CHAPTER_SHOW_DOWNLOADED + val notDownloadEnabled = manga.downloadedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_DOWNLOADED + val bookmarkEnabled = manga.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_BOOKMARKED + val notBookmarkEnabled = manga.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_BOOKMARKED // if none of the filters are enabled skip the filtering of them return if (readEnabled || unreadEnabled || downloadEnabled || notDownloadEnabled || bookmarkEnabled || notBookmarkEnabled) { diff --git a/app/src/main/res/layout/chapter_filter_layout.xml b/app/src/main/res/layout/chapter_filter_layout.xml index 18c05a7edb..18e74b8e68 100644 --- a/app/src/main/res/layout/chapter_filter_layout.xml +++ b/app/src/main/res/layout/chapter_filter_layout.xml @@ -5,14 +5,49 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical"> - + android:layout_height="wrap_content"> + + + + + + @@ -86,18 +88,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> - -