fix: WebDAV配置来源统一
This commit is contained in:
@@ -3,7 +3,6 @@ package io.legado.app.help
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.constant.PreferKey
|
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.data.entities.BookProgress
|
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.UrlUtil
|
||||||
import io.legado.app.utils.compress.ZipUtils
|
import io.legado.app.utils.compress.ZipUtils
|
||||||
import io.legado.app.utils.fromJsonObject
|
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.isJson
|
||||||
import io.legado.app.utils.normalizeFileName
|
import io.legado.app.utils.normalizeFileName
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
@@ -62,8 +61,8 @@ object AppWebDav {
|
|||||||
|
|
||||||
private val rootWebDavUrl: String
|
private val rootWebDavUrl: String
|
||||||
get() {
|
get() {
|
||||||
val configUrl = appCtx.getPrefString(PreferKey.webDavUrl)?.trim()
|
val configUrl = BackupConfig.webDavUrl.trim()
|
||||||
var url = if (configUrl.isNullOrEmpty()) defaultWebDavUrl else configUrl
|
var url = if (configUrl.isEmpty()) defaultWebDavUrl else configUrl
|
||||||
if (!url.endsWith("/")) url = "${url}/"
|
if (!url.endsWith("/")) url = "${url}/"
|
||||||
AppConfig.webDavDir?.trim()?.let {
|
AppConfig.webDavDir?.trim()?.let {
|
||||||
if (it.isNotEmpty()) {
|
if (it.isNotEmpty()) {
|
||||||
@@ -77,8 +76,8 @@ object AppWebDav {
|
|||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
authorization = null
|
authorization = null
|
||||||
defaultBookWebDav = null
|
defaultBookWebDav = null
|
||||||
val account = appCtx.getPrefString(PreferKey.webDavAccount)
|
val account = BackupConfig.webDavAccount
|
||||||
val password = appCtx.getPrefString(PreferKey.webDavPassword)
|
val password = BackupConfig.webDavPassword
|
||||||
if (!account.isNullOrEmpty() && !password.isNullOrEmpty()) {
|
if (!account.isNullOrEmpty() && !password.isNullOrEmpty()) {
|
||||||
val mAuthorization = Authorization(account, password)
|
val mAuthorization = Authorization(account, password)
|
||||||
checkAuthorization(mAuthorization)
|
checkAuthorization(mAuthorization)
|
||||||
@@ -162,8 +161,8 @@ object AppWebDav {
|
|||||||
|
|
||||||
suspend fun testWebDav(): Boolean {
|
suspend fun testWebDav(): Boolean {
|
||||||
return kotlin.runCatching {
|
return kotlin.runCatching {
|
||||||
val account = appCtx.getPrefString(PreferKey.webDavAccount)
|
val account = BackupConfig.webDavAccount
|
||||||
val password = appCtx.getPrefString(PreferKey.webDavPassword)
|
val password = BackupConfig.webDavPassword
|
||||||
if (account.isNullOrEmpty() || password.isNullOrEmpty()) {
|
if (account.isNullOrEmpty() || password.isNullOrEmpty()) {
|
||||||
appCtx.toastOnUi("账号或密码为空")
|
appCtx.toastOnUi("账号或密码为空")
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.legado.app.help
|
|||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import io.legado.app.constant.PreferKey
|
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.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.data.entities.BookProgress
|
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.compress.ZipUtils
|
||||||
import io.legado.app.utils.defaultSharedPreferences
|
import io.legado.app.utils.defaultSharedPreferences
|
||||||
import io.legado.app.utils.fromJsonObject
|
import io.legado.app.utils.fromJsonObject
|
||||||
import io.legado.app.utils.getPrefString
|
|
||||||
import io.legado.app.utils.isJson
|
import io.legado.app.utils.isJson
|
||||||
import io.legado.app.utils.normalizeFileName
|
import io.legado.app.utils.normalizeFileName
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -287,11 +287,11 @@ class WebDavManager(
|
|||||||
|
|
||||||
private fun readConfig(): WebDavConfig {
|
private fun readConfig(): WebDavConfig {
|
||||||
return WebDavConfig(
|
return WebDavConfig(
|
||||||
url = appCtx.getPrefString(PreferKey.webDavUrl, "") ?: "",
|
url = BackupConfig.webDavUrl,
|
||||||
account = appCtx.getPrefString(PreferKey.webDavAccount, "") ?: "",
|
account = BackupConfig.webDavAccount,
|
||||||
password = appCtx.getPrefString(PreferKey.webDavPassword, "") ?: "",
|
password = BackupConfig.webDavPassword,
|
||||||
dir = appCtx.getPrefString(PreferKey.webDavDir, "legado") ?: "legado",
|
dir = BackupConfig.webDavDir,
|
||||||
deviceName = appCtx.getPrefString(PreferKey.webDavDeviceName, "") ?: ""
|
deviceName = BackupConfig.webDavDeviceName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ import io.legado.app.utils.LogUtils
|
|||||||
import io.legado.app.utils.compress.ZipUtils
|
import io.legado.app.utils.compress.ZipUtils
|
||||||
import io.legado.app.utils.defaultSharedPreferences
|
import io.legado.app.utils.defaultSharedPreferences
|
||||||
import io.legado.app.utils.fromJsonArray
|
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.getPrefString
|
||||||
import io.legado.app.utils.isContentScheme
|
import io.legado.app.utils.isContentScheme
|
||||||
import io.legado.app.utils.isJsonArray
|
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)
|
appCtx.toastOnUi(R.string.restore_success)
|
||||||
withContext(Main) {
|
withContext(Main) {
|
||||||
delay(100)
|
delay(100)
|
||||||
|
|||||||
@@ -7,18 +7,16 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import androidx.core.content.edit
|
|
||||||
import androidx.core.widget.doAfterTextChanged
|
import androidx.core.widget.doAfterTextChanged
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseFragment
|
import io.legado.app.base.BaseFragment
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.constant.PreferKey
|
|
||||||
import io.legado.app.databinding.FragmentWebdavAuthBinding
|
import io.legado.app.databinding.FragmentWebdavAuthBinding
|
||||||
import io.legado.app.domain.usecase.WebDavBackupUseCase
|
import io.legado.app.domain.usecase.WebDavBackupUseCase
|
||||||
import io.legado.app.exception.NoStackTraceException
|
import io.legado.app.exception.NoStackTraceException
|
||||||
import io.legado.app.help.config.LocalConfig
|
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.coroutine.Coroutine
|
||||||
import io.legado.app.help.storage.Restore
|
import io.legado.app.help.storage.Restore
|
||||||
import io.legado.app.lib.dialogs.alert
|
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?) {
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
|
||||||
|
|
||||||
val urls = listOf(
|
val urls = listOf(
|
||||||
"https://dav.jianguoyun.com/dav/",
|
"https://dav.jianguoyun.com/dav/",
|
||||||
"https://webdav.aliyundrive.com/",
|
"https://webdav.aliyundrive.com/",
|
||||||
@@ -87,8 +83,8 @@ class WebDavFragment : BaseFragment(R.layout.fragment_webdav_auth) {
|
|||||||
|
|
||||||
binding.editUrl.setAdapter(adapter)
|
binding.editUrl.setAdapter(adapter)
|
||||||
|
|
||||||
binding.editAccount.setText(prefs.getString(PreferKey.webDavAccount, ""))
|
binding.editAccount.setText(BackupConfig.webDavAccount)
|
||||||
binding.editPassword.setText(prefs.getString(PreferKey.webDavPassword, ""))
|
binding.editPassword.setText(BackupConfig.webDavPassword)
|
||||||
binding.editPassword.inputType =
|
binding.editPassword.inputType =
|
||||||
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
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) {
|
fun saveWebDavConfig(config: WebDavConfig, onSaved: (() -> Unit)? = null) {
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
|
BackupConfig.webDavUrl = config.url
|
||||||
putString(PreferKey.webDavUrl, config.url)
|
BackupConfig.webDavAccount = config.account
|
||||||
putString(PreferKey.webDavAccount, config.account)
|
BackupConfig.webDavPassword = config.password
|
||||||
putString(PreferKey.webDavPassword, config.password)
|
|
||||||
}
|
|
||||||
|
|
||||||
onSaved?.invoke()
|
onSaved?.invoke()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user