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
This commit is contained in:
Jays2Kings 2021-07-11 17:49:02 -04:00
parent 469db068e3
commit 7ad228d19f
13 changed files with 256 additions and 91 deletions

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.database.models
import android.content.Context import android.content.Context
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.reader.settings.OrientationType 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 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) { private fun setChapterFlags(flag: Int, mask: Int) {
chapter_flags = chapter_flags and mask.inv() or (flag and mask) 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 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 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 { fun sortDescending(defaultDesc: Boolean): Boolean {
return if (usesLocalSort()) sortDescending() else defaultDesc return if (usesLocalSort()) sortDescending() else defaultDesc
} }
@ -60,6 +67,34 @@ interface Manga : SManga {
return if (usesLocalSort()) sorting else defaultOrder 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 showChapterTitle(defaultShow: Boolean): Boolean = chapter_flags and CHAPTER_DISPLAY_MASK == CHAPTER_DISPLAY_NUMBER
fun seriesType(context: Context, sourceManager: SourceManager? = null): String { 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_FILTER_GLOBAL = 0x00000000
const val CHAPTER_SORT_LOCAL = 0x00001000 const val CHAPTER_SORT_LOCAL = 0x00001000
const val CHAPTER_SORT_LOCAL_MASK = 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_UNREAD = 0x00000002
const val CHAPTER_SHOW_READ = 0x00000004 const val CHAPTER_SHOW_READ = 0x00000004

View File

@ -239,7 +239,7 @@ object PreferenceKeys {
const val defaultChapterSortByAscendingOrDescending = "default_chapter_sort_by_ascending_or_descending" 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" fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId"

View File

@ -424,28 +424,17 @@ class PreferencesHelper(val context: Context) {
fun incognitoMode() = flowPrefs.getBoolean(Keys.incognitoMode, false) 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 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 chaptersDescAsDefault() = rxPrefs.getBoolean("chapters_desc_as_default", true)
fun sortChapterByAscendingOrDescending() = prefs.getInt(Keys.defaultChapterSortByAscendingOrDescending, Manga.CHAPTER_SORT_DESC) 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)
}
}
} }

View File

@ -211,16 +211,6 @@ class MangaDetailsPresenter(
return model 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. * Whether the sorting method is descending or ascending.
*/ */
@ -507,6 +497,13 @@ class MangaDetailsPresenter(
asyncUpdateMangaAndChapters() 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 globalSort(): Boolean = preferences.chaptersDescAsDefault().getOrDefault()
private fun globalSorting(): Int = preferences.sortChapterOrder().get() private fun globalSorting(): Int = preferences.sortChapterOrder().get()
@ -515,11 +512,13 @@ class MangaDetailsPresenter(
return (manga.sortDescending() == globalSort() && manga.sorting == globalSorting()) || !manga.usesLocalSort() return (manga.sortDescending() == globalSort() && manga.sorting == globalSorting()) || !manga.usesLocalSort()
} }
fun setGlobalChapterSort(sort: Int, descend: Boolean) { fun mangaFilterMatchesDefault(): Boolean {
preferences.sortChapterOrder().set(sort) return (
preferences.chaptersDescAsDefault().set(descend) manga.readFilter == preferences.filterChapterByRead().get() &&
manga.setSortToGlobal() manga.downloadedFilter == preferences.filterChapterByDownloaded().get() &&
asyncUpdateMangaAndChapters() manga.bookmarkedFilter == preferences.filterChapterByBookmarked().get() &&
manga.hideChapterTitles() == preferences.hideChapterTitlesByDefault().get()
) || !manga.usesLocalFilter()
} }
fun resetSortingToDefault() { fun resetSortingToDefault() {
@ -550,6 +549,60 @@ class MangaDetailsPresenter(
TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED TriStateCheckBox.State.INVERSED -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED
else -> Manga.SHOW_ALL 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() asyncUpdateMangaAndChapters()
} }
@ -563,12 +616,12 @@ class MangaDetailsPresenter(
fun currentFilters(): String { fun currentFilters(): String {
val filtersId = mutableListOf<Int?>() val filtersId = mutableListOf<Int?>()
filtersId.add(if (manga.readFilter == Manga.CHAPTER_SHOW_READ) R.string.read else null) filtersId.add(if (manga.readFilter(preferences) == 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.readFilter(preferences) == 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(preferences) == 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.downloadedFilter(preferences) == 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(preferences) == 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.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_BOOKMARKED) R.string.not_bookmarked else null)
return filtersId.filterNotNull().joinToString(", ") { preferences.context.getString(it) } return filtersId.filterNotNull().joinToString(", ") { preferences.context.getString(it) }
} }

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.LinearLayout import android.widget.LinearLayout
import eu.kanade.tachiyomi.data.database.models.Manga 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.databinding.ChapterFilterLayoutBinding
import eu.kanade.tachiyomi.widget.TriStateCheckBox import eu.kanade.tachiyomi.widget.TriStateCheckBox
@ -11,6 +12,7 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att
LinearLayout(context, attrs) { LinearLayout(context, attrs) {
lateinit var binding: ChapterFilterLayoutBinding lateinit var binding: ChapterFilterLayoutBinding
private var mOnCheckedChangeListener: OnCheckedChangeListener? = null
override fun onFinishInflate() { override fun onFinishInflate() {
super.onFinishInflate() super.onFinishInflate()
@ -41,20 +43,21 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att
) { ) {
binding.showAll.animateDrawableToState(TriStateCheckBox.State.CHECKED) binding.showAll.animateDrawableToState(TriStateCheckBox.State.CHECKED)
} }
mOnCheckedChangeListener?.onCheckedChanged(this)
} }
fun setCheckboxes(manga: Manga) { fun setCheckboxes(manga: Manga, preferences: PreferencesHelper) {
binding.showUnread.state = when (manga.readFilter) { binding.showUnread.state = when (manga.readFilter(preferences)) {
Manga.CHAPTER_SHOW_UNREAD -> TriStateCheckBox.State.CHECKED Manga.CHAPTER_SHOW_UNREAD -> TriStateCheckBox.State.CHECKED
Manga.CHAPTER_SHOW_READ -> TriStateCheckBox.State.INVERSED Manga.CHAPTER_SHOW_READ -> TriStateCheckBox.State.INVERSED
else -> TriStateCheckBox.State.UNCHECKED 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_DOWNLOADED -> TriStateCheckBox.State.CHECKED
Manga.CHAPTER_SHOW_NOT_DOWNLOADED -> TriStateCheckBox.State.INVERSED Manga.CHAPTER_SHOW_NOT_DOWNLOADED -> TriStateCheckBox.State.INVERSED
else -> TriStateCheckBox.State.UNCHECKED 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_BOOKMARKED -> TriStateCheckBox.State.CHECKED
Manga.CHAPTER_SHOW_NOT_BOOKMARKED -> TriStateCheckBox.State.INVERSED Manga.CHAPTER_SHOW_NOT_BOOKMARKED -> TriStateCheckBox.State.INVERSED
else -> TriStateCheckBox.State.UNCHECKED else -> TriStateCheckBox.State.UNCHECKED
@ -64,4 +67,27 @@ class ChapterFilterLayout @JvmOverloads constructor(context: Context, attrs: Att
binding.showDownload.isUnchecked && binding.showDownload.isUnchecked &&
binding.showBookmark.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)
}
} }

View File

@ -33,13 +33,10 @@ class ChapterHolder(
fun bind(item: ChapterItem, manga: Manga) { fun bind(item: ChapterItem, manga: Manga) {
val chapter = item.chapter val chapter = item.chapter
val isLocked = item.isLocked val isLocked = item.isLocked
binding.chapterTitle.text = when (manga.displayMode) { binding.chapterTitle.text = if (manga.hideChapterTitle(adapter.preferences)) {
Manga.CHAPTER_DISPLAY_NUMBER -> { val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble())
val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) itemView.context.getString(R.string.chapter_, number)
itemView.context.getString(R.string.chapter_, number) } else chapter.name
}
else -> chapter.name
}
localSource = manga.source == LocalSource.ID localSource = manga.source == LocalSource.ID
binding.downloadButton.downloadButton.isVisible = !localSource && !isLocked binding.downloadButton.downloadButton.isVisible = !localSource && !isLocked

View File

@ -24,7 +24,7 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) :
override fun createBinding(inflater: LayoutInflater) = ChapterSortBottomSheetBinding.inflate(inflater) override fun createBinding(inflater: LayoutInflater) = ChapterSortBottomSheetBinding.inflate(inflater)
init { init {
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
sheetBehavior.peekHeight = 415.dpToPx + height sheetBehavior.peekHeight = 460.dpToPx + height
sheetBehavior.addBottomSheetCallback( sheetBehavior.addBottomSheetCallback(
object : BottomSheetBehavior.BottomSheetCallback() { object : BottomSheetBehavior.BottomSheetCallback() {
@ -64,18 +64,12 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) :
// making the view gone somehow breaks the layout so lets make it invisible // making the view gone somehow breaks the layout so lets make it invisible
binding.pill.isInvisible = isScrollable binding.pill.isInvisible = isScrollable
} }
setOnDismissListener {
presenter.setFilters(
binding.chapterFilterLayout.showUnread.state,
binding.chapterFilterLayout.showDownload.state,
binding.chapterFilterLayout.showBookmark.state
)
}
} }
private fun initGeneralPreferences() { 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.byChapterNumber.state = SortTextView.State.NONE
binding.byUploadDate.state = SortTextView.State.NONE binding.byUploadDate.state = SortTextView.State.NONE
@ -98,7 +92,7 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) :
binding.byUploadDate.setOnSortChangeListener(::sortChanged) binding.byUploadDate.setOnSortChangeListener(::sortChanged)
binding.bySource.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 { binding.setAsDefaultSort.setOnClickListener {
presenter.setGlobalChapterSort( presenter.setGlobalChapterSort(
@ -133,7 +127,42 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) :
binding.hideTitles.setOnCheckedChangeListener { _, isChecked -> binding.hideTitles.setOnCheckedChangeListener { _, isChecked ->
presenter.hideTitle(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() { private fun checkIfSortMatchesDefault() {

View File

@ -8,8 +8,10 @@ import com.mikepenz.fastadapter.items.AbstractItem
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.databinding.ReaderChapterItemBinding
import eu.kanade.tachiyomi.util.chapter.ChapterUtil import eu.kanade.tachiyomi.util.chapter.ChapterUtil
import uy.kohesive.injekt.injectLazy
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.DecimalFormatSymbols import java.text.DecimalFormatSymbols
@ -20,6 +22,8 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B
val decimalFormat = val decimalFormat =
DecimalFormat("#.###", DecimalFormatSymbols().apply { decimalSeparator = '.' }) DecimalFormat("#.###", DecimalFormatSymbols().apply { decimalSeparator = '.' })
val preferences: PreferencesHelper by injectLazy()
/** defines the type defining this item. must be unique. preferably an id */ /** defines the type defining this item. must be unique. preferably an id */
override val type: Int = R.id.reader_chapter_layout 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) val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter)
binding.chapterTitle.text = when (manga.displayMode) { binding.chapterTitle.text = if (manga.hideChapterTitle(item.preferences)) {
Manga.CHAPTER_DISPLAY_NUMBER -> { val number = item.decimalFormat.format(item.chapter_number.toDouble())
val number = item.decimalFormat.format(item.chapter_number.toDouble()) itemView.context.getString(R.string.chapter_, number)
itemView.context.getString(R.string.chapter_, number) } else item.name
}
else -> item.name
}
val statuses = mutableListOf<String>() val statuses = mutableListOf<String>()
ChapterUtil.relativeDate(item)?.let { statuses.add(it) } ChapterUtil.relativeDate(item)?.let { statuses.add(it) }

View File

@ -16,7 +16,7 @@ import java.text.DecimalFormatSymbols
class RecentMangaAdapter(val delegate: RecentsInterface) : class RecentMangaAdapter(val delegate: RecentsInterface) :
BaseChapterAdapter<IFlexible<*>>(delegate) { BaseChapterAdapter<IFlexible<*>>(delegate) {
private val preferences: PreferencesHelper by injectLazy() val preferences: PreferencesHelper by injectLazy()
var showDownloads = preferences.showRecentsDownloads().get() var showDownloads = preferences.showRecentsDownloads().get()
var showRemoveHistory = preferences.showRecentsRemHistory().get() var showRemoveHistory = preferences.showRecentsRemHistory().get()

View File

@ -82,9 +82,13 @@ class RecentMangaHolder(
} }
} }
binding.removeHistory.isVisible = item.mch.history.id != null && showRemoveHistory 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 { binding.title.apply {
text = if (!showTitleFirst) { text = if (!showTitleFirst) {
item.chapter.name chapterName
} else { } else {
item.mch.manga.title item.mch.manga.title
} }
@ -94,7 +98,7 @@ class RecentMangaHolder(
text = if (!showTitleFirst) { text = if (!showTitleFirst) {
item.mch.manga.title item.mch.manga.title
} else { } else {
item.chapter.name chapterName
} }
setTextColor(ChapterUtil.readColor(context, item)) setTextColor(ChapterUtil.readColor(context, item))
} }

View File

@ -11,12 +11,12 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl
// filters chapters based on the manga values // filters chapters based on the manga values
fun <T : Chapter> filterChapters(chapters: List<T>, manga: Manga): List<T> { fun <T : Chapter> filterChapters(chapters: List<T>, manga: Manga): List<T> {
val readEnabled = manga.readFilter == Manga.CHAPTER_SHOW_READ val readEnabled = manga.readFilter(preferences) == Manga.CHAPTER_SHOW_READ
val unreadEnabled = manga.readFilter == Manga.CHAPTER_SHOW_UNREAD val unreadEnabled = manga.readFilter(preferences) == Manga.CHAPTER_SHOW_UNREAD
val downloadEnabled = manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED val downloadEnabled = manga.downloadedFilter(preferences) == Manga.CHAPTER_SHOW_DOWNLOADED
val notDownloadEnabled = manga.downloadedFilter == Manga.CHAPTER_SHOW_NOT_DOWNLOADED val notDownloadEnabled = manga.downloadedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_DOWNLOADED
val bookmarkEnabled = manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED val bookmarkEnabled = manga.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_BOOKMARKED
val notBookmarkEnabled = manga.bookmarkedFilter == Manga.CHAPTER_SHOW_NOT_BOOKMARKED val notBookmarkEnabled = manga.bookmarkedFilter(preferences) == Manga.CHAPTER_SHOW_NOT_BOOKMARKED
// if none of the filters are enabled skip the filtering of them // if none of the filters are enabled skip the filtering of them
return if (readEnabled || unreadEnabled || downloadEnabled || notDownloadEnabled || bookmarkEnabled || notBookmarkEnabled) { return if (readEnabled || unreadEnabled || downloadEnabled || notDownloadEnabled || bookmarkEnabled || notBookmarkEnabled) {

View File

@ -5,14 +5,49 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView <androidx.constraintlayout.widget.ConstraintLayout
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:layout_marginTop="12dp" <com.google.android.material.textview.MaterialTextView
android:paddingStart="16dp" android:id="@+id/filter_title"
android:paddingEnd="12dp" style="@style/TextAppearance.MaterialComponents.Headline6"
android:text="@string/filter" /> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingStart="16dp"
android:layout_gravity="center_vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingEnd="12dp"
android:text="@string/filter" />
<com.google.android.material.button.MaterialButton
android:id="@+id/set_as_default_filter"
style="@style/Theme.Widget.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="38sp"
android:padding="4dp"
android:layout_marginStart="6dp"
android:layout_gravity="center_vertical"
app:layout_constraintBaseline_toBaselineOf="@id/filter_title"
app:layout_constraintStart_toEndOf="@id/filter_title"
android:text="@string/set_as_default" />
<com.google.android.material.button.MaterialButton
android:id="@+id/reset_as_default_filter"
style="@style/Theme.Widget.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="38sp"
android:padding="4dp"
android:layout_marginEnd="6dp"
app:layout_constraintStart_toEndOf="@id/set_as_default_filter"
app:layout_constraintHorizontal_bias="1.0"
android:layout_gravity="center_vertical"
app:layout_constraintBaseline_toBaselineOf="@id/filter_title"
app:layout_constraintEnd_toEndOf="parent"
android:text="@string/reset" />
</androidx.constraintlayout.widget.ConstraintLayout>
<eu.kanade.tachiyomi.widget.TriStateCheckBox <eu.kanade.tachiyomi.widget.TriStateCheckBox
android:id="@+id/show_all" android:id="@+id/show_all"

View File

@ -58,6 +58,8 @@
android:padding="4dp" android:padding="4dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
app:layout_constraintStart_toEndOf="@id/set_as_default_sort"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintBaseline_toBaselineOf="@id/sort_title" app:layout_constraintBaseline_toBaselineOf="@id/sort_title"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:text="@string/reset" /> android:text="@string/reset" />
@ -86,18 +88,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingStart="16dp"
android:paddingEnd="12dp"
android:text="@string/more" />
<com.google.android.material.checkbox.MaterialCheckBox <com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/hide_titles" android:id="@+id/hide_titles"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_marginTop="6dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"