Option to hide unread badges (closes #3095)
This commit is contained in:
parent
521ebf0678
commit
1442e2b53e
@ -141,6 +141,8 @@ object PreferenceKeys {
|
||||
|
||||
const val downloadBadge = "display_download_badge"
|
||||
|
||||
const val unreadBadge = "display_unread_badge"
|
||||
|
||||
const val alwaysShowChapterTransition = "always_show_chapter_transition"
|
||||
|
||||
const val searchPinnedSourcesOnly = "search_pinned_sources_only"
|
||||
|
@ -205,6 +205,8 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun downloadedOnly() = flowPrefs.getBoolean(Keys.downloadedOnly, false)
|
||||
|
||||
fun unreadBadge() = flowPrefs.getBoolean(Keys.unreadBadge, false)
|
||||
|
||||
fun filterDownloaded() = flowPrefs.getBoolean(Keys.filterDownloaded, false)
|
||||
|
||||
fun filterUnread() = flowPrefs.getBoolean(Keys.filterUnread, false)
|
||||
|
@ -171,7 +171,7 @@ class LibraryController(
|
||||
is LibrarySettingsSheet.Filter.FilterGroup -> onFilterChanged()
|
||||
is LibrarySettingsSheet.Sort.SortGroup -> onSortChanged()
|
||||
is LibrarySettingsSheet.Display.DisplayGroup -> reattachAdapter()
|
||||
is LibrarySettingsSheet.Display.BadgeGroup -> onDownloadBadgeChanged()
|
||||
is LibrarySettingsSheet.Display.BadgeGroup -> onBadgeChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,8 +284,8 @@ class LibraryController(
|
||||
activity?.invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
private fun onDownloadBadgeChanged() {
|
||||
presenter.requestDownloadBadgesUpdate()
|
||||
private fun onBadgeChanged() {
|
||||
presenter.requestBadgesUpdate()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,8 +39,8 @@ class LibraryGridHolder(
|
||||
|
||||
// Update the unread count and its visibility.
|
||||
with(unread_text) {
|
||||
visibleIf { item.manga.unread > 0 }
|
||||
text = item.manga.unread.toString()
|
||||
visibleIf { item.unreadCount > 0 }
|
||||
text = item.unreadCount.toString()
|
||||
}
|
||||
// Update the download count and its visibility.
|
||||
with(download_text) {
|
||||
|
@ -25,6 +25,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference
|
||||
private val sourceManager: SourceManager = Injekt.get()
|
||||
|
||||
var downloadCount = -1
|
||||
var unreadCount = -1
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return if (libraryAsList.get()) {
|
||||
|
@ -66,7 +66,7 @@ class LibraryPresenter(
|
||||
/**
|
||||
* 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.
|
||||
@ -89,8 +89,8 @@ class LibraryPresenter(
|
||||
fun subscribeLibrary() {
|
||||
if (librarySubscription.isNullOrUnsubscribed()) {
|
||||
librarySubscription = getLibraryObservable()
|
||||
.combineLatest(downloadTriggerRelay.observeOn(Schedulers.io())) { lib, _ ->
|
||||
lib.apply { setDownloadCount(mangaMap) }
|
||||
.combineLatest(badgeTriggerRelay.observeOn(Schedulers.io())) { lib, _ ->
|
||||
lib.apply { setBadges(mangaMap) }
|
||||
}
|
||||
.combineLatest(filterTriggerRelay.observeOn(Schedulers.io())) { lib, _ ->
|
||||
lib.copy(mangaMap = applyFilters(lib.mangaMap))
|
||||
@ -149,20 +149,25 @@ class LibraryPresenter(
|
||||
*
|
||||
* @param map the map of manga.
|
||||
*/
|
||||
private fun setDownloadCount(map: LibraryMap) {
|
||||
if (!preferences.downloadBadge().get()) {
|
||||
// Unset download count if the preference is not enabled.
|
||||
for ((_, itemList) in map) {
|
||||
for (item in itemList) {
|
||||
item.downloadCount = -1
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
private fun setBadges(map: LibraryMap) {
|
||||
val showDownloadBadges = preferences.downloadBadge().get()
|
||||
val showUnreadBadges = preferences.unreadBadge().get()
|
||||
|
||||
for ((_, itemList) in map) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -275,8 +280,8 @@ class LibraryPresenter(
|
||||
/**
|
||||
* Requests the library to have download badges added.
|
||||
*/
|
||||
fun requestDownloadBadgesUpdate() {
|
||||
downloadTriggerRelay.call(Unit)
|
||||
fun requestBadgesUpdate() {
|
||||
badgeTriggerRelay.call(Unit)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,19 +210,24 @@ class LibrarySettingsSheet(
|
||||
|
||||
inner class BadgeGroup : Group {
|
||||
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 items = listOf(downloadBadge)
|
||||
override val items = listOf(downloadBadge, unreadBadge)
|
||||
override val footer = null
|
||||
|
||||
override fun initModels() {
|
||||
downloadBadge.checked = preferences.downloadBadge().get()
|
||||
unreadBadge.checked = preferences.unreadBadge().get()
|
||||
}
|
||||
|
||||
override fun onItemClicked(item: Item) {
|
||||
item as Item.CheckboxGroup
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,7 @@
|
||||
<string name="action_display_grid">Grid</string>
|
||||
<string name="action_display_list">List</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_pin">Pin</string>
|
||||
<string name="action_unpin">Unpin</string>
|
||||
|
Loading…
Reference in New Issue
Block a user