远程书籍单独配置webDav,多个webDav看情况再添加

This commit is contained in:
kunfei
2023-03-03 23:43:44 +08:00
parent 688acbed70
commit d90f80e648
2 changed files with 18 additions and 1 deletions
@@ -6,9 +6,11 @@ import io.legado.app.constant.AppLog
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.AppWebDav import io.legado.app.help.AppWebDav
import io.legado.app.lib.webdav.Authorization
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.remote.RemoteBook import io.legado.app.model.remote.RemoteBook
import io.legado.app.model.remote.RemoteBookWebDav import io.legado.app.model.remote.RemoteBookWebDav
import io.legado.app.utils.ACache
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.awaitClose
@@ -76,6 +78,17 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
fun initData(onSuccess: () -> Unit) { fun initData(onSuccess: () -> Unit) {
execute { execute {
val config = ACache.get().getAsJSONObject("remoteServerConfig")
if (config != null && config.has("url")) {
val url = config.getString("url")
if (url.isNotBlank()) {
val user = config.getString("user")
val password = config.getString("password")
val authorization = Authorization(user, password)
remoteBookWebDav = RemoteBookWebDav(url, authorization)
return@execute
}
}
remoteBookWebDav = AppWebDav.defaultBookWebDav remoteBookWebDav = AppWebDav.defaultBookWebDav
?: throw NoStackTraceException("webDav没有配置") ?: throw NoStackTraceException("webDav没有配置")
}.onError { }.onError {
@@ -46,7 +46,11 @@ class ServerConfigDialog : BaseDialogFragment(R.layout.dialog_webdav_server, tru
when (item.itemId) { when (item.itemId) {
R.id.menu_save -> { R.id.menu_save -> {
val data = getConfigData() val data = getConfigData()
if (data.isEmpty()) {
ACache.get().remove("remoteServerConfig")
} else {
ACache.get().put("remoteServerConfig", GSON.toJson(data)) ACache.get().put("remoteServerConfig", GSON.toJson(data))
}
dismissAllowingStateLoss() dismissAllowingStateLoss()
} }
} }