From 8bfc5f045084ff06ba36460fdee1fcd26fa10a93 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 18 Jul 2021 12:55:26 -0400 Subject: [PATCH] Put Komga tracker in separate group --- .../data/library/LibraryUpdateService.kt | 4 +- ...rackService.kt => EnhancedTrackService.kt} | 16 ++++++-- .../tachiyomi/data/track/komga/Komga.kt | 8 ++-- .../source/browse/BrowseSourcePresenter.kt | 4 +- .../tachiyomi/ui/manga/MangaController.kt | 4 +- .../tachiyomi/ui/manga/MangaPresenter.kt | 6 +-- .../tachiyomi/ui/manga/track/TrackSheet.kt | 4 +- .../ui/setting/SettingsTrackingController.kt | 38 ++++++++++++------- .../util/preference/PreferenceDSL.kt | 5 +-- app/src/main/res/values/strings.xml | 4 +- 10 files changed, 56 insertions(+), 37 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/data/track/{UnattendedTrackService.kt => EnhancedTrackService.kt} (50%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 5c0e191ba6..a6f9c410cc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -20,9 +20,9 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateRanker.rankingScheme import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper +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.UnattendedTrackService import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.toSChapter @@ -489,7 +489,7 @@ class LibraryUpdateService( val updatedTrack = service.refresh(track) db.insertTrack(updatedTrack).executeAsBlocking() - if (service is UnattendedTrackService) { + if (service is EnhancedTrackService) { syncChaptersWithTrackServiceTwoWay(db, db.getChapters(manga).executeAsBlocking(), track, service) } } catch (e: Throwable) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/UnattendedTrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt similarity index 50% rename from app/src/main/java/eu/kanade/tachiyomi/data/track/UnattendedTrackService.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt index fbbed65eaf..7539655834 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/UnattendedTrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/EnhancedTrackService.kt @@ -1,18 +1,26 @@ package eu.kanade.tachiyomi.data.track import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.track.komga.Komga import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source /** - * An Unattended Track Service will never prompt the user to match a manga with the remote. - * It is expected that such Track Sercice can only work with specific sources and unique IDs. + * An Enhanced Track Service will never prompt the user to match a manga with the remote. + * It is expected that such Track Service can only work with specific sources and unique IDs. */ -interface UnattendedTrackService { +interface EnhancedTrackService { /** * This TrackService will only work with the sources that are accepted by this filter function. */ - fun accept(source: Source): Boolean + fun accept(source: Source): Boolean { + return source::class.qualifiedName in getAcceptedSources() + } + + /** + * Fully qualified source classes that this track service is compatible with. + */ + fun getAcceptedSources(): List /** * 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/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index 2d3fa0912f..efab5bbcc1 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 @@ -6,22 +6,20 @@ import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga 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.UnattendedTrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.source.Source import okhttp3.Dns import okhttp3.OkHttpClient -class Komga(private val context: Context, id: Int) : TrackService(id), UnattendedTrackService, NoLoginTrackService { +class Komga(private val context: Context, id: Int) : TrackService(id), EnhancedTrackService, NoLoginTrackService { companion object { const val UNREAD = 1 const val READING = 2 const val COMPLETED = 3 - - const val ACCEPTED_SOURCE = "eu.kanade.tachiyomi.extension.all.komga.Komga" } override val client: OkHttpClient = @@ -94,7 +92,7 @@ class Komga(private val context: Context, id: Int) : TrackService(id), Unattende saveCredentials("user", "pass") } - override fun accept(source: Source): Boolean = source::class.qualifiedName == ACCEPTED_SOURCE + override fun getAcceptedSources() = listOf("eu.kanade.tachiyomi.extension.all.komga.Komga") override suspend fun match(manga: Manga): TrackSearch? = try { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index d48b634183..10ffa89468 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -9,9 +9,9 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.preference.PreferencesHelper +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.UnattendedTrackService import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Filter @@ -277,7 +277,7 @@ open class BrowseSourcePresenter( private fun autoAddTrack(manga: Manga) { loggedServices - .filterIsInstance() + .filterIsInstance() .filter { it.accept(source) } .forEach { service -> launchIO { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 9c858713c4..8abb8edc22 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -36,8 +36,8 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackService -import eu.kanade.tachiyomi.data.track.UnattendedTrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.databinding.MangaControllerBinding import eu.kanade.tachiyomi.source.LocalSource @@ -538,7 +538,7 @@ class MangaController : if (source != null && preferences.autoAddTrack()) { presenter.trackList .map { it.service } - .filterIsInstance() + .filterIsInstance() .filter { it.accept(source!!) } .forEach { service -> launchIO { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 5d1112eb99..4a873a7cea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -15,9 +15,9 @@ import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.preference.PreferencesHelper +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.UnattendedTrackService import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.model.toSChapter @@ -747,7 +747,7 @@ class MangaPresenter( val track = it.service.refresh(it.track!!) db.insertTrack(track).executeAsBlocking() - if (it.service is UnattendedTrackService) { + if (it.service is EnhancedTrackService) { syncChaptersWithTrackServiceTwoWay(db, allChapters, track, it.service) } } @@ -783,7 +783,7 @@ class MangaPresenter( service.bind(item, hasReadChapters) db.insertTrack(item).executeAsBlocking() - if (service is UnattendedTrackService) { + if (service is EnhancedTrackService) { syncChaptersWithTrackServiceTwoWay(db, allChapters, item, service) } } catch (e: Throwable) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt index 33506fb91c..b64086ab37 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt @@ -12,7 +12,7 @@ import com.google.android.material.datepicker.DateValidatorPointForward import com.google.android.material.datepicker.MaterialDatePicker import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.track.UnattendedTrackService +import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.databinding.TrackControllerBinding import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.base.controller.openInBrowser @@ -80,7 +80,7 @@ class TrackSheet( override fun onSetClick(position: Int) { val item = adapter.getItem(position) ?: return - if (item.service is UnattendedTrackService) { + if (item.service is EnhancedTrackService) { if (item.track != null) { controller.presenter.unregisterTracking(item.service) return diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt index dbf72ef6ef..8d76a18498 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt @@ -4,8 +4,10 @@ import android.app.Activity import android.view.Menu import android.view.MenuInflater import android.view.MenuItem +import androidx.preference.PreferenceGroup import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.NoLoginTrackService import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService @@ -13,11 +15,13 @@ import eu.kanade.tachiyomi.data.track.anilist.AnilistApi import eu.kanade.tachiyomi.data.track.bangumi.BangumiApi import eu.kanade.tachiyomi.data.track.myanimelist.MyAnimeListApi import eu.kanade.tachiyomi.data.track.shikimori.ShikimoriApi +import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.setting.track.TrackLoginDialog import eu.kanade.tachiyomi.ui.setting.track.TrackLogoutDialog +import eu.kanade.tachiyomi.util.preference.add import eu.kanade.tachiyomi.util.preference.defaultValue +import eu.kanade.tachiyomi.util.preference.iconRes import eu.kanade.tachiyomi.util.preference.infoPreference -import eu.kanade.tachiyomi.util.preference.initThenAdd import eu.kanade.tachiyomi.util.preference.onClick import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference @@ -33,6 +37,7 @@ class SettingsTrackingController : TrackLogoutDialog.Listener { private val trackManager: TrackManager by injectLazy() + private val sourceManager: SourceManager by injectLazy() override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_tracking @@ -42,11 +47,7 @@ class SettingsTrackingController : titleRes = R.string.pref_auto_update_manga_sync defaultValue = true } - switchPreference { - key = Keys.autoAddTrack - titleRes = R.string.pref_auto_add_track - defaultValue = true - } + preferenceCategory { titleRes = R.string.services @@ -67,26 +68,37 @@ class SettingsTrackingController : trackPreference(trackManager.bangumi) { activity?.openInBrowser(BangumiApi.authUrl(), trackManager.bangumi.getLogoColor()) } + + infoPreference(R.string.tracking_info) + } + + preferenceCategory { + titleRes = R.string.enhanced_services + + switchPreference { + key = Keys.autoAddTrack + titleRes = R.string.pref_auto_add_track + defaultValue = true + } + trackPreference(trackManager.komga) { trackManager.komga.loginNoop() updatePreference(trackManager.komga.id) } - } - preferenceCategory { - infoPreference(R.string.tracking_info) + + infoPreference(R.string.enhanced_tracking_info) } } - private inline fun PreferenceScreen.trackPreference( + private inline fun PreferenceGroup.trackPreference( service: TrackService, crossinline login: () -> Unit ): LoginPreference { - return initThenAdd( + return add( LoginPreference(context).apply { key = Keys.trackUsername(service.id) titleRes = service.nameRes() - }, - { + iconRes = service.getLogo() onClick { if (service.isLogged) { if (service is NoLoginTrackService) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt index 03a74b48dc..efdb8f535d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt @@ -34,9 +34,8 @@ inline fun PreferenceGroup.preference(block: (@DSL Preference).() -> Unit): Pref } inline fun PreferenceGroup.infoPreference(@StringRes infoRes: Int): Preference { - return initThenAdd( - Preference(context), - { + return add( + Preference(context).apply { iconRes = R.drawable.ic_info_24dp iconTint = context.getResourceColor(android.R.attr.textColorHint) summaryRes = infoRes diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index db3de167eb..ba8e570278 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -381,9 +381,11 @@ Tracking guide Update chapter progress after reading - Track silently when adding manga to library Services One-way sync to update the chapter progress in tracking services. Set up tracking for individual manga entries from their tracking button. + Enhanced services + Automatically track manga when added to library + Services that provide enhanced features for specific sources. Check for extension updates