From 48cab708ce28ead30c5ea500899c17e379eb3000 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Jan 2023 10:37:30 -0500 Subject: [PATCH] Show available but not installed enhanced trackers Closes #8859 --- .../settings/screen/SettingsTrackingScreen.kt | 28 ++++++++++++++----- .../data/track/EnhancedTrackService.kt | 2 ++ .../data/track/NoLoginTrackService.kt | 8 ------ .../tachiyomi/data/track/kavita/Kavita.kt | 3 +- .../tachiyomi/data/track/komga/Komga.kt | 3 +- .../tachiyomi/data/track/suwayomi/Suwayomi.kt | 3 +- i18n/src/main/res/values/strings.xml | 1 + 7 files changed, 27 insertions(+), 21 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/track/NoLoginTrackService.kt diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt index b81ea6857a..f591ed155b 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt @@ -44,6 +44,7 @@ import androidx.compose.ui.unit.dp import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.presentation.more.settings.Preference import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.anilist.AnilistApi @@ -102,6 +103,23 @@ object SettingsTrackingScreen : SearchableSettings { } } + val enhancedTrackers = trackManager.services + .filter { it is EnhancedTrackService } + .partition { service -> + val acceptedSources = (service as EnhancedTrackService).getAcceptedSources() + sourceManager.getCatalogueSources().any { it::class.qualifiedName in acceptedSources } + } + var enhancedTrackerInfo = stringResource(R.string.enhanced_tracking_info) + if (enhancedTrackers.second.isNotEmpty()) { + val missingSourcesInfo = stringResource( + R.string.enhanced_services_not_installed, + enhancedTrackers.second + .map { stringResource(it.nameRes()) } + .joinToString(), + ) + enhancedTrackerInfo += "\n\n$missingSourcesInfo" + } + return listOf( Preference.PreferenceItem.SwitchPreference( pref = trackPreferences.autoUpdateTrack(), @@ -151,19 +169,15 @@ object SettingsTrackingScreen : SearchableSettings { ), Preference.PreferenceGroup( title = stringResource(R.string.enhanced_services), - preferenceItems = listOf(trackManager.komga, trackManager.kavita, trackManager.suwayomi) - .filter { service -> - val acceptedSources = service.getAcceptedSources() - sourceManager.getCatalogueSources().any { it::class.qualifiedName in acceptedSources } - } + preferenceItems = enhancedTrackers.first .map { service -> Preference.PreferenceItem.TrackingPreference( title = stringResource(service.nameRes()), service = service, - login = service::loginNoop, + login = { (service as EnhancedTrackService).loginNoop() }, logout = service::logout, ) - } + listOf(Preference.PreferenceItem.InfoPreference(stringResource(R.string.enhanced_tracking_info))), + } + listOf(Preference.PreferenceItem.InfoPreference(enhancedTrackerInfo)), ), ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt index 21d1ee3326..1331d45f54 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt @@ -22,6 +22,8 @@ interface EnhancedTrackService { */ fun getAcceptedSources(): List + fun loginNoop() + /** * match is similar to TrackService.search, but only return zero or one match. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/NoLoginTrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/NoLoginTrackService.kt deleted file mode 100644 index 7e5f02fc8f..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/NoLoginTrackService.kt +++ /dev/null @@ -1,8 +0,0 @@ -package eu.kanade.tachiyomi.data.track - -/** - * A TrackService that doesn't need explicit login. - */ -interface NoLoginTrackService { - fun loginNoop() -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt index f130fb2b33..c381ad2c4e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt @@ -8,14 +8,13 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.EnhancedTrackService -import eu.kanade.tachiyomi.data.track.NoLoginTrackService import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source import java.security.MessageDigest import eu.kanade.domain.track.model.Track as DomainTrack -class Kavita(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService, NoLoginTrackService { +class Kavita(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService { companion object { const val UNREAD = 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index 1c918acd76..c2a30d2ee6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt @@ -7,7 +7,6 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.EnhancedTrackService -import eu.kanade.tachiyomi.data.track.NoLoginTrackService import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source @@ -15,7 +14,7 @@ import okhttp3.Dns import okhttp3.OkHttpClient import eu.kanade.domain.track.model.Track as DomainTrack -class Komga(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService, NoLoginTrackService { +class Komga(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService { companion object { const val UNREAD = 1 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt index 111d43ade1..11f3738e5b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt @@ -6,14 +6,13 @@ import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.EnhancedTrackService -import eu.kanade.tachiyomi.data.track.NoLoginTrackService import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source import eu.kanade.domain.manga.model.Manga as DomainManga import eu.kanade.domain.track.model.Track as DomainTrack -class Suwayomi(private val context: Context, id: Long) : TrackService(id), NoLoginTrackService, EnhancedTrackService { +class Suwayomi(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService { val api by lazy { TachideskApi() } @StringRes diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index a9c4c26b2c..598ba1e5ed 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -451,6 +451,7 @@ Services One-way sync to update the chapter progress in tracking services. Set up tracking for individual entries from their tracking button. Enhanced services + Available but source not installed: %s Services that provide enhanced features for specific sources. Entries are automatically tracked when added to your library. Track