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