Option to hide unread badges (closes #3095)

(cherry picked from commit 1442e2b53e8394b0988f1cf638f43a92d7c9f604)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt
#	app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt
This commit is contained in:
arkon 2020-05-08 23:01:16 -04:00 committed by Jobobby04
parent 60caba86a5
commit f19685787f
8 changed files with 39 additions and 23 deletions

View File

@ -143,6 +143,8 @@ object PreferenceKeys {
const val downloadBadge = "display_download_badge" const val downloadBadge = "display_download_badge"
const val unreadBadge = "display_unread_badge"
const val skipPreMigration = "skip_pre_migration" const val skipPreMigration = "skip_pre_migration"
const val alwaysShowChapterTransition = "always_show_chapter_transition" const val alwaysShowChapterTransition = "always_show_chapter_transition"

View File

@ -207,6 +207,8 @@ class PreferencesHelper(val context: Context) {
fun downloadedOnly() = flowPrefs.getBoolean(Keys.downloadedOnly, false) fun downloadedOnly() = flowPrefs.getBoolean(Keys.downloadedOnly, false)
fun unreadBadge() = flowPrefs.getBoolean(Keys.unreadBadge, false)
// J2K converted from boolean to integer // J2K converted from boolean to integer
fun filterDownloaded() = flowPrefs.getInt(Keys.filterDownloaded, 0) fun filterDownloaded() = flowPrefs.getInt(Keys.filterDownloaded, 0)

View File

@ -202,7 +202,7 @@ class LibraryController(
is LibrarySettingsSheet.Filter.FilterGroup -> onFilterChanged() is LibrarySettingsSheet.Filter.FilterGroup -> onFilterChanged()
is LibrarySettingsSheet.Sort.SortGroup -> onSortChanged() is LibrarySettingsSheet.Sort.SortGroup -> onSortChanged()
is LibrarySettingsSheet.Display.DisplayGroup -> reattachAdapter() is LibrarySettingsSheet.Display.DisplayGroup -> reattachAdapter()
is LibrarySettingsSheet.Display.BadgeGroup -> onDownloadBadgeChanged() is LibrarySettingsSheet.Display.BadgeGroup -> onBadgeChanged()
} }
} }
@ -315,8 +315,8 @@ class LibraryController(
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
} }
private fun onDownloadBadgeChanged() { private fun onBadgeChanged() {
presenter.requestDownloadBadgesUpdate() presenter.requestBadgesUpdate()
} }
/** /**

View File

@ -44,8 +44,8 @@ class LibraryGridHolder(
// Update the unread count and its visibility. // Update the unread count and its visibility.
with(unread_text) { with(unread_text) {
visibleIf { item.manga.unread > 0 } visibleIf { item.unreadCount > 0 }
text = item.manga.unread.toString() text = item.unreadCount.toString()
} }
// Update the download count and its visibility. // Update the download count and its visibility.
with(download_text) { with(download_text) {

View File

@ -25,6 +25,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference
private val sourceManager: SourceManager = Injekt.get() private val sourceManager: SourceManager = Injekt.get()
var downloadCount = -1 var downloadCount = -1
var unreadCount = -1
override fun getLayoutRes(): Int { override fun getLayoutRes(): Int {
return if (libraryAsList.get()) { return if (libraryAsList.get()) {

View File

@ -74,7 +74,7 @@ class LibraryPresenter(
/** /**
* Relay used to apply the UI update to the last emission of the library. * Relay used to apply the UI update to the last emission of the library.
*/ */
private val downloadTriggerRelay = BehaviorRelay.create(Unit) private val badgeTriggerRelay = BehaviorRelay.create(Unit)
/** /**
* Relay used to apply the selected sorting method to the last emission of the library. * Relay used to apply the selected sorting method to the last emission of the library.
@ -101,8 +101,8 @@ class LibraryPresenter(
fun subscribeLibrary() { fun subscribeLibrary() {
if (librarySubscription.isNullOrUnsubscribed()) { if (librarySubscription.isNullOrUnsubscribed()) {
librarySubscription = getLibraryObservable() librarySubscription = getLibraryObservable()
.combineLatest(downloadTriggerRelay.observeOn(Schedulers.io())) { lib, _ -> .combineLatest(badgeTriggerRelay.observeOn(Schedulers.io())) { lib, _ ->
lib.apply { setDownloadCount(mangaMap) } lib.apply { setBadges(mangaMap) }
} }
.combineLatest(filterTriggerRelay.observeOn(Schedulers.io())) { lib, _ -> .combineLatest(filterTriggerRelay.observeOn(Schedulers.io())) { lib, _ ->
lib.copy(mangaMap = applyFilters(lib.mangaMap)) lib.copy(mangaMap = applyFilters(lib.mangaMap))
@ -162,20 +162,25 @@ class LibraryPresenter(
* *
* @param map the map of manga. * @param map the map of manga.
*/ */
private fun setDownloadCount(map: LibraryMap) { private fun setBadges(map: LibraryMap) {
if (!preferences.downloadBadge().get()) { val showDownloadBadges = preferences.downloadBadge().get()
// Unset download count if the preference is not enabled. val showUnreadBadges = preferences.unreadBadge().get()
for ((_, itemList) in map) {
for (item in itemList) {
item.downloadCount = -1
}
}
return
}
for ((_, itemList) in map) { for ((_, itemList) in map) {
for (item in itemList) { for (item in itemList) {
item.downloadCount = downloadManager.getDownloadCount(item.manga) item.downloadCount = if (showDownloadBadges) {
downloadManager.getDownloadCount(item.manga)
} else {
// Unset download count if not enabled
-1
}
item.unreadCount = if (showUnreadBadges) {
item.manga.unread
} else {
// Unset unread count if not enabled
-1
}
} }
} }
} }
@ -297,8 +302,8 @@ class LibraryPresenter(
/** /**
* Requests the library to have download badges added. * Requests the library to have download badges added.
*/ */
fun requestDownloadBadgesUpdate() { fun requestBadgesUpdate() {
downloadTriggerRelay.call(Unit) badgeTriggerRelay.call(Unit)
} }
/** /**

View File

@ -229,19 +229,24 @@ class LibrarySettingsSheet(
inner class BadgeGroup : Group { inner class BadgeGroup : Group {
private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this) private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this)
private val unreadBadge = Item.CheckboxGroup(R.string.action_display_unread_badge, this)
override val header = null override val header = null
override val items = listOf(downloadBadge) override val items = listOf(downloadBadge, unreadBadge)
override val footer = null override val footer = null
override fun initModels() { override fun initModels() {
downloadBadge.checked = preferences.downloadBadge().get() downloadBadge.checked = preferences.downloadBadge().get()
unreadBadge.checked = preferences.unreadBadge().get()
} }
override fun onItemClicked(item: Item) { override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup item as Item.CheckboxGroup
item.checked = !item.checked item.checked = !item.checked
preferences.downloadBadge().set((item.checked)) when (item) {
downloadBadge -> preferences.downloadBadge().set((item.checked))
unreadBadge -> preferences.unreadBadge().set((item.checked))
}
adapter.notifyItemChanged(item) adapter.notifyItemChanged(item)
} }
} }

View File

@ -83,6 +83,7 @@
<string name="action_display_grid">Grid</string> <string name="action_display_grid">Grid</string>
<string name="action_display_list">List</string> <string name="action_display_list">List</string>
<string name="action_display_download_badge">Download badges</string> <string name="action_display_download_badge">Download badges</string>
<string name="action_display_unread_badge">Unread badges</string>
<string name="action_hide">Hide</string> <string name="action_hide">Hide</string>
<string name="action_pin">Pin</string> <string name="action_pin">Pin</string>
<string name="action_unpin">Unpin</string> <string name="action_unpin">Unpin</string>