kunfei 4 лет назад
Родитель
Сommit
d1d019394a

+ 2 - 2
app/src/main/java/io/legado/app/help/storage/AppWebDav.kt

@@ -33,7 +33,7 @@ object AppWebDav {
 
     init {
         runBlocking {
-            initConfig()
+            upConfig()
         }
     }
 
@@ -57,7 +57,7 @@ object AppWebDav {
             return "backup${backupDate}.zip"
         }
 
-    suspend fun initConfig() {
+    suspend fun upConfig() {
         kotlin.runCatching {
             isOk = false
             val account = appCtx.getPrefString(PreferKey.webDavAccount)

+ 14 - 7
app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@@ -9,6 +9,7 @@ import android.view.MenuInflater
 import android.view.MenuItem
 import android.view.View
 import androidx.documentfile.provider.DocumentFile
+import androidx.fragment.app.activityViewModels
 import androidx.lifecycle.lifecycleScope
 import androidx.preference.EditTextPreference
 import androidx.preference.ListPreference
@@ -36,6 +37,8 @@ import splitties.init.appCtx
 class BackupConfigFragment : BasePreferenceFragment(),
     SharedPreferences.OnSharedPreferenceChangeListener {
 
+    private val viewModel by activityViewModels<ConfigViewModel>()
+
     private val selectBackupPath = registerForActivityResult(HandleFileContract()) {
         it.uri?.let { uri ->
             if (uri.isContentScheme()) {
@@ -101,7 +104,6 @@ class BackupConfigFragment : BasePreferenceFragment(),
             it.setOnBindEditTextListener { editText ->
                 editText.applyTint(requireContext().accentColor)
             }
-
         }
         findPreference<EditTextPreference>(PreferKey.webDavAccount)?.let {
             it.setOnBindEditTextListener { editText ->
@@ -115,6 +117,11 @@ class BackupConfigFragment : BasePreferenceFragment(),
                     InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
             }
         }
+        findPreference<EditTextPreference>(PreferKey.webDavDir)?.let {
+            it.setOnBindEditTextListener { editText ->
+                editText.applyTint(requireContext().accentColor)
+            }
+        }
         upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl))
         upPreferenceSummary(PreferKey.webDavAccount, getPrefString(PreferKey.webDavAccount))
         upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword))
@@ -160,13 +167,14 @@ class BackupConfigFragment : BasePreferenceFragment(),
 
     override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
         when (key) {
+            PreferKey.backupPath -> upPreferenceSummary(key, getPrefString(key))
             PreferKey.webDavUrl,
             PreferKey.webDavAccount,
             PreferKey.webDavPassword,
-            PreferKey.backupPath -> {
+            PreferKey.webDavDir -> listView.post {
                 upPreferenceSummary(key, getPrefString(key))
+                viewModel.upWebDavConfig()
             }
-            PreferKey.webDavDir -> upPreferenceSummary(key, AppConfig.webDavDir)
         }
     }
 
@@ -191,10 +199,9 @@ class BackupConfigFragment : BasePreferenceFragment(),
                 } else {
                     preference.summary = "*".repeat(value.toString().length)
                 }
-            PreferKey.webDavDir -> if (value.isNullOrBlank()) {
-                preference.summary = "null"
-            } else {
-                preference.summary = value
+            PreferKey.webDavDir -> preference.summary = when (value) {
+                null -> "legado"
+                else -> value
             }
             else -> {
                 if (preference is ListPreference) {

+ 7 - 0
app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt

@@ -4,11 +4,18 @@ import android.app.Application
 import io.legado.app.R
 import io.legado.app.base.BaseViewModel
 import io.legado.app.help.BookHelp
+import io.legado.app.help.storage.AppWebDav
 import io.legado.app.utils.FileUtils
 import io.legado.app.utils.toastOnUi
 
 class ConfigViewModel(application: Application) : BaseViewModel(application) {
 
+    fun upWebDavConfig() {
+        execute {
+            AppWebDav.upConfig()
+        }
+    }
+
     fun clearCache() {
         execute {
             BookHelp.clearCache()