diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt index 0bc284cb7..31d3b6ccc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt @@ -96,7 +96,8 @@ abstract class AbstractBackupRestore(protected val co errors.add(Date() to "${manga.title} - ${e.message}") } } else { - errors.add(Date() to "${manga.title} - ${context.getString(R.string.tracker_not_logged_in, service?.name)}") + val serviceName = service?.nameRes()?.let { context.getString(it) } + errors.add(Date() to "${manga.title} - ${context.getString(R.string.tracker_not_logged_in, serviceName)}") } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt index e482196ba..4cb30234c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt @@ -41,7 +41,7 @@ class FullBackupRestoreValidator : AbstractBackupRestoreValidator() { val missingTrackers = trackers .mapNotNull { trackManager.getService(it) } .filter { !it.isLogged } - .map { it.name } + .map { context.getString(it.nameRes()) } .sorted() return Results(missingSources, missingTrackers) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestoreValidator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestoreValidator.kt index f1b7cbf12..ab757059c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestoreValidator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestoreValidator.kt @@ -45,7 +45,7 @@ class LegacyBackupRestoreValidator : AbstractBackupRestoreValidator() { val missingTrackers = trackers .mapNotNull { trackManager.getService(it) } .filter { !it.isLogged } - .map { it.name } + .map { context.getString(it.nameRes()) } .sorted() return Results(missingSources, missingTrackers) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 7169d5e23..3d02a8ac7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -123,7 +123,7 @@ object PreferenceKeys { const val filterCompleted = "pref_filter_library_completed" - const val filterTracking = "pref_filter_library_tracking" + const val filterTracked = "pref_filter_library_tracked" const val librarySortingMode = "library_sorting_mode" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index d5f2a4662..27e65dc1a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -221,7 +221,7 @@ class PreferencesHelper(val context: Context) { fun filterCompleted() = flowPrefs.getInt(Keys.filterCompleted, ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) - fun filterTracking(name: String) = flowPrefs.getInt("${Keys.filterTracking}_$name", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) + fun filterTracking(name: Int) = flowPrefs.getInt("${Keys.filterTracked}_$name", ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) fun librarySortingMode() = flowPrefs.getInt(Keys.librarySortingMode, 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index 884fdf4c0..972685909 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.track import androidx.annotation.CallSuper import androidx.annotation.ColorInt import androidx.annotation.DrawableRes +import androidx.annotation.StringRes import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.model.TrackSearch @@ -19,7 +20,8 @@ abstract class TrackService(val id: Int) { get() = networkService.client // Name of the manga sync service to display - abstract val name: String + @StringRes + abstract fun nameRes(): Int // Application and remote support for reading dates open val supportsReadingDates: Boolean = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt index 6cdc17889..aecf53888 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.anilist import android.content.Context import android.graphics.Color +import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackService @@ -31,8 +32,6 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { const val POINT_3 = "POINT_3" } - override val name = "AniList" - private val json: Json by injectLazy() private val interceptor by lazy { AnilistInterceptor(this, getPassword()) } @@ -51,6 +50,9 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) { } } + @StringRes + override fun nameRes() = R.string.tracker_anilist + override fun getLogo() = R.drawable.ic_tracker_anilist override fun getLogoColor() = Color.rgb(18, 25, 35) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt index ff54e6eab..a65af7702 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.bangumi import android.content.Context import android.graphics.Color +import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackService @@ -13,14 +14,15 @@ import uy.kohesive.injekt.injectLazy class Bangumi(private val context: Context, id: Int) : TrackService(id) { - override val name = "Bangumi" - private val json: Json by injectLazy() private val interceptor by lazy { BangumiInterceptor(this) } private val api by lazy { BangumiApi(client, interceptor) } + @StringRes + override fun nameRes() = R.string.tracker_bangumi + override fun getScoreList(): List { return IntRange(0, 10).map(Int::toString) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index 7cd4473df..66edfce25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.kitsu import android.content.Context import android.graphics.Color +import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackService @@ -25,7 +26,8 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { const val DEFAULT_SCORE = 0f } - override val name = "Kitsu" + @StringRes + override fun nameRes() = R.string.tracker_kitsu private val json: Json by injectLazy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt index bae8eda31..cfbc25247 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.myanimelist import android.content.Context import android.graphics.Color +import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackService @@ -30,8 +31,8 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { private val interceptor by lazy { MyAnimeListInterceptor(this, getPassword()) } private val api by lazy { MyAnimeListApi(client, interceptor) } - override val name: String - get() = "MyAnimeList" + @StringRes + override fun nameRes() = R.string.tracker_myanimelist override val supportsReadingDates: Boolean = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt index eebe0eb46..aec1b462b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.shikimori import android.content.Context import android.graphics.Color +import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackService @@ -25,14 +26,15 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) { const val DEFAULT_SCORE = 0 } - override val name = "Shikimori" - private val json: Json by injectLazy() private val interceptor by lazy { ShikimoriInterceptor(this) } private val api by lazy { ShikimoriApi(client, interceptor) } + @StringRes + override fun nameRes() = R.string.tracker_shikimori + override fun getScoreList(): List { return IntRange(0, 10).map(Int::toString) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index d8707dee7..0f678b8e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -119,7 +119,7 @@ class LibraryPresenter( val filterCompleted = preferences.filterCompleted().get() val loggedInServices = trackManager.services.filter { trackService -> trackService.isLogged } .associate { trackService -> - Pair(trackService.id, preferences.filterTracking(trackService.name).get()) + Pair(trackService.id, preferences.filterTracking(trackService.id).get()) } val isNotAnyLoggedIn = !loggedInServices.values.any() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 0d99247f9..9a37d73a8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -9,11 +9,6 @@ import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService -import eu.kanade.tachiyomi.data.track.anilist.Anilist -import eu.kanade.tachiyomi.data.track.bangumi.Bangumi -import eu.kanade.tachiyomi.data.track.kitsu.Kitsu -import eu.kanade.tachiyomi.data.track.myanimelist.MyAnimeList -import eu.kanade.tachiyomi.data.track.shikimori.Shikimori import eu.kanade.tachiyomi.widget.ExtendedNavigationView import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog @@ -78,7 +73,7 @@ class LibrarySettingsSheet( private val downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this) private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) private val completed = Item.TriStateGroup(R.string.completed, this) - private val trackFilters: Map + private val trackFilters: Map override val header = null override val items: List @@ -89,7 +84,7 @@ class LibrarySettingsSheet( .also { services -> val size = services.size trackFilters = services.associate { service -> - Pair(service.name, Item.TriStateGroup(getServiceResId(service, size), this)) + Pair(service.id, Item.TriStateGroup(getServiceResId(service, size), this)) } val list: MutableList = mutableListOf(downloaded, unread, completed) if (size > 1) list.add(Item.Header(R.string.action_filter_tracked)) @@ -99,18 +94,7 @@ class LibrarySettingsSheet( } private fun getServiceResId(service: TrackService, size: Int): Int { - return if (size > 1) getServiceResId(service) else R.string.action_filter_tracked - } - - private fun getServiceResId(service: TrackService): Int { - return when (service) { - is Anilist -> R.string.anilist - is MyAnimeList -> R.string.my_anime_list - is Kitsu -> R.string.kitsu - is Bangumi -> R.string.bangumi - is Shikimori -> R.string.shikimori - else -> R.string.unknown - } + return if (size > 1) service.nameRes() else R.string.action_filter_tracked } override fun initModels() { 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 5600c9bf6..950d2dc60 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 @@ -71,7 +71,7 @@ class SettingsTrackingController : return initThenAdd( LoginPreference(context).apply { key = Keys.trackUsername(service.id) - title = service.name + titleRes = service.nameRes() }, { onClick { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt index d59b3510d..62e287f94 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt @@ -15,18 +15,19 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get class TrackLoginDialog( - @StringRes titleRes: Int? = null, - titleFormatArgs: Any? = null, @StringRes usernameLabelRes: Int? = null, bundle: Bundle? = null -) : LoginDialogPreference(titleRes, titleFormatArgs, usernameLabelRes, bundle) { +) : LoginDialogPreference(usernameLabelRes, bundle) { - private val service = Injekt.get().getService(args.getInt("key"))!! + private val service = Injekt.get().getService(args.getInt("serviceId"))!! constructor(service: TrackService) : this(service, null) constructor(service: TrackService, @StringRes usernameLabelRes: Int?) : - this(R.string.login_title, service.name, usernameLabelRes, bundleOf("key" to service.id)) + this(usernameLabelRes, bundleOf("serviceId" to service.id)) + + @StringRes + override fun getTitleName(): Int = service.nameRes() override fun setCredentialsOnView(view: View) { binding?.username?.setText(service.getUsername()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt index 187069bd9..308dbd08d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt @@ -14,13 +14,14 @@ import uy.kohesive.injekt.api.get class TrackLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) { - private val service = Injekt.get().getService(args.getInt("key"))!! + private val service = Injekt.get().getService(args.getInt("serviceId"))!! - constructor(service: TrackService) : this(bundleOf("key" to service.id)) + constructor(service: TrackService) : this(bundleOf("serviceId" to service.id)) override fun onCreateDialog(savedViewState: Bundle?): Dialog { + val serviceName = activity!!.getString(service.nameRes()) return MaterialDialog(activity!!) - .title(text = activity!!.getString(R.string.logout_title, service.name)) + .title(text = activity!!.getString(R.string.logout_title, serviceName)) .positiveButton(R.string.logout) { service.logout() (targetController as? Listener)?.trackLogoutDialogClosed(service) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt index ca6f8dee9..68b223de8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt @@ -10,14 +10,13 @@ import com.afollestad.materialdialogs.customview.customView import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.dd.processbutton.iml.ActionProcessButton +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding import eu.kanade.tachiyomi.ui.base.controller.DialogController import uy.kohesive.injekt.injectLazy abstract class LoginDialogPreference( - @StringRes private val titleRes: Int? = null, - private val titleFormatArgs: Any? = null, @StringRes private val usernameLabelRes: Int? = null, bundle: Bundle? = null ) : DialogController(bundle) { @@ -29,14 +28,12 @@ abstract class LoginDialogPreference( override fun onCreateDialog(savedViewState: Bundle?): Dialog { binding = PrefAccountLoginBinding.inflate(LayoutInflater.from(activity!!)) - var dialog = MaterialDialog(activity!!) + val titleName = activity!!.getString(getTitleName()) + val dialog = MaterialDialog(activity!!) + .title(text = activity!!.getString(R.string.login_title, titleName)) .customView(view = binding!!.root) .negativeButton(android.R.string.cancel) - if (titleRes != null) { - dialog = dialog.title(text = activity!!.getString(titleRes, titleFormatArgs)) - } - onViewCreated(dialog.view) return dialog @@ -64,6 +61,9 @@ abstract class LoginDialogPreference( binding = null } + @StringRes + protected abstract fun getTitleName(): Int + protected abstract fun checkLogin() protected abstract fun setCredentialsOnView(view: View) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c6e125668..dbe08b74d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -562,6 +562,11 @@ No chapters found + AniList + MyAnimeList + Kitsu + Bangumi + Shikimori Tracking 1 tracker @@ -747,11 +752,4 @@ Previous page Next page - - AniList - MyAnimeList - Kitsu - Bangumi - Shikimori -