Show available but not installed enhanced trackers

Closes #8859
This commit is contained in:
arkon 2023-01-08 10:37:30 -05:00
parent 5d9753d6a7
commit 48cab708ce
7 changed files with 27 additions and 21 deletions

View File

@ -44,6 +44,7 @@ import androidx.compose.ui.unit.dp
import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.domain.track.service.TrackPreferences
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.tachiyomi.R 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.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.data.track.anilist.AnilistApi 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( return listOf(
Preference.PreferenceItem.SwitchPreference( Preference.PreferenceItem.SwitchPreference(
pref = trackPreferences.autoUpdateTrack(), pref = trackPreferences.autoUpdateTrack(),
@ -151,19 +169,15 @@ object SettingsTrackingScreen : SearchableSettings {
), ),
Preference.PreferenceGroup( Preference.PreferenceGroup(
title = stringResource(R.string.enhanced_services), title = stringResource(R.string.enhanced_services),
preferenceItems = listOf(trackManager.komga, trackManager.kavita, trackManager.suwayomi) preferenceItems = enhancedTrackers.first
.filter { service ->
val acceptedSources = service.getAcceptedSources()
sourceManager.getCatalogueSources().any { it::class.qualifiedName in acceptedSources }
}
.map { service -> .map { service ->
Preference.PreferenceItem.TrackingPreference( Preference.PreferenceItem.TrackingPreference(
title = stringResource(service.nameRes()), title = stringResource(service.nameRes()),
service = service, service = service,
login = service::loginNoop, login = { (service as EnhancedTrackService).loginNoop() },
logout = service::logout, logout = service::logout,
) )
} + listOf(Preference.PreferenceItem.InfoPreference(stringResource(R.string.enhanced_tracking_info))), } + listOf(Preference.PreferenceItem.InfoPreference(enhancedTrackerInfo)),
), ),
) )
} }

View File

@ -22,6 +22,8 @@ interface EnhancedTrackService {
*/ */
fun getAcceptedSources(): List<String> fun getAcceptedSources(): List<String>
fun loginNoop()
/** /**
* match is similar to TrackService.search, but only return zero or one match. * match is similar to TrackService.search, but only return zero or one match.
*/ */

View File

@ -1,8 +0,0 @@
package eu.kanade.tachiyomi.data.track
/**
* A TrackService that doesn't need explicit login.
*/
interface NoLoginTrackService {
fun loginNoop()
}

View File

@ -8,14 +8,13 @@ import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.EnhancedTrackService 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.TrackService
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import java.security.MessageDigest import java.security.MessageDigest
import eu.kanade.domain.track.model.Track as DomainTrack 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 { companion object {
const val UNREAD = 1 const val UNREAD = 1

View File

@ -7,7 +7,6 @@ import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.EnhancedTrackService 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.TrackService
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
@ -15,7 +14,7 @@ import okhttp3.Dns
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import eu.kanade.domain.track.model.Track as DomainTrack 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 { companion object {
const val UNREAD = 1 const val UNREAD = 1

View File

@ -6,14 +6,13 @@ import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.EnhancedTrackService 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.TrackService
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.domain.manga.model.Manga as DomainManga import eu.kanade.domain.manga.model.Manga as DomainManga
import eu.kanade.domain.track.model.Track as DomainTrack 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() } val api by lazy { TachideskApi() }
@StringRes @StringRes

View File

@ -451,6 +451,7 @@
<string name="services">Services</string> <string name="services">Services</string>
<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="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_services">Enhanced services</string>
<string name="enhanced_services_not_installed">Available but source not installed: %s</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_info">Services that provide enhanced features for specific sources. Entries are automatically tracked when added to your library.</string>
<string name="action_track">Track</string> <string name="action_track">Track</string>