Hide tracking when no tracker is logged in and change filter logic (#4310)

* Hide tracking when not logged in

* Change string name and value
This commit is contained in:
Andreas 2021-01-18 23:08:11 +01:00 committed by GitHub
parent 4044427d93
commit 1a5858e99b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 9 deletions

View File

@ -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<Map<Long, Boolean>> {
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())
}

View File

@ -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) {

View File

@ -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
}
}
}

View File

@ -34,7 +34,7 @@
<string name="action_filter">Filter</string>
<string name="action_filter_downloaded">Downloaded</string>
<string name="action_filter_bookmarked">Bookmarked</string>
<string name="action_filter_tracking">Tracking</string>
<string name="action_filter_tracked">Tracked</string>
<string name="action_filter_unread">Unread</string>
<string name="action_filter_empty">Remove filter</string>
<string name="action_sort_alpha">Alphabetically</string>