pull/1977/head
kunfei 2 years ago
parent 37bca90adf
commit 646f892f3e
  1. 4
      app/src/main/java/io/legado/app/help/AppWebDav.kt
  2. 18
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt
  4. 18
      app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt
  5. 11
      app/src/main/res/menu/book_remote.xml

@ -31,7 +31,7 @@ import java.util.*
* webDav初始化会访问网络,不要放到主线程
*/
object AppWebDav {
const val defaultWebDavUrl = "https://dav.jianguoyun.com/dav/"
private const val defaultWebDavUrl = "https://dav.jianguoyun.com/dav/"
private val zipFilePath = "${appCtx.externalFiles.absolutePath}${File.separator}backup.zip"
private val bookProgressUrl get() = "${rootWebDavUrl}bookProgress/"
private val exportsWebDavUrl get() = "${rootWebDavUrl}books/"
@ -48,7 +48,7 @@ object AppWebDav {
}
}
private val rootWebDavUrl: String
val rootWebDavUrl: String
get() {
val configUrl = appCtx.getPrefString(PreferKey.webDavUrl)?.trim()
var url = if (configUrl.isNullOrEmpty()) defaultWebDavUrl else configUrl

@ -2,6 +2,8 @@ package io.legado.app.ui.book.remote
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.activity.viewModels
import androidx.core.view.isGone
import androidx.recyclerview.widget.LinearLayoutManager
@ -50,13 +52,27 @@ class RemoteBookActivity : VMBaseActivity<ActivityRemoteBookBinding,RemoteBookVi
viewModel.loadRemoteBookList()
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_remote, menu)
return super.onCompatCreateOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_refresh -> {
viewModel.loadRemoteBookList()
}
}
return super.onCompatOptionsItemSelected(item)
}
@SuppressLint("NotifyDataSetChanged")
override fun addToBookshelf(remoteBook: RemoteBook) {
waitDialog.show()
viewModel.addToBookshelf(remoteBook, success = {
toastOnUi(getString(R.string.download_book_success))
adapter.notifyDataSetChanged()
}){
}) {
waitDialog.dismiss()
}
}

@ -54,6 +54,8 @@ class RemoteBookViewModel(application: Application): BaseViewModel(application){
dataCallback?.clear()
val bookList = RemoteBookWebDav.getRemoteBookList()
dataCallback?.setItems(bookList)
}.onError {
context.toastOnUi("获取webDav书籍出错\n${it.localizedMessage}")
}
}

@ -3,17 +3,14 @@ package io.legado.app.ui.book.remote.manager
import android.net.Uri
import io.legado.app.constant.AppPattern.bookFileRegex
import io.legado.app.constant.PreferKey
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.AppWebDav
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.webdav.WebDav
import io.legado.app.lib.webdav.WebDavFile
import io.legado.app.model.localBook.LocalBook
import io.legado.app.ui.book.remote.RemoteBook
import io.legado.app.ui.book.remote.RemoteBookManager
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.getPrefString
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.readBytes
import kotlinx.coroutines.runBlocking
@ -22,7 +19,7 @@ import java.io.File
import java.net.URLDecoder
object RemoteBookWebDav : RemoteBookManager() {
private val remoteBookUrl get() = "${rootWebDavUrl}${remoteBookFolder}"
private val remoteBookUrl get() = "${AppWebDav.rootWebDavUrl}${remoteBookFolder}"
init {
runBlocking {
@ -30,19 +27,6 @@ object RemoteBookWebDav : RemoteBookManager() {
}
}
private val rootWebDavUrl: String
get() {
val configUrl = appCtx.getPrefString(PreferKey.webDavUrl)?.trim()
var url = if (configUrl.isNullOrEmpty()) AppWebDav.defaultWebDavUrl else configUrl
if (!url.endsWith("/")) url = "${url}/"
AppConfig.webDavDir?.trim()?.let {
if (it.isNotEmpty()) {
url = "${url}${it}/"
}
}
return url
}
override suspend fun initRemoteContext() {
AppWebDav.authorization?.let {
WebDav(remoteBookUrl, it).makeAsDir()

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_refresh"
android:title="@string/refresh"
android:icon="@drawable/ic_refresh_black_24dp"
app:showAsAction="always" />
</menu>
Loading…
Cancel
Save