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 8ae37d9fc9..2eadd175cc 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
@@ -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"
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 8b93cec085..371bc754f1 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
@@ -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)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
index a342457265..955a225d4d 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
@@ -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()
}
/**
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt
index 5c1bf711a0..5db7cc4135 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt
@@ -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) {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt
index 5a8e42629c..736c878178 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt
@@ -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()) {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
index d22247e687..2751eceefc 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
@@ -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)
}
/**
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt
index c93f8cce8e..a7e96eb67a 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt
@@ -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)
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index de0f2d582b..d6309d420d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -83,6 +83,7 @@
Grid
List
Download badges
+ Unread badges
Hide
Pin
Unpin