mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
package io.legado.app.help.config
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import splitties.init.appCtx
|
||||
|
||||
object LocalConfig {
|
||||
object LocalConfig :
|
||||
SharedPreferences by appCtx.getSharedPreferences("local", Context.MODE_PRIVATE) {
|
||||
private const val versionCodeKey = "appVersionCode"
|
||||
|
||||
private val localConfig =
|
||||
appCtx.getSharedPreferences("local", Context.MODE_PRIVATE)
|
||||
|
||||
val readHelpVersionIsLast: Boolean
|
||||
get() = isLastVersion(1, "readHelpVersion", "firstRead")
|
||||
|
||||
@@ -35,18 +34,16 @@ object LocalConfig {
|
||||
get() = !isLastVersion(4, "rssSourceVersion")
|
||||
|
||||
var versionCode
|
||||
get() = localConfig.getLong(versionCodeKey, 0)
|
||||
get() = getLong(versionCodeKey, 0)
|
||||
set(value) {
|
||||
localConfig.edit {
|
||||
putLong(versionCodeKey, value)
|
||||
}
|
||||
edit { putLong(versionCodeKey, value) }
|
||||
}
|
||||
|
||||
val isFirstOpenApp: Boolean
|
||||
get() {
|
||||
val value = localConfig.getBoolean("firstOpen", true)
|
||||
val value = getBoolean("firstOpen", true)
|
||||
if (value) {
|
||||
localConfig.edit { putBoolean("firstOpen", false) }
|
||||
edit { putBoolean("firstOpen", false) }
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -57,14 +54,14 @@ object LocalConfig {
|
||||
versionKey: String,
|
||||
firstOpenKey: String? = null
|
||||
): Boolean {
|
||||
var version = localConfig.getInt(versionKey, 0)
|
||||
var version = getInt(versionKey, 0)
|
||||
if (version == 0 && firstOpenKey != null) {
|
||||
if (!localConfig.getBoolean(firstOpenKey, true)) {
|
||||
if (!getBoolean(firstOpenKey, true)) {
|
||||
version = 1
|
||||
}
|
||||
}
|
||||
if (version < lastVersion) {
|
||||
localConfig.edit { putInt(versionKey, lastVersion) }
|
||||
edit { putInt(versionKey, lastVersion) }
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.documentfile.provider.DocumentFile
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.help.config.LocalConfig
|
||||
import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.help.config.ThemeConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
@@ -47,13 +48,13 @@ object Backup {
|
||||
}
|
||||
|
||||
fun autoBack(context: Context) {
|
||||
val lastBackup = context.getPrefLong(PreferKey.lastBackup)
|
||||
val lastBackup = LocalConfig.getLong(PreferKey.lastBackup, 0)
|
||||
if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) {
|
||||
Coroutine.async {
|
||||
if (!AppWebDav.hasBackUp()) {
|
||||
backup(context, context.getPrefString(PreferKey.backupPath), true)
|
||||
} else {
|
||||
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis())
|
||||
LocalConfig.putLong(PreferKey.lastBackup, System.currentTimeMillis())
|
||||
}
|
||||
}.onError {
|
||||
AppLog.put("自动备份失败\n${it.localizedMessage}")
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
|
||||
|
||||
fun SharedPreferences.putLong(key: String, value: Long) {
|
||||
edit {
|
||||
putLong(key, value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user