From d8b528a4e0d1da00c653c0123ee01848db4b1b87 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 7 Jan 2023 14:41:27 -0500 Subject: [PATCH] Remove repetition in enhanced tracker preference declarations Also hides entries that aren't relevant (i.e. if you don't have the source installed). --- .../settings/screen/SettingsTrackingScreen.kt | 70 ++++--------------- i18n/src/main/res/values/strings.xml | 1 - 2 files changed, 14 insertions(+), 57 deletions(-) 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 c7c808fbe..b81ea6857 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 @@ -1,7 +1,6 @@ package eu.kanade.presentation.more.settings.screen import android.content.Context -import android.widget.Toast import androidx.annotation.StringRes import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -82,6 +81,7 @@ object SettingsTrackingScreen : SearchableSettings { val context = LocalContext.current val trackPreferences = remember { Injekt.get() } val trackManager = remember { Injekt.get() } + val sourceManager = remember { Injekt.get() } var dialog by remember { mutableStateOf(null) } dialog?.run { @@ -151,61 +151,19 @@ object SettingsTrackingScreen : SearchableSettings { ), Preference.PreferenceGroup( title = stringResource(R.string.enhanced_services), - preferenceItems = listOf( - Preference.PreferenceItem.TrackingPreference( - title = stringResource(trackManager.komga.nameRes()), - service = trackManager.komga, - login = { - val sourceManager = Injekt.get() - val acceptedSources = trackManager.komga.getAcceptedSources() - val hasValidSourceInstalled = sourceManager.getCatalogueSources() - .any { it::class.qualifiedName in acceptedSources } - - if (hasValidSourceInstalled) { - trackManager.komga.loginNoop() - } else { - context.toast(context.getString(R.string.enhanced_tracking_warning, context.getString(trackManager.komga.nameRes())), Toast.LENGTH_LONG) - } - }, - logout = trackManager.komga::logout, - ), - Preference.PreferenceItem.TrackingPreference( - title = stringResource(trackManager.kavita.nameRes()), - service = trackManager.kavita, - login = { - val sourceManager = Injekt.get() - val acceptedSources = trackManager.kavita.getAcceptedSources() - val hasValidSourceInstalled = sourceManager.getCatalogueSources() - .any { it::class.qualifiedName in acceptedSources } - - if (hasValidSourceInstalled) { - trackManager.kavita.loginNoop() - } else { - context.toast(context.getString(R.string.enhanced_tracking_warning, context.getString(trackManager.kavita.nameRes())), Toast.LENGTH_LONG) - } - }, - logout = trackManager.kavita::logout, - ), - - Preference.PreferenceItem.TrackingPreference( - title = stringResource(trackManager.suwayomi.nameRes()), - service = trackManager.suwayomi, - login = { - val sourceManager = Injekt.get() - val acceptedSources = trackManager.suwayomi.getAcceptedSources() - val hasValidSourceInstalled = sourceManager.getCatalogueSources() - .any { it::class.qualifiedName in acceptedSources } - - if (hasValidSourceInstalled) { - trackManager.suwayomi.loginNoop() - } else { - context.toast(context.getString(R.string.enhanced_tracking_warning, context.getString(trackManager.suwayomi.nameRes())), Toast.LENGTH_LONG) - } - }, - logout = trackManager.suwayomi::logout, - ), - Preference.PreferenceItem.InfoPreference(stringResource(R.string.enhanced_tracking_info)), - ), + preferenceItems = listOf(trackManager.komga, trackManager.kavita, trackManager.suwayomi) + .filter { service -> + val acceptedSources = service.getAcceptedSources() + sourceManager.getCatalogueSources().any { it::class.qualifiedName in acceptedSources } + } + .map { service -> + Preference.PreferenceItem.TrackingPreference( + title = stringResource(service.nameRes()), + service = service, + login = service::loginNoop, + logout = service::logout, + ) + } + listOf(Preference.PreferenceItem.InfoPreference(stringResource(R.string.enhanced_tracking_info))), ), ) } diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index f9becf36c..a9c4c26b2 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -452,7 +452,6 @@ One-way sync to update the chapter progress in tracking services. Set up tracking for individual entries from their tracking button. Enhanced services Services that provide enhanced features for specific sources. Entries are automatically tracked when added to your library. - This tracker is only compatible with the %1$s source. Track