فهرست منبع

Remove repetition in enhanced tracker preference declarations

Also hides entries that aren't relevant (i.e. if you don't have the source installed).
arkon 2 سال پیش
والد
کامیت
d8b528a4e0

+ 14 - 56
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<TrackPreferences>() }
         val trackManager = remember { Injekt.get<TrackManager>() }
+        val sourceManager = remember { Injekt.get<SourceManager>() }
 
         var dialog by remember { mutableStateOf<Any?>(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<SourceManager>()
-                            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<SourceManager>()
-                            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<SourceManager>()
-                            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))),
             ),
         )
     }

+ 0 - 1
i18n/src/main/res/values/strings.xml

@@ -452,7 +452,6 @@
     <string name="tracking_info">One-way sync to update the chapter progress in tracking services. Set up tracking for individual entries from their tracking button.</string>
     <string name="enhanced_services">Enhanced services</string>
     <string name="enhanced_tracking_info">Services that provide enhanced features for specific sources. Entries are automatically tracked when added to your library.</string>
-    <string name="enhanced_tracking_warning">This tracker is only compatible with the %1$s source.</string>
     <string name="action_track">Track</string>
 
       <!-- Browse section -->