pull/1835/head
kunfei 3 years ago
parent 28c571162d
commit 2d9ffadcba
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 7
      app/src/main/java/io/legado/app/help/config/LocalConfig.kt
  3. 6
      app/src/main/java/io/legado/app/help/storage/Backup.kt

@ -61,7 +61,6 @@ object PreferKey {
const val chineseConverterType = "chineseConverterType" const val chineseConverterType = "chineseConverterType"
const val launcherIcon = "launcherIcon" const val launcherIcon = "launcherIcon"
const val textSelectAble = "selectText" const val textSelectAble = "selectText"
const val lastBackup = "lastBackup"
const val shareLayout = "shareLayout" const val shareLayout = "shareLayout"
const val readStyleSelect = "readStyleSelect" const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces" const val systemTypefaces = "system_typefaces"

@ -3,12 +3,19 @@ package io.legado.app.help.config
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import androidx.core.content.edit import androidx.core.content.edit
import io.legado.app.utils.putLong
import splitties.init.appCtx import splitties.init.appCtx
object LocalConfig : object LocalConfig :
SharedPreferences by appCtx.getSharedPreferences("local", Context.MODE_PRIVATE) { SharedPreferences by appCtx.getSharedPreferences("local", Context.MODE_PRIVATE) {
private const val versionCodeKey = "appVersionCode" private const val versionCodeKey = "appVersionCode"
var lastBackup: Long
get() = getLong("lastBackup", 0)
set(value) {
putLong("lastBackup", value)
}
val readHelpVersionIsLast: Boolean val readHelpVersionIsLast: Boolean
get() = isLastVersion(1, "readHelpVersion", "firstRead") get() = isLastVersion(1, "readHelpVersion", "firstRead")

@ -48,13 +48,13 @@ object Backup {
} }
fun autoBack(context: Context) { fun autoBack(context: Context) {
val lastBackup = LocalConfig.getLong(PreferKey.lastBackup, 0) val lastBackup = LocalConfig.lastBackup
if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) { if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) {
Coroutine.async { Coroutine.async {
if (!AppWebDav.hasBackUp()) { if (!AppWebDav.hasBackUp()) {
backup(context, context.getPrefString(PreferKey.backupPath), true) backup(context, context.getPrefString(PreferKey.backupPath), true)
} else { } else {
LocalConfig.putLong(PreferKey.lastBackup, System.currentTimeMillis()) LocalConfig.lastBackup = System.currentTimeMillis()
} }
}.onError { }.onError {
AppLog.put("自动备份失败\n${it.localizedMessage}") AppLog.put("自动备份失败\n${it.localizedMessage}")
@ -63,7 +63,6 @@ object Backup {
} }
suspend fun backup(context: Context, path: String?, isAuto: Boolean = false) { suspend fun backup(context: Context, path: String?, isAuto: Boolean = false) {
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis())
withContext(IO) { withContext(IO) {
FileUtils.delete(backupPath) FileUtils.delete(backupPath)
writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath) writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath)
@ -119,6 +118,7 @@ object Backup {
} }
AppWebDav.backUpWebDav(backupPath) AppWebDav.backUpWebDav(backupPath)
} }
LocalConfig.lastBackup = System.currentTimeMillis()
} }
private fun writeListToJson(list: List<Any>, fileName: String, path: String) { private fun writeListToJson(list: List<Any>, fileName: String, path: String) {

Loading…
Cancel
Save