mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
远程书籍单独配置webDav,多个webDav看情况再添加
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user