pull/1994/head
kunfei 2 years ago
parent 4da7880bb3
commit ecbe571c51
  1. 3
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt
  4. 14
      app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt
  5. 12
      app/src/main/res/menu/book_remote.xml

@ -19,6 +19,7 @@ import java.io.FileOutputStream
import java.io.InputStream import java.io.InputStream
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.URL import java.net.URL
import java.net.URLDecoder
import java.net.URLEncoder import java.net.URLEncoder
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.ZoneOffset import java.time.ZoneOffset
@ -125,7 +126,7 @@ open class WebDav(val path: String, val authorization: Authorization) {
httpUrl?.let { urlStr -> httpUrl?.let { urlStr ->
val baseUrl = NetworkUtils.getBaseUrl(urlStr) val baseUrl = NetworkUtils.getBaseUrl(urlStr)
for (element in elements) { for (element in elements) {
val href = element.getElementsByTag("d:href")[0].text() val href = URLDecoder.decode(element.getElementsByTag("d:href")[0].text(), "UTF-8")
if (!href.endsWith("/")) { if (!href.endsWith("/")) {
val fileName = href.substring(href.lastIndexOf("/") + 1) val fileName = href.substring(href.lastIndexOf("/") + 1)
val webDavFile: WebDav val webDavFile: WebDav

@ -10,9 +10,11 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityImportBookBinding import io.legado.app.databinding.ActivityImportBookBinding
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.remote.manager.RemoteBookWebDav import io.legado.app.ui.book.remote.manager.RemoteBookWebDav
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.dialog.WaitDialog import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -72,9 +74,8 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_refresh -> { R.id.menu_refresh -> upPath()
upPath() R.id.menu_log -> showDialogFragment<AppLogDialog>()
}
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }

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

@ -16,7 +16,6 @@ import io.legado.app.utils.readBytes
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
import java.net.URLDecoder
object RemoteBookWebDav : RemoteBookManager() { object RemoteBookWebDav : RemoteBookManager() {
val rootBookUrl get() = "${AppWebDav.rootWebDavUrl}${remoteBookFolder}" val rootBookUrl get() = "${AppWebDav.rootWebDavUrl}${remoteBookFolder}"
@ -44,26 +43,23 @@ object RemoteBookWebDav : RemoteBookManager() {
val remoteWebDavFileList: List<WebDavFile> = WebDav(path, it).listFiles() val remoteWebDavFileList: List<WebDavFile> = WebDav(path, it).listFiles()
//转化远程文件信息到本地对象 //转化远程文件信息到本地对象
remoteWebDavFileList.forEach { webDavFile -> remoteWebDavFileList.forEach { webDavFile ->
var webDavFileName = webDavFile.displayName
webDavFileName = URLDecoder.decode(webDavFileName, "utf-8")
if (webDavFile.isDir) { if (webDavFile.isDir) {
remoteBooks.add( remoteBooks.add(
RemoteBook( RemoteBook(
webDavFileName, webDavFile.path, webDavFile.size, webDavFile.displayName, webDavFile.path, webDavFile.size,
"folder", webDavFile.lastModify, false "folder", webDavFile.lastModify, false
) )
) )
} else { } else {
//分割后缀 //分割后缀
val fileExtension = webDavFileName.substringAfterLast(".") val fileExtension = webDavFile.displayName.substringAfterLast(".")
//扩展名符合阅读的格式则认为是书籍 //扩展名符合阅读的格式则认为是书籍
if (bookFileRegex.matches(webDavFileName)) { if (bookFileRegex.matches(webDavFile.displayName)) {
val isOnBookShelf = LocalBook.isOnBookShelf(webDavFileName) val isOnBookShelf = LocalBook.isOnBookShelf(webDavFile.displayName)
remoteBooks.add( remoteBooks.add(
RemoteBook( RemoteBook(
webDavFileName, webDavFile.path, webDavFile.size, webDavFile.displayName, webDavFile.path, webDavFile.size,
fileExtension, webDavFile.lastModify, isOnBookShelf fileExtension, webDavFile.lastModify, isOnBookShelf
) )
) )

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