mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
bff2a7f544
commit
18db4e1594
@ -44,6 +44,8 @@ object AppWebDav {
|
||||
var authorization: Authorization? = null
|
||||
private set
|
||||
|
||||
var defaultBookWebDav: RemoteBookWebDav? = null
|
||||
|
||||
val isOk get() = authorization != null
|
||||
|
||||
private val isJianGuoYun get() = rootWebDavUrl.startsWith(defaultWebDavUrl, true)
|
||||
@ -79,14 +81,6 @@ object AppWebDav {
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(NoStackTraceException::class)
|
||||
fun getDefaultRemoteBookWebDav(): RemoteBookWebDav {
|
||||
val rootUrl = "${rootWebDavUrl}books"
|
||||
val authorization = AppWebDav.authorization
|
||||
?: throw NoStackTraceException("webDav没有配置")
|
||||
return RemoteBookWebDav(rootUrl, authorization)
|
||||
}
|
||||
|
||||
suspend fun upConfig() {
|
||||
kotlin.runCatching {
|
||||
authorization = null
|
||||
@ -97,6 +91,8 @@ object AppWebDav {
|
||||
WebDav(rootWebDavUrl, mAuthorization).makeAsDir()
|
||||
WebDav(bookProgressUrl, mAuthorization).makeAsDir()
|
||||
WebDav(exportsWebDavUrl, mAuthorization).makeAsDir()
|
||||
val rootBooksUrl = "${rootWebDavUrl}books"
|
||||
defaultBookWebDav = RemoteBookWebDav(rootBooksUrl, mAuthorization)
|
||||
authorization = mAuthorization
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +76,8 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
|
||||
fun initData(onSuccess: () -> Unit) {
|
||||
execute {
|
||||
val rootUrl = "${AppWebDav.rootWebDavUrl}books"
|
||||
val authorization = AppWebDav.authorization
|
||||
remoteBookWebDav = AppWebDav.defaultBookWebDav
|
||||
?: throw NoStackTraceException("webDav没有配置")
|
||||
remoteBookWebDav = RemoteBookWebDav(rootUrl, authorization)
|
||||
}.onError {
|
||||
context.toastOnUi("初始化webDav出错:${it.localizedMessage}")
|
||||
}.onSuccess {
|
||||
|
@ -19,6 +19,7 @@ import io.legado.app.data.entities.BookChapter
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.databinding.ActivityBookInfoBinding
|
||||
import io.legado.app.databinding.DialogEditTextBinding
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.AppWebDav
|
||||
import io.legado.app.help.book.isAudio
|
||||
import io.legado.app.help.book.isLocal
|
||||
@ -210,8 +211,9 @@ class BookInfoActivity :
|
||||
waitDialog.setText("上传中.....")
|
||||
waitDialog.show()
|
||||
try {
|
||||
AppWebDav.getDefaultRemoteBookWebDav()
|
||||
.upload(it)
|
||||
AppWebDav.defaultBookWebDav
|
||||
?.upload(it)
|
||||
?: throw NoStackTraceException("未配置webDav")
|
||||
//更新书籍最后更新时间,使之比远程书籍的时间新
|
||||
it.lastCheckTime = System.currentTimeMillis()
|
||||
viewModel.saveBook(it)
|
||||
|
@ -114,7 +114,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
if (book.isLocal) {
|
||||
book.tocUrl = ""
|
||||
book.getRemoteUrl()?.let {
|
||||
val bookWebDav = AppWebDav.getDefaultRemoteBookWebDav()
|
||||
val bookWebDav = AppWebDav.defaultBookWebDav
|
||||
?: throw NoStackTraceException("webDav没有配置")
|
||||
val remoteBook = bookWebDav.getRemoteBook(it)
|
||||
if (remoteBook == null) {
|
||||
book.origin = BookType.localTag
|
||||
|
Loading…
Reference in New Issue
Block a user