Refactor tracker name strings

This commit is contained in:
arkon 2021-01-24 16:06:28 -05:00
parent fea2e0a265
commit 0a54901eb0
18 changed files with 54 additions and 58 deletions

View File

@ -96,7 +96,8 @@ abstract class AbstractBackupRestore<T : AbstractBackupManager>(protected val co
errors.add(Date() to "${manga.title} - ${e.message}") errors.add(Date() to "${manga.title} - ${e.message}")
} }
} else { } 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)}")
} }
} }
} }

View File

@ -41,7 +41,7 @@ class FullBackupRestoreValidator : AbstractBackupRestoreValidator() {
val missingTrackers = trackers val missingTrackers = trackers
.mapNotNull { trackManager.getService(it) } .mapNotNull { trackManager.getService(it) }
.filter { !it.isLogged } .filter { !it.isLogged }
.map { it.name } .map { context.getString(it.nameRes()) }
.sorted() .sorted()
return Results(missingSources, missingTrackers) return Results(missingSources, missingTrackers)

View File

@ -45,7 +45,7 @@ class LegacyBackupRestoreValidator : AbstractBackupRestoreValidator() {
val missingTrackers = trackers val missingTrackers = trackers
.mapNotNull { trackManager.getService(it) } .mapNotNull { trackManager.getService(it) }
.filter { !it.isLogged } .filter { !it.isLogged }
.map { it.name } .map { context.getString(it.nameRes()) }
.sorted() .sorted()
return Results(missingSources, missingTrackers) return Results(missingSources, missingTrackers)

View File

@ -123,7 +123,7 @@ object PreferenceKeys {
const val filterCompleted = "pref_filter_library_completed" 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" const val librarySortingMode = "library_sorting_mode"

View File

@ -221,7 +221,7 @@ class PreferencesHelper(val context: Context) {
fun filterCompleted() = flowPrefs.getInt(Keys.filterCompleted, ExtendedNavigationView.Item.TriStateGroup.State.IGNORE.value) 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) fun librarySortingMode() = flowPrefs.getInt(Keys.librarySortingMode, 0)

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.track
import androidx.annotation.CallSuper import androidx.annotation.CallSuper
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
@ -19,7 +20,8 @@ abstract class TrackService(val id: Int) {
get() = networkService.client get() = networkService.client
// Name of the manga sync service to display // Name of the manga sync service to display
abstract val name: String @StringRes
abstract fun nameRes(): Int
// Application and remote support for reading dates // Application and remote support for reading dates
open val supportsReadingDates: Boolean = false open val supportsReadingDates: Boolean = false

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.anilist
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
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.TrackService 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" const val POINT_3 = "POINT_3"
} }
override val name = "AniList"
private val json: Json by injectLazy() private val json: Json by injectLazy()
private val interceptor by lazy { AnilistInterceptor(this, getPassword()) } 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 getLogo() = R.drawable.ic_tracker_anilist
override fun getLogoColor() = Color.rgb(18, 25, 35) override fun getLogoColor() = Color.rgb(18, 25, 35)

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.bangumi
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
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.TrackService 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) { class Bangumi(private val context: Context, id: Int) : TrackService(id) {
override val name = "Bangumi"
private val json: Json by injectLazy() private val json: Json by injectLazy()
private val interceptor by lazy { BangumiInterceptor(this) } private val interceptor by lazy { BangumiInterceptor(this) }
private val api by lazy { BangumiApi(client, interceptor) } private val api by lazy { BangumiApi(client, interceptor) }
@StringRes
override fun nameRes() = R.string.tracker_bangumi
override fun getScoreList(): List<String> { override fun getScoreList(): List<String> {
return IntRange(0, 10).map(Int::toString) return IntRange(0, 10).map(Int::toString)
} }

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.kitsu
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
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.TrackService 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 const val DEFAULT_SCORE = 0f
} }
override val name = "Kitsu" @StringRes
override fun nameRes() = R.string.tracker_kitsu
private val json: Json by injectLazy() private val json: Json by injectLazy()

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.myanimelist
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
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.TrackService 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 interceptor by lazy { MyAnimeListInterceptor(this, getPassword()) }
private val api by lazy { MyAnimeListApi(client, interceptor) } private val api by lazy { MyAnimeListApi(client, interceptor) }
override val name: String @StringRes
get() = "MyAnimeList" override fun nameRes() = R.string.tracker_myanimelist
override val supportsReadingDates: Boolean = true override val supportsReadingDates: Boolean = true

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.shikimori
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
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.TrackService 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 const val DEFAULT_SCORE = 0
} }
override val name = "Shikimori"
private val json: Json by injectLazy() private val json: Json by injectLazy()
private val interceptor by lazy { ShikimoriInterceptor(this) } private val interceptor by lazy { ShikimoriInterceptor(this) }
private val api by lazy { ShikimoriApi(client, interceptor) } private val api by lazy { ShikimoriApi(client, interceptor) }
@StringRes
override fun nameRes() = R.string.tracker_shikimori
override fun getScoreList(): List<String> { override fun getScoreList(): List<String> {
return IntRange(0, 10).map(Int::toString) return IntRange(0, 10).map(Int::toString)
} }

View File

@ -119,7 +119,7 @@ class LibraryPresenter(
val filterCompleted = preferences.filterCompleted().get() val filterCompleted = preferences.filterCompleted().get()
val loggedInServices = trackManager.services.filter { trackService -> trackService.isLogged } val loggedInServices = trackManager.services.filter { trackService -> trackService.isLogged }
.associate { trackService -> .associate { trackService ->
Pair(trackService.id, preferences.filterTracking(trackService.name).get()) Pair(trackService.id, preferences.filterTracking(trackService.id).get())
} }
val isNotAnyLoggedIn = !loggedInServices.values.any() val isNotAnyLoggedIn = !loggedInServices.values.any()

View File

@ -9,11 +9,6 @@ import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
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.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
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog 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 downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this)
private val unread = Item.TriStateGroup(R.string.action_filter_unread, this) private val unread = Item.TriStateGroup(R.string.action_filter_unread, this)
private val completed = Item.TriStateGroup(R.string.completed, 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 header = null
override val items: List<Item> override val items: List<Item>
@ -89,7 +84,7 @@ class LibrarySettingsSheet(
.also { services -> .also { services ->
val size = services.size val size = services.size
trackFilters = services.associate { service -> 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) val list: MutableList<Item> = mutableListOf(downloaded, unread, completed)
if (size > 1) list.add(Item.Header(R.string.action_filter_tracked)) 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 { private fun getServiceResId(service: TrackService, size: Int): Int {
return if (size > 1) getServiceResId(service) else R.string.action_filter_tracked return if (size > 1) service.nameRes() 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
}
} }
override fun initModels() { override fun initModels() {

View File

@ -71,7 +71,7 @@ class SettingsTrackingController :
return initThenAdd( return initThenAdd(
LoginPreference(context).apply { LoginPreference(context).apply {
key = Keys.trackUsername(service.id) key = Keys.trackUsername(service.id)
title = service.name titleRes = service.nameRes()
}, },
{ {
onClick { onClick {

View File

@ -15,18 +15,19 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
class TrackLoginDialog( class TrackLoginDialog(
@StringRes titleRes: Int? = null,
titleFormatArgs: Any? = null,
@StringRes usernameLabelRes: Int? = null, @StringRes usernameLabelRes: Int? = null,
bundle: Bundle? = 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) : this(service, null)
constructor(service: TrackService, @StringRes usernameLabelRes: Int?) : 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) { override fun setCredentialsOnView(view: View) {
binding?.username?.setText(service.getUsername()) binding?.username?.setText(service.getUsername())

View File

@ -14,13 +14,14 @@ import uy.kohesive.injekt.api.get
class TrackLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) { 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 { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val serviceName = activity!!.getString(service.nameRes())
return MaterialDialog(activity!!) 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) { .positiveButton(R.string.logout) {
service.logout() service.logout()
(targetController as? Listener)?.trackLogoutDialogClosed(service) (targetController as? Listener)?.trackLogoutDialogClosed(service)

View File

@ -10,14 +10,13 @@ import com.afollestad.materialdialogs.customview.customView
import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
import com.dd.processbutton.iml.ActionProcessButton import com.dd.processbutton.iml.ActionProcessButton
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
abstract class LoginDialogPreference( abstract class LoginDialogPreference(
@StringRes private val titleRes: Int? = null,
private val titleFormatArgs: Any? = null,
@StringRes private val usernameLabelRes: Int? = null, @StringRes private val usernameLabelRes: Int? = null,
bundle: Bundle? = null bundle: Bundle? = null
) : DialogController(bundle) { ) : DialogController(bundle) {
@ -29,14 +28,12 @@ abstract class LoginDialogPreference(
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
binding = PrefAccountLoginBinding.inflate(LayoutInflater.from(activity!!)) 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) .customView(view = binding!!.root)
.negativeButton(android.R.string.cancel) .negativeButton(android.R.string.cancel)
if (titleRes != null) {
dialog = dialog.title(text = activity!!.getString(titleRes, titleFormatArgs))
}
onViewCreated(dialog.view) onViewCreated(dialog.view)
return dialog return dialog
@ -64,6 +61,9 @@ abstract class LoginDialogPreference(
binding = null binding = null
} }
@StringRes
protected abstract fun getTitleName(): Int
protected abstract fun checkLogin() protected abstract fun checkLogin()
protected abstract fun setCredentialsOnView(view: View) protected abstract fun setCredentialsOnView(view: View)

View File

@ -562,6 +562,11 @@
<string name="no_chapters_error">No chapters found</string> <string name="no_chapters_error">No chapters found</string>
<!-- Tracking Screen --> <!-- 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> <string name="manga_tracking_tab">Tracking</string>
<plurals name="num_trackers"> <plurals name="num_trackers">
<item quantity="one">1 tracker</item> <item quantity="one">1 tracker</item>
@ -747,11 +752,4 @@
<string name="spen_previous_page">Previous page</string> <string name="spen_previous_page">Previous page</string>
<string name="spen_next_page">Next 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> </resources>