mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -7,19 +7,25 @@ import io.legado.app.utils.getBoolean
|
||||
import io.legado.app.utils.putBoolean
|
||||
import io.legado.app.utils.putLong
|
||||
import io.legado.app.utils.putString
|
||||
import io.legado.app.utils.remove
|
||||
import splitties.init.appCtx
|
||||
|
||||
object LocalConfig :
|
||||
SharedPreferences by appCtx.getSharedPreferences("local", Context.MODE_PRIVATE) {
|
||||
object LocalConfig : SharedPreferences
|
||||
by appCtx.getSharedPreferences("local", Context.MODE_PRIVATE) {
|
||||
|
||||
private const val versionCodeKey = "appVersionCode"
|
||||
|
||||
/**
|
||||
* 本地密码,用来对需要备份的敏感信息加密,如 webdav 配置等
|
||||
*/
|
||||
var password: String
|
||||
get() = getString("password", "") ?: ""
|
||||
var password: String?
|
||||
get() = getString("password", null)
|
||||
set(value) {
|
||||
putString("password", value)
|
||||
if (value != null) {
|
||||
putString("password", value)
|
||||
} else {
|
||||
remove("password")
|
||||
}
|
||||
}
|
||||
|
||||
var lastBackup: Long
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import io.legado.app.BuildConfig
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.VMBaseActivity
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppConst.appInfo
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.PreferKey
|
||||
@@ -212,7 +211,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
* 设置本地密码
|
||||
*/
|
||||
private suspend fun setLocalPassword() = suspendCoroutine { block ->
|
||||
if (LocalConfig.password.isNotBlank()) {
|
||||
if (LocalConfig.password != null) {
|
||||
block.resume(null)
|
||||
return@suspendCoroutine
|
||||
}
|
||||
@@ -230,7 +229,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
LocalConfig.password = editTextBinding.editView.text.toString()
|
||||
}
|
||||
cancelButton {
|
||||
LocalConfig.password = AppConst.androidId
|
||||
LocalConfig.password = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,4 +94,10 @@ fun SharedPreferences.putFloat(key: String, value: Float) {
|
||||
edit {
|
||||
putFloat(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
fun SharedPreferences.remove(key: String) {
|
||||
edit {
|
||||
remove(key)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user