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