mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
fix: 远程webDav初始化时服务器id错误 默认webDavId为-1
This commit is contained in:
parent
0155358081
commit
6d11d4e244
@ -25,6 +25,8 @@ object AppConst {
|
||||
|
||||
const val MAX_THREAD = 9
|
||||
|
||||
const val DEFAULT_WEBDAV_ID = -1
|
||||
|
||||
val SCRIPT_ENGINE: RhinoScriptEngine by lazy {
|
||||
RhinoScriptEngine()
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.legado.app.lib.webdav
|
||||
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Server.WebDavConfig
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import okhttp3.Credentials
|
||||
import java.nio.charset.Charset
|
||||
@ -29,4 +30,6 @@ data class Authorization(
|
||||
} ?: throw WebDavException("Unexpected WebDav Authorization")
|
||||
}
|
||||
|
||||
constructor(webDavConfig: WebDavConfig): this(webDavConfig.username, webDavConfig.password)
|
||||
|
||||
}
|
@ -30,7 +30,8 @@ import java.io.File
|
||||
class RemoteBookActivity : BaseImportBookActivity<ActivityImportBookBinding, RemoteBookViewModel>(),
|
||||
RemoteBookAdapter.CallBack,
|
||||
SelectActionBar.CallBack,
|
||||
ServerConfigDialog.Callback {
|
||||
ServerConfigDialog.Callback,
|
||||
ServersDialog.Callback {
|
||||
override val binding by viewBinding(ActivityImportBookBinding::inflate)
|
||||
override val viewModel by viewModels<RemoteBookViewModel>()
|
||||
private val adapter by lazy { RemoteBookAdapter(this, this) }
|
||||
|
@ -80,17 +80,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
|
||||
fun initData(onSuccess: () -> Unit) {
|
||||
execute {
|
||||
val server = appDb.serverDao.get(AppConfig.remoteServerId)
|
||||
val serverConfig = server?.getConfigJsonObject()
|
||||
if (serverConfig != null && serverConfig.has("url")) {
|
||||
val url = serverConfig.getString("url")
|
||||
if (url.isNotBlank()) {
|
||||
val user = serverConfig.getString("user")
|
||||
val password = serverConfig.getString("password")
|
||||
val authorization = Authorization(user, password)
|
||||
remoteBookWebDav = RemoteBookWebDav(url, authorization, 10001)
|
||||
return@execute
|
||||
}
|
||||
appDb.serverDao.get(AppConfig.remoteServerId)?.getWebDavConfig()?.let {
|
||||
val authorization = Authorization(it)
|
||||
remoteBookWebDav = RemoteBookWebDav(it.url, authorization, AppConfig.remoteServerId)
|
||||
return@execute
|
||||
}
|
||||
remoteBookWebDav = AppWebDav.defaultBookWebDav
|
||||
?: throw NoStackTraceException("webDav没有配置")
|
||||
|
@ -10,6 +10,7 @@ import androidx.appcompat.widget.Toolbar
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import io.legado.app.R
|
||||
import io.legado.app.constant.AppConst.DEFAULT_WEBDAV_ID
|
||||
import io.legado.app.base.BaseDialogFragment
|
||||
import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.base.adapter.RecyclerAdapter
|
||||
@ -61,7 +62,7 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
binding.tvFooterLeft.text = getString(R.string.text_default)
|
||||
binding.tvFooterLeft.visible()
|
||||
binding.tvFooterLeft.setOnClickListener {
|
||||
AppConfig.remoteServerId = 0
|
||||
AppConfig.remoteServerId = DEFAULT_WEBDAV_ID
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
binding.tvCancel.visible()
|
||||
|
Loading…
Reference in New Issue
Block a user