parent
298c49f3ab
commit
1aa5222c99
4 changed files with 16 additions and 2 deletions
|
@ -33,6 +33,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import eu.kanade.presentation.more.settings.Preference
|
import eu.kanade.presentation.more.settings.Preference
|
||||||
import eu.kanade.presentation.permissions.PermissionRequestHelper
|
import eu.kanade.presentation.permissions.PermissionRequestHelper
|
||||||
|
import eu.kanade.presentation.util.relativeTimeSpanString
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.backup.BackupConst
|
import eu.kanade.tachiyomi.data.backup.BackupConst
|
||||||
import eu.kanade.tachiyomi.data.backup.BackupCreateJob
|
import eu.kanade.tachiyomi.data.backup.BackupCreateJob
|
||||||
|
@ -82,6 +83,7 @@ object SettingsDataScreen : SearchableSettings {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val backupIntervalPref = backupPreferences.backupInterval()
|
val backupIntervalPref = backupPreferences.backupInterval()
|
||||||
val backupInterval by backupIntervalPref.collectAsState()
|
val backupInterval by backupIntervalPref.collectAsState()
|
||||||
|
val lastAutoBackup by backupPreferences.lastAutoBackupTimestamp().collectAsState()
|
||||||
|
|
||||||
return Preference.PreferenceGroup(
|
return Preference.PreferenceGroup(
|
||||||
title = stringResource(R.string.label_backup),
|
title = stringResource(R.string.label_backup),
|
||||||
|
@ -113,7 +115,10 @@ object SettingsDataScreen : SearchableSettings {
|
||||||
title = stringResource(R.string.pref_backup_slots),
|
title = stringResource(R.string.pref_backup_slots),
|
||||||
entries = listOf(2, 3, 4, 5).associateWith { it.toString() },
|
entries = listOf(2, 3, 4, 5).associateWith { it.toString() },
|
||||||
),
|
),
|
||||||
Preference.PreferenceItem.InfoPreference(stringResource(R.string.backup_info)),
|
Preference.PreferenceItem.InfoPreference(
|
||||||
|
stringResource(R.string.backup_info) + "\n\n" +
|
||||||
|
stringResource(R.string.last_auto_backup_info, relativeTimeSpanString(lastAutoBackup)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import tachiyomi.core.util.system.logcat
|
||||||
import tachiyomi.domain.backup.service.BackupPreferences
|
import tachiyomi.domain.backup.service.BackupPreferences
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import java.util.Date
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.time.Duration.Companion.minutes
|
import kotlin.time.Duration.Companion.minutes
|
||||||
import kotlin.time.toJavaDuration
|
import kotlin.time.toJavaDuration
|
||||||
|
@ -50,7 +51,11 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val location = BackupCreator(context).createBackup(uri, flags, isAutoBackup)
|
val location = BackupCreator(context).createBackup(uri, flags, isAutoBackup)
|
||||||
if (!isAutoBackup) notifier.showBackupComplete(UniFile.fromUri(context, location.toUri()))
|
if (isAutoBackup) {
|
||||||
|
backupPreferences.lastAutoBackupTimestamp().set(Date().time)
|
||||||
|
} else {
|
||||||
|
notifier.showBackupComplete(UniFile.fromUri(context, location.toUri()))
|
||||||
|
}
|
||||||
Result.success()
|
Result.success()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logcat(LogPriority.ERROR, e)
|
logcat(LogPriority.ERROR, e)
|
||||||
|
|
|
@ -13,4 +13,7 @@ class BackupPreferences(
|
||||||
fun numberOfBackups() = preferenceStore.getInt("backup_slots", 2)
|
fun numberOfBackups() = preferenceStore.getInt("backup_slots", 2)
|
||||||
|
|
||||||
fun backupInterval() = preferenceStore.getInt("backup_interval", 12)
|
fun backupInterval() = preferenceStore.getInt("backup_interval", 12)
|
||||||
|
|
||||||
|
// TODO: move this and other "app state" preferences elsewhere and exclude from backups
|
||||||
|
fun lastAutoBackupTimestamp() = preferenceStore.getLong("__APP_STATE_last_auto_backup_timestamp", 0L)
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,6 +505,7 @@
|
||||||
<string name="restoring_backup_error">Restoring backup failed</string>
|
<string name="restoring_backup_error">Restoring backup failed</string>
|
||||||
<string name="restoring_backup_canceled">Canceled restore</string>
|
<string name="restoring_backup_canceled">Canceled restore</string>
|
||||||
<string name="backup_info">You should keep copies of backups in other places as well. Backups may contain sensitive data including any stored passwords; be careful if sharing.</string>
|
<string name="backup_info">You should keep copies of backups in other places as well. Backups may contain sensitive data including any stored passwords; be careful if sharing.</string>
|
||||||
|
<string name="last_auto_backup_info">Last automatically backed up: %s</string>
|
||||||
|
|
||||||
<!-- Sync section -->
|
<!-- Sync section -->
|
||||||
<string name="syncing_library">Syncing library</string>
|
<string name="syncing_library">Syncing library</string>
|
||||||
|
|
Reference in a new issue