mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
添加本地密码设置,用来对备份的敏感信息进行加密和解密
This commit is contained in:
@@ -6,12 +6,22 @@ import androidx.core.content.edit
|
||||
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 splitties.init.appCtx
|
||||
|
||||
object LocalConfig :
|
||||
SharedPreferences by appCtx.getSharedPreferences("local", Context.MODE_PRIVATE) {
|
||||
private const val versionCodeKey = "appVersionCode"
|
||||
|
||||
/**
|
||||
* 本地密码,用来对需要备份的敏感信息加密,如 webdav 配置等
|
||||
*/
|
||||
var password: String
|
||||
get() = getString("password", "") ?: ""
|
||||
set(value) {
|
||||
putString("password", value)
|
||||
}
|
||||
|
||||
var lastBackup: Long
|
||||
get() = getLong("lastBackup", 0)
|
||||
set(value) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.legado.app.constant.AppConst.appInfo
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.databinding.ActivityMainBinding
|
||||
import io.legado.app.databinding.DialogEditTextBinding
|
||||
import io.legado.app.help.AppWebDav
|
||||
import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.config.AppConfig
|
||||
@@ -103,6 +104,8 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
if (!privacyPolicy()) return@launch
|
||||
//版本更新
|
||||
upVersion()
|
||||
//设置本地密码
|
||||
setLocalPassword()
|
||||
//备份同步
|
||||
backupSync()
|
||||
//自动更新书籍
|
||||
@@ -181,7 +184,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
*/
|
||||
private suspend fun upVersion() = suspendCoroutine { block ->
|
||||
if (LocalConfig.versionCode == appInfo.versionCode) {
|
||||
block.resume(Unit)
|
||||
block.resume(null)
|
||||
return@suspendCoroutine
|
||||
}
|
||||
LocalConfig.versionCode = appInfo.versionCode
|
||||
@@ -189,18 +192,43 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
val help = String(assets.open("help/appHelp.md").readBytes())
|
||||
val dialog = TextDialog(getString(R.string.help), help, TextDialog.Mode.MD)
|
||||
dialog.setOnDismissListener {
|
||||
block.resume(Unit)
|
||||
block.resume(null)
|
||||
}
|
||||
showDialogFragment(dialog)
|
||||
} else if (!BuildConfig.DEBUG) {
|
||||
val log = String(assets.open("updateLog.md").readBytes())
|
||||
val dialog = TextDialog(getString(R.string.update_log), log, TextDialog.Mode.MD)
|
||||
dialog.setOnDismissListener {
|
||||
block.resume(Unit)
|
||||
block.resume(null)
|
||||
}
|
||||
showDialogFragment(dialog)
|
||||
} else {
|
||||
block.resume(Unit)
|
||||
block.resume(null)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置本地密码
|
||||
*/
|
||||
private suspend fun setLocalPassword() = suspendCoroutine { block ->
|
||||
if (LocalConfig.password.isNotBlank()) {
|
||||
block.resume(null)
|
||||
return@suspendCoroutine
|
||||
}
|
||||
alert(R.string.set_local_password, R.string.set_local_password_summary) {
|
||||
val editTextBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.hint = "password"
|
||||
}
|
||||
customView {
|
||||
editTextBinding.root
|
||||
}
|
||||
onDismiss {
|
||||
block.resume(null)
|
||||
}
|
||||
okButton {
|
||||
LocalConfig.password = editTextBinding.editView.text.toString()
|
||||
}
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1094,4 +1094,6 @@
|
||||
<string name="text_underline">文字下划线</string>
|
||||
<string name="select_new_source">选中新增源</string>
|
||||
<string name="select_update_source">选中更新源</string>
|
||||
<string name="set_local_password">设置本地密码</string>
|
||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1097,4 +1097,6 @@
|
||||
<string name="text_underline">文字下划线</string>
|
||||
<string name="select_new_source">选中新增源</string>
|
||||
<string name="select_update_source">选中更新源</string>
|
||||
<string name="set_local_password">设置本地密码</string>
|
||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1097,4 +1097,6 @@
|
||||
<string name="text_underline">文字下划线</string>
|
||||
<string name="select_new_source">选中新增源</string>
|
||||
<string name="select_update_source">选中更新源</string>
|
||||
<string name="set_local_password">设置本地密码</string>
|
||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1094,4 +1094,6 @@
|
||||
<string name="text_underline">文字下划线</string>
|
||||
<string name="select_new_source">选中新增源</string>
|
||||
<string name="select_update_source">选中更新源</string>
|
||||
<string name="set_local_password">设置本地密码</string>
|
||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1096,4 +1096,6 @@
|
||||
<string name="text_underline">文字下划线</string>
|
||||
<string name="select_new_source">选中新增源</string>
|
||||
<string name="select_update_source">选中更新源</string>
|
||||
<string name="set_local_password">设置本地密码</string>
|
||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1096,4 +1096,6 @@
|
||||
<string name="text_underline">文字下划线</string>
|
||||
<string name="select_new_source">选中新增源</string>
|
||||
<string name="select_update_source">选中更新源</string>
|
||||
<string name="set_local_password">设置本地密码</string>
|
||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1097,4 +1097,6 @@
|
||||
<string name="text_underline">文字下划线</string>
|
||||
<string name="select_new_source">选中新增源</string>
|
||||
<string name="select_update_source">选中更新源</string>
|
||||
<string name="set_local_password">设置本地密码</string>
|
||||
<string name="set_local_password_summary">本地密码用来对备份的敏感信息加密和解密,如需在不同设备之间同步,本地密码需一致.</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user