mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Split backup related preferences to its own class
Also increased default number of backups to 5
This commit is contained in:
parent
0f9ff92f89
commit
6d60177a09
7 changed files with 26 additions and 13 deletions
|
@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.data.backup.create.creators.PreferenceBackupCreator
|
|||
import eu.kanade.tachiyomi.data.backup.create.creators.SourcesBackupCreator
|
||||
import eu.kanade.tachiyomi.data.backup.models.Backup
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.system.e
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import okio.buffer
|
||||
|
@ -20,6 +19,7 @@ import okio.sink
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.backup.BackupPreferences
|
||||
import yokai.domain.storage.StorageManager
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
@ -35,7 +35,7 @@ class BackupCreator(
|
|||
|
||||
val parser = ProtoBuf
|
||||
private val db: DatabaseHelper = Injekt.get()
|
||||
private val preferences: PreferencesHelper = Injekt.get()
|
||||
private val preferences: BackupPreferences = Injekt.get()
|
||||
private val storageManager: StorageManager by injectLazy()
|
||||
|
||||
@Suppress("RedundantSuspendModifier")
|
||||
|
|
|
@ -16,13 +16,13 @@ import co.touchlab.kermit.Logger
|
|||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.data.backup.BackupNotifier
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.system.e
|
||||
import eu.kanade.tachiyomi.util.system.localeContext
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.backup.BackupPreferences
|
||||
import yokai.domain.storage.StorageManager
|
||||
import java.util.concurrent.*
|
||||
|
||||
|
@ -58,7 +58,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
|
|||
}
|
||||
|
||||
fun setupTask(context: Context, prefInterval: Int? = null) {
|
||||
val preferences = Injekt.get<PreferencesHelper>()
|
||||
val preferences = Injekt.get<BackupPreferences>()
|
||||
val interval = prefInterval ?: preferences.backupInterval().get()
|
||||
val workManager = WorkManager.getInstance(context)
|
||||
if (interval > 0) {
|
||||
|
|
|
@ -204,9 +204,6 @@ class PreferencesHelper(val context: Context, val preferenceStore: PreferenceSto
|
|||
|
||||
fun lastLibrarySuggestion() = preferenceStore.getLong("last_library_suggestion", 0L)
|
||||
|
||||
fun numberOfBackups() = preferenceStore.getInt(Keys.numberOfBackups, 2)
|
||||
|
||||
fun backupInterval() = preferenceStore.getInt(Keys.backupInterval, 0)
|
||||
fun removeAfterReadSlots() = preferenceStore.getInt(Keys.removeAfterReadSlots, -1)
|
||||
|
||||
fun removeAfterMarkedAsRead() = preferenceStore.getBoolean(Keys.removeAfterMarkedAsRead, false)
|
||||
|
|
|
@ -45,6 +45,7 @@ import eu.kanade.tachiyomi.util.view.setTitle
|
|||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.backup.BackupPreferences
|
||||
import yokai.domain.storage.StorageManager
|
||||
import yokai.domain.storage.StoragePreferences
|
||||
import yokai.i18n.MR
|
||||
|
@ -63,6 +64,7 @@ class SettingsDataLegacyController : SettingsLegacyController() {
|
|||
internal val storagePreferences: StoragePreferences by injectLazy()
|
||||
internal val storageManager: StorageManager by injectLazy()
|
||||
internal val extensionManager: ExtensionManager by injectLazy()
|
||||
internal val backupPreferences: BackupPreferences by injectLazy()
|
||||
|
||||
private val coverCache: CoverCache by injectLazy()
|
||||
private val chapterCache: ChapterCache by injectLazy()
|
||||
|
@ -142,7 +144,7 @@ class SettingsDataLegacyController : SettingsLegacyController() {
|
|||
titleRes = MR.strings.automatic_backups
|
||||
|
||||
intListPreference(activity) {
|
||||
bindTo(preferences.backupInterval())
|
||||
bindTo(backupPreferences.backupInterval())
|
||||
titleRes = MR.strings.backup_frequency
|
||||
entriesRes = arrayOf(
|
||||
MR.strings.manual,
|
||||
|
@ -161,12 +163,12 @@ class SettingsDataLegacyController : SettingsLegacyController() {
|
|||
}
|
||||
}
|
||||
intListPreference(activity) {
|
||||
bindTo(preferences.numberOfBackups())
|
||||
bindTo(backupPreferences.numberOfBackups())
|
||||
titleRes = MR.strings.max_auto_backups
|
||||
entries = (1..5).map(Int::toString)
|
||||
entryRange = 1..5
|
||||
|
||||
visibleIf(preferences.backupInterval()) { it > 0 }
|
||||
visibleIf(backupPreferences.backupInterval()) { it > 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import uy.kohesive.injekt.api.InjektModule
|
|||
import uy.kohesive.injekt.api.InjektRegistrar
|
||||
import uy.kohesive.injekt.api.addSingletonFactory
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.domain.backup.BackupPreferences
|
||||
import yokai.domain.base.BasePreferences
|
||||
import yokai.domain.download.DownloadPreferences
|
||||
import yokai.domain.recents.RecentsPreferences
|
||||
|
@ -42,6 +43,8 @@ class PreferenceModule(val application: Application) : InjektModule {
|
|||
|
||||
addSingletonFactory { SecurityPreferences(get()) }
|
||||
|
||||
addSingletonFactory { BackupPreferences(get()) }
|
||||
|
||||
addSingletonFactory {
|
||||
PreferencesHelper(
|
||||
context = application,
|
||||
|
|
11
app/src/main/java/yokai/domain/backup/BackupPreferences.kt
Normal file
11
app/src/main/java/yokai/domain/backup/BackupPreferences.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package yokai.domain.backup
|
||||
|
||||
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
|
||||
class BackupPreferences(private val preferenceStore: PreferenceStore) {
|
||||
|
||||
fun numberOfBackups() = preferenceStore.getInt(PreferenceKeys.numberOfBackups, 5)
|
||||
|
||||
fun backupInterval() = preferenceStore.getInt(PreferenceKeys.backupInterval, 0)
|
||||
}
|
|
@ -32,7 +32,6 @@ import eu.kanade.tachiyomi.data.backup.create.BackupCreatorJob
|
|||
import eu.kanade.tachiyomi.data.backup.restore.BackupRestoreJob
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
import eu.kanade.tachiyomi.util.compose.LocalAlertDialog
|
||||
import eu.kanade.tachiyomi.util.compose.currentOrThrow
|
||||
|
@ -48,6 +47,7 @@ import kotlinx.coroutines.launch
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.backup.BackupPreferences
|
||||
import yokai.domain.storage.StorageManager
|
||||
import yokai.domain.storage.StoragePreferences
|
||||
import yokai.i18n.MR
|
||||
|
@ -69,7 +69,7 @@ object SettingsDataScreen : ComposableSettings {
|
|||
@Composable
|
||||
override fun getPreferences(): List<Preference> {
|
||||
val storagePreferences: StoragePreferences by injectLazy()
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
val preferences: BackupPreferences by injectLazy()
|
||||
|
||||
return persistentListOf(
|
||||
getStorageLocationPreference(storagePreferences = storagePreferences),
|
||||
|
@ -97,7 +97,7 @@ object SettingsDataScreen : ComposableSettings {
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun getBackupAndRestoreGroup(preferences: PreferencesHelper): Preference.PreferenceGroup {
|
||||
private fun getBackupAndRestoreGroup(preferences: BackupPreferences): Preference.PreferenceGroup {
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
val alertDialog = LocalAlertDialog.currentOrThrow
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue