mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-24 01:48:24 +01:00
Remove repetition in enhanced tracker preference declarations
Also hides entries that aren't relevant (i.e. if you don't have the source installed).
This commit is contained in:
parent
0f45907144
commit
d8b528a4e0
@ -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))),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -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 -->
|
||||
|
Loading…
Reference in New Issue
Block a user