mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Option to hide unread badges (closes #3095)
(cherry picked from commit 1442e2b53e)
# 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:
		| @@ -143,6 +143,8 @@ object PreferenceKeys { | ||||
|  | ||||
|     const val downloadBadge = "display_download_badge" | ||||
|  | ||||
|     const val unreadBadge = "display_unread_badge" | ||||
|  | ||||
|     const val skipPreMigration = "skip_pre_migration" | ||||
|  | ||||
|     const val alwaysShowChapterTransition = "always_show_chapter_transition" | ||||
|   | ||||
| @@ -207,6 +207,8 @@ class PreferencesHelper(val context: Context) { | ||||
|  | ||||
|     fun downloadedOnly() = flowPrefs.getBoolean(Keys.downloadedOnly, false) | ||||
|  | ||||
|     fun unreadBadge() = flowPrefs.getBoolean(Keys.unreadBadge, false) | ||||
|  | ||||
|     // J2K converted from boolean to integer | ||||
|     fun filterDownloaded() = flowPrefs.getInt(Keys.filterDownloaded, 0) | ||||
|  | ||||
|   | ||||
| @@ -202,7 +202,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() | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -315,8 +315,8 @@ class LibraryController( | ||||
|         activity?.invalidateOptionsMenu() | ||||
|     } | ||||
|  | ||||
|     private fun onDownloadBadgeChanged() { | ||||
|         presenter.requestDownloadBadgesUpdate() | ||||
|     private fun onBadgeChanged() { | ||||
|         presenter.requestBadgesUpdate() | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -44,8 +44,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()) { | ||||
|   | ||||
| @@ -74,7 +74,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. | ||||
| @@ -101,8 +101,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)) | ||||
| @@ -162,20 +162,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 | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -297,8 +302,8 @@ class LibraryPresenter( | ||||
|     /** | ||||
|      * Requests the library to have download badges added. | ||||
|      */ | ||||
|     fun requestDownloadBadgesUpdate() { | ||||
|         downloadTriggerRelay.call(Unit) | ||||
|     fun requestBadgesUpdate() { | ||||
|         badgeTriggerRelay.call(Unit) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -229,19 +229,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) | ||||
|             } | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user