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:
Hunter Nickel 2021-10-30 10:32:51 -06:00 committed by GitHub
parent 00817aacfe
commit 459759bfe5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 0 deletions

View file

@ -291,6 +291,7 @@ class LibraryUpdateService(
val failedUpdates = CopyOnWriteArrayList<Pair<Manga, String?>>() val failedUpdates = CopyOnWriteArrayList<Pair<Manga, String?>>()
val hasDownloads = AtomicBoolean(false) val hasDownloads = AtomicBoolean(false)
val loggedServices by lazy { trackManager.services.filter { it.isLogged } } val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
val currentUnreadUpdatesCount = preferences.libraryUnreadUpdatesCount().get()
withIOContext { withIOContext {
mangaToUpdate.groupBy { it.source } mangaToUpdate.groupBy { it.source }
@ -354,6 +355,8 @@ class LibraryUpdateService(
if (newUpdates.isNotEmpty()) { if (newUpdates.isNotEmpty()) {
notifier.showUpdateNotifications(newUpdates) notifier.showUpdateNotifications(newUpdates)
val newChapterCount = newUpdates.sumOf { it.second.size }
preferences.libraryUnreadUpdatesCount().set(currentUnreadUpdatesCount + newChapterCount)
if (hasDownloads.get()) { if (hasDownloads.get()) {
DownloadService.start(this) DownloadService.start(this)
} }

View file

@ -133,6 +133,8 @@ object PreferenceKeys {
const val libraryUpdateRestriction = "library_update_restriction" const val libraryUpdateRestriction = "library_update_restriction"
const val libraryUpdateShowTabBadge = "library_update_show_tab_badge"
const val libraryUpdateCategories = "library_update_categories" const val libraryUpdateCategories = "library_update_categories"
const val libraryUpdateCategoriesExclude = "library_update_categories_exclude" const val libraryUpdateCategoriesExclude = "library_update_categories_exclude"

View file

@ -238,6 +238,9 @@ class PreferencesHelper(val context: Context) {
fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(ONLY_ON_WIFI)) fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(ONLY_ON_WIFI))
fun libraryUpdateShowTabBadge() = flowPrefs.getBoolean(Keys.libraryUpdateShowTabBadge, true)
fun libraryUnreadUpdatesCount() = flowPrefs.getInt("library_unread_updates_count", 0)
fun libraryUpdateCategories() = flowPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet()) fun libraryUpdateCategories() = flowPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet())
fun libraryUpdateCategoriesExclude() = flowPrefs.getStringSet(Keys.libraryUpdateCategoriesExclude, emptySet()) fun libraryUpdateCategoriesExclude() = flowPrefs.getStringSet(Keys.libraryUpdateCategoriesExclude, emptySet())

View file

@ -68,6 +68,7 @@ import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import logcat.LogPriority import logcat.LogPriority
@ -227,6 +228,10 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
} }
} }
merge(preferences.libraryUpdateShowTabBadge().asFlow(), preferences.libraryUnreadUpdatesCount().asFlow())
.onEach { setUnreadUpdatesBadge() }
.launchIn(lifecycleScope)
preferences.extensionUpdatesCount() preferences.extensionUpdatesCount()
.asImmediateFlow { setExtensionsBadge() } .asImmediateFlow { setExtensionsBadge() }
.launchIn(lifecycleScope) .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() { private fun setExtensionsBadge() {
val updates = preferences.extensionUpdatesCount().get() val updates = preferences.extensionUpdatesCount().get()
if (updates > 0) { if (updates > 0) {

View file

@ -105,6 +105,9 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
} }
setDownloadedChapters(list) setDownloadedChapters(list)
chapters = list chapters = list
//Set unread chapter count for bottom bar badge
preferences.libraryUnreadUpdatesCount().set(list.count { !it.read })
} }
} }

View file

@ -199,6 +199,11 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_update_only_non_completed titleRes = R.string.pref_update_only_non_completed
defaultValue = false defaultValue = false
} }
switchPreference {
key = Keys.libraryUpdateShowTabBadge
titleRes = R.string.pref_library_update_show_tab_badge
defaultValue = true
}
preference { preference {
key = Keys.libraryUpdateCategories key = Keys.libraryUpdateCategories
titleRes = R.string.categories titleRes = R.string.categories

View file

@ -223,6 +223,7 @@
<string name="charging">Charging</string> <string name="charging">Charging</string>
<string name="restrictions">Restrictions: %s</string> <string name="restrictions">Restrictions: %s</string>
<string name="pref_update_only_non_completed">Only update ongoing manga</string> <string name="pref_update_only_non_completed">Only update ongoing manga</string>
<string name="pref_library_update_show_tab_badge">Show update count on bottom bar</string>
<string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string> <string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string>
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string> <string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>
<string name="pref_library_update_refresh_trackers">Automatically refresh trackers</string> <string name="pref_library_update_refresh_trackers">Automatically refresh trackers</string>