mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-14 03:55:06 +01:00
Refactor tracker name strings
This commit is contained in:
parent
fea2e0a265
commit
0a54901eb0
@ -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)}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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,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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -71,7 +71,7 @@ class SettingsTrackingController :
|
||||
return initThenAdd(
|
||||
LoginPreference(context).apply {
|
||||
key = Keys.trackUsername(service.id)
|
||||
title = service.name
|
||||
titleRes = service.nameRes()
|
||||
},
|
||||
{
|
||||
onClick {
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user