mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-04 16:18:55 +01:00
Split track preferences from PreferencesHelper (#8046)
This commit is contained in:
@@ -382,7 +382,7 @@ class LibraryUpdateService(
|
||||
failedUpdates.add(mangaWithNotif to errorMessage)
|
||||
}
|
||||
|
||||
if (preferences.autoUpdateTrackers().get()) {
|
||||
if (libraryPreferences.autoUpdateTrackers().get()) {
|
||||
updateTrackings(mangaWithNotif, loggedServices)
|
||||
}
|
||||
}
|
||||
@@ -432,7 +432,7 @@ class LibraryUpdateService(
|
||||
val source = sourceManager.getOrStub(manga.source)
|
||||
|
||||
// Update manga metadata if needed
|
||||
if (preferences.autoUpdateMetadata().get()) {
|
||||
if (libraryPreferences.autoUpdateMetadata().get()) {
|
||||
val networkManga = source.getMangaDetails(manga.toSManga())
|
||||
updateManga.awaitUpdateFromSource(manga, networkManga, manualFetch = false, coverCache)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
||||
import eu.kanade.tachiyomi.core.preference.getEnum
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
import eu.kanade.tachiyomi.data.track.anilist.Anilist
|
||||
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
||||
import eu.kanade.tachiyomi.util.system.isDynamicColorAvailable
|
||||
import java.io.File
|
||||
@@ -41,10 +39,6 @@ class PreferencesHelper(
|
||||
|
||||
fun sideNavIconAlignment() = preferenceStore.getInt("pref_side_nav_icon_alignment", 0)
|
||||
|
||||
fun autoUpdateMetadata() = preferenceStore.getBoolean("auto_update_metadata", false)
|
||||
|
||||
fun autoUpdateTrackers() = preferenceStore.getBoolean("auto_update_trackers", false)
|
||||
|
||||
fun themeMode() = preferenceStore.getEnum(
|
||||
"pref_theme_mode_key",
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Values.ThemeMode.system } else { Values.ThemeMode.light },
|
||||
@@ -59,19 +53,6 @@ class PreferencesHelper(
|
||||
|
||||
fun lastVersionCode() = preferenceStore.getInt("last_version_code", 0)
|
||||
|
||||
fun trackUsername(sync: TrackService) = preferenceStore.getString(Keys.trackUsername(sync.id), "")
|
||||
|
||||
fun trackPassword(sync: TrackService) = preferenceStore.getString(Keys.trackPassword(sync.id), "")
|
||||
|
||||
fun setTrackCredentials(sync: TrackService, username: String, password: String) {
|
||||
trackUsername(sync).set(username)
|
||||
trackPassword(sync).set(password)
|
||||
}
|
||||
|
||||
fun trackToken(sync: TrackService) = preferenceStore.getString(Keys.trackToken(sync.id), "")
|
||||
|
||||
fun anilistScoreType() = preferenceStore.getString("anilist_score_type", Anilist.POINT_10)
|
||||
|
||||
fun backupsDirectory() = preferenceStore.getString("backup_directory", defaultBackupDir.toString())
|
||||
|
||||
fun relativeTime() = preferenceStore.getInt("relative_time", 7)
|
||||
@@ -115,8 +96,6 @@ class PreferencesHelper(
|
||||
|
||||
fun autoDownloadWhileReading() = preferenceStore.getInt("auto_download_while_reading", 0)
|
||||
|
||||
fun autoUpdateTrack() = preferenceStore.getBoolean("pref_auto_update_manga_sync_key", true)
|
||||
|
||||
fun migrateFlags() = preferenceStore.getInt("migrate_flags", Int.MAX_VALUE)
|
||||
|
||||
fun filterChapterByRead() = preferenceStore.getInt("default_chapter_filter_by_read", DomainManga.SHOW_ALL.toInt())
|
||||
|
||||
@@ -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