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 launcherIcon = "launcherIcon"
const val textSelectAble = "selectText"
const val lastBackup = "lastBackup"
const val shareLayout = "shareLayout"
const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces"

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

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

Loading…
Cancel
Save