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

This commit is contained in:
kunfei
2023-03-03 23:43:44 +08:00
parent 305f728c60
commit c1e358e713
2 changed files with 18 additions and 1 deletions

View File

@@ -6,9 +6,11 @@ import io.legado.app.constant.AppLog
import io.legado.app.constant.BookType
import io.legado.app.exception.NoStackTraceException
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.remote.RemoteBook
import io.legado.app.model.remote.RemoteBookWebDav
import io.legado.app.utils.ACache
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
@@ -76,6 +78,17 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
fun initData(onSuccess: () -> Unit) {
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
?: throw NoStackTraceException("webDav没有配置")
}.onError {

View File

@@ -46,7 +46,11 @@ class ServerConfigDialog : BaseDialogFragment(R.layout.dialog_webdav_server, tru
when (item.itemId) {
R.id.menu_save -> {
val data = getConfigData()
ACache.get().put("remoteServerConfig", GSON.toJson(data))
if (data.isEmpty()) {
ACache.get().remove("remoteServerConfig")
} else {
ACache.get().put("remoteServerConfig", GSON.toJson(data))
}
dismissAllowingStateLoss()
}
}