pull/1738/head
kunfei 3 years ago
parent cf90bae931
commit 481df04b80
  1. 4
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt
  2. 21
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  3. 7
      app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt

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

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

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

Loading…
Cancel
Save