From 1a5858e99ba98482a6470c7f70b2e4c43323940f Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 18 Jan 2021 23:08:11 +0100 Subject: [PATCH] Hide tracking when no tracker is logged in and change filter logic (#4310) * Hide tracking when not logged in * Change string name and value --- .../tachiyomi/ui/library/LibraryPresenter.kt | 14 +++++++++----- .../tachiyomi/ui/library/LibrarySettingsSheet.kt | 15 +++++++++++++-- .../tachiyomi/widget/ExtendedNavigationView.kt | 4 +++- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) 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 71882b27b..6f4cef0bc 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 @@ -118,6 +118,7 @@ class LibraryPresenter( val filterUnread = preferences.filterUnread().get() val filterCompleted = preferences.filterCompleted().get() val tracking = preferences.filterTracking().get() + val isNotLogged = !trackManager.hasLoggedServices() val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item -> if (filterUnread == State.IGNORE.value) return@unread true @@ -148,7 +149,7 @@ class LibraryPresenter( } val filterFnTracking: (LibraryItem) -> Boolean = tracking@{ item -> - if (tracking == State.IGNORE.value) return@tracking true + if (isNotLogged || tracking == State.IGNORE.value) return@tracking true val isTracking = trackMap[item.manga.id ?: -1] ?: false @@ -310,10 +311,13 @@ class LibraryPresenter( */ private fun getTracksObservable(): Observable> { return db.getTracks().asRxObservable().map { tracks -> - tracks.associate { track -> - val isLogged = tracks.any { trackManager.getService(it.sync_id)?.isLogged ?: false } - Pair(track.manga_id, isLogged) - } + tracks.groupBy { it.manga_id } + .mapValues { tracksForMangaId -> + // Check if any of the trackers is logged in for the current manga id + tracksForMangaId.value.any { + trackManager.getService(it.sync_id)?.isLogged ?: false + } + } }.observeOn(Schedulers.io()) } 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 23642c5cd..493946672 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 @@ -7,10 +7,12 @@ import com.bluelinelabs.conductor.Router import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.widget.ExtendedNavigationView import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog import uy.kohesive.injekt.injectLazy +import uy.kohesive.injekt.injectValue class LibrarySettingsSheet( router: Router, @@ -52,6 +54,8 @@ class LibrarySettingsSheet( private val filterGroup = FilterGroup() + private val trackManager: TrackManager by injectValue() + init { setGroups(listOf(filterGroup)) } @@ -68,7 +72,7 @@ class LibrarySettingsSheet( private val downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this) private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) private val completed = Item.TriStateGroup(R.string.completed, this) - private val tracking = Item.TriStateGroup(R.string.action_filter_tracking, this) + private val tracking = Item.TriStateGroup(R.string.action_filter_tracked, this) override val header = null override val items = listOf(downloaded, unread, completed, tracking) @@ -83,7 +87,14 @@ class LibrarySettingsSheet( } unread.state = preferences.filterUnread().get() completed.state = preferences.filterCompleted().get() - tracking.state = preferences.filterTracking().get() + + if (!trackManager.hasLoggedServices()) { + tracking.state = State.IGNORE.value + tracking.isVisible = false + } else { + tracking.state = preferences.filterTracking().get() + tracking.isVisible = true + } } override fun onItemClicked(item: Item) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt index b52a49cdb..01a2939fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt @@ -8,6 +8,7 @@ import androidx.annotation.AttrRes import androidx.annotation.CallSuper import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor @@ -59,7 +60,7 @@ open class ExtendedNavigationView @JvmOverloads constructor( /** * An item with which needs more than two states (selected/deselected). */ - abstract class MultiState(val resTitle: Int, var state: Int = 0, var enabled: Boolean = true) : Item() { + abstract class MultiState(val resTitle: Int, var state: Int = 0, var enabled: Boolean = true, var isVisible: Boolean = true) : Item() { /** * Returns the drawable associated to every possible each state. @@ -258,6 +259,7 @@ open class ExtendedNavigationView @JvmOverloads constructor( // Mimics checkbox/radio button holder.text.alpha = if (item.enabled) 1f else 0.4f + holder.itemView.isVisible = item.isVisible } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 25742976d..85bf2a221 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,7 +34,7 @@ Filter Downloaded Bookmarked - Tracking + Tracked Unread Remove filter Alphabetically