mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
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 downloadBadge = "display_download_badge"
|
||||||
|
|
||||||
|
const val unreadBadge = "display_unread_badge"
|
||||||
|
|
||||||
const val alwaysShowChapterTransition = "always_show_chapter_transition"
|
const val alwaysShowChapterTransition = "always_show_chapter_transition"
|
||||||
|
|
||||||
const val searchPinnedSourcesOnly = "search_pinned_sources_only"
|
const val searchPinnedSourcesOnly = "search_pinned_sources_only"
|
||||||
|
@ -205,6 +205,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)
|
||||||
|
|
||||||
fun filterDownloaded() = flowPrefs.getBoolean(Keys.filterDownloaded, false)
|
fun filterDownloaded() = flowPrefs.getBoolean(Keys.filterDownloaded, false)
|
||||||
|
|
||||||
fun filterUnread() = flowPrefs.getBoolean(Keys.filterUnread, false)
|
fun filterUnread() = flowPrefs.getBoolean(Keys.filterUnread, false)
|
||||||
|
@ -171,7 +171,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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,8 +284,8 @@ class LibraryController(
|
|||||||
activity?.invalidateOptionsMenu()
|
activity?.invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onDownloadBadgeChanged() {
|
private fun onBadgeChanged() {
|
||||||
presenter.requestDownloadBadgesUpdate()
|
presenter.requestBadgesUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,8 +39,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) {
|
||||||
|
@ -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()) {
|
||||||
|
@ -66,7 +66,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.
|
||||||
@ -89,8 +89,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))
|
||||||
@ -149,20 +149,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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,8 +280,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,19 +210,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user