mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 05:27:28 +01:00
Add badge to bottom bar Updates tab indicating how many unread chapter updates are available (#5620)
Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
@@ -68,6 +68,7 @@ import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import logcat.LogPriority
|
||||
|
||||
@@ -227,6 +228,10 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
merge(preferences.libraryUpdateShowTabBadge().asFlow(), preferences.libraryUnreadUpdatesCount().asFlow())
|
||||
.onEach { setUnreadUpdatesBadge() }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
preferences.extensionUpdatesCount()
|
||||
.asImmediateFlow { setExtensionsBadge() }
|
||||
.launchIn(lifecycleScope)
|
||||
@@ -349,6 +354,15 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUnreadUpdatesBadge() {
|
||||
val updates = if (preferences.libraryUpdateShowTabBadge().get()) preferences.libraryUnreadUpdatesCount().get() else 0
|
||||
if (updates > 0) {
|
||||
nav.getOrCreateBadge(R.id.nav_updates).number = updates
|
||||
} else {
|
||||
nav.removeBadge(R.id.nav_updates)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setExtensionsBadge() {
|
||||
val updates = preferences.extensionUpdatesCount().get()
|
||||
if (updates > 0) {
|
||||
|
||||
@@ -105,6 +105,9 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
|
||||
}
|
||||
setDownloadedChapters(list)
|
||||
chapters = list
|
||||
|
||||
//Set unread chapter count for bottom bar badge
|
||||
preferences.libraryUnreadUpdatesCount().set(list.count { !it.read })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,11 @@ class SettingsLibraryController : SettingsController() {
|
||||
titleRes = R.string.pref_update_only_non_completed
|
||||
defaultValue = false
|
||||
}
|
||||
switchPreference {
|
||||
key = Keys.libraryUpdateShowTabBadge
|
||||
titleRes = R.string.pref_library_update_show_tab_badge
|
||||
defaultValue = true
|
||||
}
|
||||
preference {
|
||||
key = Keys.libraryUpdateCategories
|
||||
titleRes = R.string.categories
|
||||
|
||||
Reference in New Issue
Block a user