|
@@ -8,14 +8,22 @@ 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.data.track.TrackService
|
|
|
+import eu.kanade.tachiyomi.data.track.anilist.Anilist
|
|
|
+import eu.kanade.tachiyomi.data.track.bangumi.Bangumi
|
|
|
+import eu.kanade.tachiyomi.data.track.kitsu.Kitsu
|
|
|
+import eu.kanade.tachiyomi.data.track.myanimelist.MyAnimeList
|
|
|
+import eu.kanade.tachiyomi.data.track.shikimori.Shikimori
|
|
|
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.Injekt
|
|
|
+import uy.kohesive.injekt.api.get
|
|
|
import uy.kohesive.injekt.injectLazy
|
|
|
-import uy.kohesive.injekt.injectValue
|
|
|
|
|
|
class LibrarySettingsSheet(
|
|
|
router: Router,
|
|
|
+ private val trackManager: TrackManager = Injekt.get(),
|
|
|
onGroupClickListener: (ExtendedNavigationView.Group) -> Unit
|
|
|
) : TabbedBottomSheetDialog(router) {
|
|
|
|
|
@@ -54,8 +62,6 @@ class LibrarySettingsSheet(
|
|
|
|
|
|
private val filterGroup = FilterGroup()
|
|
|
|
|
|
- private val trackManager: TrackManager by injectValue()
|
|
|
-
|
|
|
init {
|
|
|
setGroups(listOf(filterGroup))
|
|
|
}
|
|
@@ -64,7 +70,7 @@ class LibrarySettingsSheet(
|
|
|
* Returns true if there's at least one filter from [FilterGroup] active.
|
|
|
*/
|
|
|
fun hasActiveFilters(): Boolean {
|
|
|
- return filterGroup.items.any { it.state != State.IGNORE.value }
|
|
|
+ return filterGroup.items.filterIsInstance<Item.TriStateGroup>().any { it.state != State.IGNORE.value }
|
|
|
}
|
|
|
|
|
|
inner class FilterGroup : Group {
|
|
@@ -72,12 +78,41 @@ 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_tracked, this)
|
|
|
+ private val trackFilters: Map<String, Item.TriStateGroup>
|
|
|
|
|
|
override val header = null
|
|
|
- override val items = listOf(downloaded, unread, completed, tracking)
|
|
|
+ override val items: List<Item>
|
|
|
override val footer = null
|
|
|
|
|
|
+ init {
|
|
|
+ trackManager.services.filter { service -> service.isLogged }
|
|
|
+ .also { services ->
|
|
|
+ val size = services.size
|
|
|
+ trackFilters = services.associate { service ->
|
|
|
+ Pair(service.name, Item.TriStateGroup(getServiceResId(service, size), this))
|
|
|
+ }
|
|
|
+ val list: MutableList<Item> = mutableListOf(downloaded, unread, completed)
|
|
|
+ if (size > 1) list.add(Item.Header(R.string.action_filter_tracked))
|
|
|
+ list.addAll(trackFilters.values)
|
|
|
+ items = list
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getServiceResId(service: TrackService, size: Int): Int {
|
|
|
+ return if (size > 1) getServiceResId(service) else R.string.action_filter_tracked
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getServiceResId(service: TrackService): Int {
|
|
|
+ return when (service) {
|
|
|
+ is Anilist -> R.string.anilist
|
|
|
+ is MyAnimeList -> R.string.my_anime_list
|
|
|
+ is Kitsu -> R.string.kitsu
|
|
|
+ is Bangumi -> R.string.bangumi
|
|
|
+ is Shikimori -> R.string.shikimori
|
|
|
+ else -> R.string.unknown
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override fun initModels() {
|
|
|
if (preferences.downloadedOnly().get()) {
|
|
|
downloaded.state = State.INCLUDE.value
|
|
@@ -88,12 +123,8 @@ class LibrarySettingsSheet(
|
|
|
unread.state = preferences.filterUnread().get()
|
|
|
completed.state = preferences.filterCompleted().get()
|
|
|
|
|
|
- if (!trackManager.hasLoggedServices()) {
|
|
|
- tracking.state = State.IGNORE.value
|
|
|
- tracking.isVisible = false
|
|
|
- } else {
|
|
|
- tracking.state = preferences.filterTracking().get()
|
|
|
- tracking.isVisible = true
|
|
|
+ trackFilters.forEach { trackFilter ->
|
|
|
+ trackFilter.value.state = preferences.filterTracking(trackFilter.key).get()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -110,7 +141,13 @@ class LibrarySettingsSheet(
|
|
|
downloaded -> preferences.filterDownloaded().set(newState)
|
|
|
unread -> preferences.filterUnread().set(newState)
|
|
|
completed -> preferences.filterCompleted().set(newState)
|
|
|
- tracking -> preferences.filterTracking().set(newState)
|
|
|
+ else -> {
|
|
|
+ trackFilters.forEach { trackFilter ->
|
|
|
+ if (trackFilter.value == item) {
|
|
|
+ preferences.filterTracking(trackFilter.key).set(newState)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
adapter.notifyItemChanged(item)
|