HapeLee 5 месяцев назад
Родитель
Сommit
0adb3a1484

+ 7 - 8
app/src/main/java/io/legado/app/help/AppWebDav.kt

@@ -3,7 +3,6 @@ package io.legado.app.help
 import android.net.Uri
 import io.legado.app.R
 import io.legado.app.constant.AppLog
-import io.legado.app.constant.PreferKey
 import io.legado.app.data.appDb
 import io.legado.app.data.entities.Book
 import io.legado.app.data.entities.BookProgress
@@ -25,7 +24,7 @@ import io.legado.app.utils.NetworkUtils
 import io.legado.app.utils.UrlUtil
 import io.legado.app.utils.compress.ZipUtils
 import io.legado.app.utils.fromJsonObject
-import io.legado.app.utils.getPrefString
+import io.legado.app.ui.config.backupConfig.BackupConfig
 import io.legado.app.utils.isJson
 import io.legado.app.utils.normalizeFileName
 import io.legado.app.utils.toastOnUi
@@ -62,8 +61,8 @@ object AppWebDav {
 
     private val rootWebDavUrl: String
         get() {
-            val configUrl = appCtx.getPrefString(PreferKey.webDavUrl)?.trim()
-            var url = if (configUrl.isNullOrEmpty()) defaultWebDavUrl else configUrl
+            val configUrl = BackupConfig.webDavUrl.trim()
+            var url = if (configUrl.isEmpty()) defaultWebDavUrl else configUrl
             if (!url.endsWith("/")) url = "${url}/"
             AppConfig.webDavDir?.trim()?.let {
                 if (it.isNotEmpty()) {
@@ -77,8 +76,8 @@ object AppWebDav {
         kotlin.runCatching {
             authorization = null
             defaultBookWebDav = null
-            val account = appCtx.getPrefString(PreferKey.webDavAccount)
-            val password = appCtx.getPrefString(PreferKey.webDavPassword)
+            val account = BackupConfig.webDavAccount
+            val password = BackupConfig.webDavPassword
             if (!account.isNullOrEmpty() && !password.isNullOrEmpty()) {
                 val mAuthorization = Authorization(account, password)
                 checkAuthorization(mAuthorization)
@@ -162,8 +161,8 @@ object AppWebDav {
 
     suspend fun testWebDav(): Boolean {
         return kotlin.runCatching {
-            val account = appCtx.getPrefString(PreferKey.webDavAccount)
-            val password = appCtx.getPrefString(PreferKey.webDavPassword)
+            val account = BackupConfig.webDavAccount
+            val password = BackupConfig.webDavPassword
             if (account.isNullOrEmpty() || password.isNullOrEmpty()) {
                 appCtx.toastOnUi("账号或密码为空")
                 return false

+ 6 - 6
app/src/main/java/io/legado/app/help/WebDavManager.kt

@@ -3,6 +3,7 @@ package io.legado.app.help
 import android.content.SharedPreferences
 import android.net.Uri
 import io.legado.app.constant.PreferKey
+import io.legado.app.ui.config.backupConfig.BackupConfig
 import io.legado.app.data.appDb
 import io.legado.app.data.entities.Book
 import io.legado.app.data.entities.BookProgress
@@ -25,7 +26,6 @@ import io.legado.app.utils.UrlUtil
 import io.legado.app.utils.compress.ZipUtils
 import io.legado.app.utils.defaultSharedPreferences
 import io.legado.app.utils.fromJsonObject
-import io.legado.app.utils.getPrefString
 import io.legado.app.utils.isJson
 import io.legado.app.utils.normalizeFileName
 import kotlinx.coroutines.CoroutineDispatcher
@@ -287,11 +287,11 @@ class WebDavManager(
 
     private fun readConfig(): WebDavConfig {
         return WebDavConfig(
-            url = appCtx.getPrefString(PreferKey.webDavUrl, "") ?: "",
-            account = appCtx.getPrefString(PreferKey.webDavAccount, "") ?: "",
-            password = appCtx.getPrefString(PreferKey.webDavPassword, "") ?: "",
-            dir = appCtx.getPrefString(PreferKey.webDavDir, "legado") ?: "legado",
-            deviceName = appCtx.getPrefString(PreferKey.webDavDeviceName, "") ?: ""
+            url = BackupConfig.webDavUrl,
+            account = BackupConfig.webDavAccount,
+            password = BackupConfig.webDavPassword,
+            dir = BackupConfig.webDavDir,
+            deviceName = BackupConfig.webDavDeviceName
         )
     }
 

+ 0 - 10
app/src/main/java/io/legado/app/help/storage/Restore.kt

@@ -45,8 +45,6 @@ import io.legado.app.utils.LogUtils
 import io.legado.app.utils.compress.ZipUtils
 import io.legado.app.utils.defaultSharedPreferences
 import io.legado.app.utils.fromJsonArray
-import io.legado.app.utils.getPrefBoolean
-import io.legado.app.utils.getPrefInt
 import io.legado.app.utils.getPrefString
 import io.legado.app.utils.isContentScheme
 import io.legado.app.utils.isJsonArray
@@ -327,14 +325,6 @@ object Restore : KoinComponent {
             }
         }
 
-        ReadBookConfig.apply {
-            comicStyleSelect = appCtx.getPrefInt(PreferKey.comicStyleSelect)
-            readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
-            shareLayout = appCtx.getPrefBoolean(PreferKey.shareLayout)
-            hideStatusBar = appCtx.getPrefBoolean(PreferKey.hideStatusBar)
-            hideNavigationBar = appCtx.getPrefBoolean(PreferKey.hideNavigationBar)
-            autoReadSpeed = appCtx.getPrefInt(PreferKey.autoReadSpeed, 46)
-        }
         appCtx.toastOnUi(R.string.restore_success)
         withContext(Main) {
             delay(100)

+ 6 - 12
app/src/main/java/io/legado/app/ui/welcome/WebDavFragment.kt

@@ -7,18 +7,16 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.widget.ArrayAdapter
-import androidx.core.content.edit
 import androidx.core.widget.doAfterTextChanged
 import androidx.lifecycle.lifecycleScope
-import androidx.preference.PreferenceManager
 import io.legado.app.R
 import io.legado.app.base.BaseFragment
 import io.legado.app.constant.AppLog
-import io.legado.app.constant.PreferKey
 import io.legado.app.databinding.FragmentWebdavAuthBinding
 import io.legado.app.domain.usecase.WebDavBackupUseCase
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.help.config.LocalConfig
+import io.legado.app.ui.config.backupConfig.BackupConfig
 import io.legado.app.help.coroutine.Coroutine
 import io.legado.app.help.storage.Restore
 import io.legado.app.lib.dialogs.alert
@@ -71,8 +69,6 @@ class WebDavFragment : BaseFragment(R.layout.fragment_webdav_auth) {
 
     override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
 
-        val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
-
         val urls = listOf(
             "https://dav.jianguoyun.com/dav/",
             "https://webdav.aliyundrive.com/",
@@ -87,8 +83,8 @@ class WebDavFragment : BaseFragment(R.layout.fragment_webdav_auth) {
 
         binding.editUrl.setAdapter(adapter)
 
-        binding.editAccount.setText(prefs.getString(PreferKey.webDavAccount, ""))
-        binding.editPassword.setText(prefs.getString(PreferKey.webDavPassword, ""))
+        binding.editAccount.setText(BackupConfig.webDavAccount)
+        binding.editPassword.setText(BackupConfig.webDavPassword)
         binding.editPassword.inputType =
             InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
 
@@ -133,11 +129,9 @@ class WebDavFragment : BaseFragment(R.layout.fragment_webdav_auth) {
     }
 
     fun saveWebDavConfig(config: WebDavConfig, onSaved: (() -> Unit)? = null) {
-        PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
-            putString(PreferKey.webDavUrl, config.url)
-            putString(PreferKey.webDavAccount, config.account)
-            putString(PreferKey.webDavPassword, config.password)
-        }
+        BackupConfig.webDavUrl = config.url
+        BackupConfig.webDavAccount = config.account
+        BackupConfig.webDavPassword = config.password
 
         onSaved?.invoke()
     }