Browse Source

Refactor tracker name strings

arkon 4 years ago
parent
commit
0a54901eb0
18 changed files with 54 additions and 58 deletions
  1. 2 1
      app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt
  2. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestoreValidator.kt
  3. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestoreValidator.kt
  4. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt
  5. 1 1
      app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt
  6. 3 1
      app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt
  7. 4 2
      app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt
  8. 4 2
      app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt
  9. 3 1
      app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt
  10. 3 2
      app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt
  11. 4 2
      app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt
  12. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
  13. 3 19
      app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt
  14. 1 1
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt
  15. 6 5
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt
  16. 4 3
      app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLogoutDialog.kt
  17. 7 7
      app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt
  18. 5 7
      app/src/main/res/values/strings.xml

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt

@@ -96,7 +96,8 @@ abstract class AbstractBackupRestore<T : AbstractBackupManager>(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)}")
             }
         }
     }

+ 1 - 1
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)

+ 1 - 1
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)

+ 1 - 1
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"
 

+ 1 - 1
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)
 

+ 3 - 1
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

+ 4 - 2
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)

+ 4 - 2
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<String> {
         return IntRange(0, 10).map(Int::toString)
     }

+ 3 - 1
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()
 

+ 3 - 2
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
 

+ 4 - 2
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<String> {
         return IntRange(0, 10).map(Int::toString)
     }

+ 1 - 1
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()
 

+ 3 - 19
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<String, Item.TriStateGroup>
+            private val trackFilters: Map<Int, Item.TriStateGroup>
 
             override val header = null
             override val items: List<Item>
@@ -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<Item> = 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() {

+ 1 - 1
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 {

+ 6 - 5
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<TrackManager>().getService(args.getInt("key"))!!
+    private val service = Injekt.get<TrackManager>().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())

+ 4 - 3
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<TrackManager>().getService(args.getInt("key"))!!
+    private val service = Injekt.get<TrackManager>().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)

+ 7 - 7
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)

+ 5 - 7
app/src/main/res/values/strings.xml

@@ -562,6 +562,11 @@
     <string name="no_chapters_error">No chapters found</string>
 
     <!-- Tracking Screen -->
+    <string name="tracker_anilist" translatable="false">AniList</string>
+    <string name="tracker_myanimelist" translatable="false">MyAnimeList</string>
+    <string name="tracker_kitsu" translatable="false">Kitsu</string>
+    <string name="tracker_bangumi" translatable="false">Bangumi</string>
+    <string name="tracker_shikimori" translatable="false">Shikimori</string>
     <string name="manga_tracking_tab">Tracking</string>
     <plurals name="num_trackers">
         <item quantity="one">1 tracker</item>
@@ -747,11 +752,4 @@
     <string name="spen_previous_page">Previous page</string>
     <string name="spen_next_page">Next page</string>
 
-    <!-- Tracker names -->
-    <string name="anilist" translatable="false">AniList</string>
-    <string name="my_anime_list" translatable="false">MyAnimeList</string>
-    <string name="kitsu" translatable="false">Kitsu</string>
-    <string name="bangumi" translatable="false">Bangumi</string>
-    <string name="shikimori" translatable="false">Shikimori</string>
-
 </resources>