Split track preferences from PreferencesHelper (#8046)
This commit is contained in:
@@ -4,6 +4,7 @@ import androidx.annotation.CallSuper
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import eu.kanade.domain.track.service.TrackPreferences
|
||||
import eu.kanade.tachiyomi.data.database.models.Track
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
@@ -14,6 +15,7 @@ import uy.kohesive.injekt.injectLazy
|
||||
abstract class TrackService(val id: Long) {
|
||||
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
val trackPreferences: TrackPreferences by injectLazy()
|
||||
val networkService: NetworkHelper by injectLazy()
|
||||
|
||||
open val client: OkHttpClient
|
||||
@@ -62,18 +64,18 @@ abstract class TrackService(val id: Long) {
|
||||
|
||||
@CallSuper
|
||||
open fun logout() {
|
||||
preferences.setTrackCredentials(this, "", "")
|
||||
trackPreferences.setTrackCredentials(this, "", "")
|
||||
}
|
||||
|
||||
open val isLogged: Boolean
|
||||
get() = getUsername().isNotEmpty() &&
|
||||
getPassword().isNotEmpty()
|
||||
|
||||
fun getUsername() = preferences.trackUsername(this).get()
|
||||
fun getUsername() = trackPreferences.trackUsername(this).get()
|
||||
|
||||
fun getPassword() = preferences.trackPassword(this).get()
|
||||
fun getPassword() = trackPreferences.trackPassword(this).get()
|
||||
|
||||
fun saveCredentials(username: String, password: String) {
|
||||
preferences.setTrackCredentials(this, username, password)
|
||||
trackPreferences.setTrackCredentials(this, username, password)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class Anilist(private val context: Context, id: Long) : TrackService(id) {
|
||||
|
||||
override val supportsReadingDates: Boolean = true
|
||||
|
||||
private val scorePreference = preferences.anilistScoreType()
|
||||
private val scorePreference = trackPreferences.anilistScoreType()
|
||||
|
||||
init {
|
||||
// If the preference is an int from APIv1, logout user to force using APIv2
|
||||
@@ -211,17 +211,17 @@ class Anilist(private val context: Context, id: Long) : TrackService(id) {
|
||||
|
||||
override fun logout() {
|
||||
super.logout()
|
||||
preferences.trackToken(this).delete()
|
||||
trackPreferences.trackToken(this).delete()
|
||||
interceptor.setAuth(null)
|
||||
}
|
||||
|
||||
fun saveOAuth(oAuth: OAuth?) {
|
||||
preferences.trackToken(this).set(json.encodeToString(oAuth))
|
||||
trackPreferences.trackToken(this).set(json.encodeToString(oAuth))
|
||||
}
|
||||
|
||||
fun loadOAuth(): OAuth? {
|
||||
return try {
|
||||
json.decodeFromString<OAuth>(preferences.trackToken(this).get())
|
||||
json.decodeFromString<OAuth>(trackPreferences.trackToken(this).get())
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package eu.kanade.tachiyomi.data.track.anilist
|
||||
|
||||
import eu.kanade.domain.track.service.TrackPreferences
|
||||
import eu.kanade.tachiyomi.data.database.models.Track
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
@@ -82,7 +82,7 @@ fun Track.toAnilistStatus() = when (status) {
|
||||
else -> throw NotImplementedError("Unknown status: $status")
|
||||
}
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
private val preferences: TrackPreferences by injectLazy()
|
||||
|
||||
fun Track.toAnilistScore(): String = when (preferences.anilistScoreType().get()) {
|
||||
// 10 point
|
||||
|
||||
@@ -124,12 +124,12 @@ class Bangumi(private val context: Context, id: Long) : TrackService(id) {
|
||||
}
|
||||
|
||||
fun saveToken(oauth: OAuth?) {
|
||||
preferences.trackToken(this).set(json.encodeToString(oauth))
|
||||
trackPreferences.trackToken(this).set(json.encodeToString(oauth))
|
||||
}
|
||||
|
||||
fun restoreToken(): OAuth? {
|
||||
return try {
|
||||
json.decodeFromString<OAuth>(preferences.trackToken(this).get())
|
||||
json.decodeFromString<OAuth>(trackPreferences.trackToken(this).get())
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class Bangumi(private val context: Context, id: Long) : TrackService(id) {
|
||||
|
||||
override fun logout() {
|
||||
super.logout()
|
||||
preferences.trackToken(this).delete()
|
||||
trackPreferences.trackToken(this).delete()
|
||||
interceptor.newAuth(null)
|
||||
}
|
||||
|
||||
|
||||
@@ -141,12 +141,12 @@ class Kitsu(private val context: Context, id: Long) : TrackService(id) {
|
||||
}
|
||||
|
||||
fun saveToken(oauth: OAuth?) {
|
||||
preferences.trackToken(this).set(json.encodeToString(oauth))
|
||||
trackPreferences.trackToken(this).set(json.encodeToString(oauth))
|
||||
}
|
||||
|
||||
fun restoreToken(): OAuth? {
|
||||
return try {
|
||||
json.decodeFromString<OAuth>(preferences.trackToken(this).get())
|
||||
json.decodeFromString<OAuth>(trackPreferences.trackToken(this).get())
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
@@ -99,6 +99,6 @@ class MangaUpdates(private val context: Context, id: Long) : TrackService(id) {
|
||||
}
|
||||
|
||||
fun restoreSession(): String? {
|
||||
return preferences.trackPassword(this).get()
|
||||
return trackPreferences.trackPassword(this).get()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,17 +147,17 @@ class MyAnimeList(private val context: Context, id: Long) : TrackService(id) {
|
||||
|
||||
override fun logout() {
|
||||
super.logout()
|
||||
preferences.trackToken(this).delete()
|
||||
trackPreferences.trackToken(this).delete()
|
||||
interceptor.setAuth(null)
|
||||
}
|
||||
|
||||
fun saveOAuth(oAuth: OAuth?) {
|
||||
preferences.trackToken(this).set(json.encodeToString(oAuth))
|
||||
trackPreferences.trackToken(this).set(json.encodeToString(oAuth))
|
||||
}
|
||||
|
||||
fun loadOAuth(): OAuth? {
|
||||
return try {
|
||||
json.decodeFromString<OAuth>(preferences.trackToken(this).get())
|
||||
json.decodeFromString<OAuth>(trackPreferences.trackToken(this).get())
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ class Shikimori(private val context: Context, id: Long) : TrackService(id) {
|
||||
}
|
||||
|
||||
fun saveToken(oauth: OAuth?) {
|
||||
preferences.trackToken(this).set(json.encodeToString(oauth))
|
||||
trackPreferences.trackToken(this).set(json.encodeToString(oauth))
|
||||
}
|
||||
|
||||
fun restoreToken(): OAuth? {
|
||||
return try {
|
||||
json.decodeFromString<OAuth>(preferences.trackToken(this).get())
|
||||
json.decodeFromString<OAuth>(trackPreferences.trackToken(this).get())
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class Shikimori(private val context: Context, id: Long) : TrackService(id) {
|
||||
|
||||
override fun logout() {
|
||||
super.logout()
|
||||
preferences.trackToken(this).delete()
|
||||
trackPreferences.trackToken(this).delete()
|
||||
interceptor.newAuth(null)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user