mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -19,6 +19,7 @@ import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import java.net.URLDecoder
|
||||
import java.net.URLEncoder
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneOffset
|
||||
@@ -125,7 +126,7 @@ open class WebDav(val path: String, val authorization: Authorization) {
|
||||
httpUrl?.let { urlStr ->
|
||||
val baseUrl = NetworkUtils.getBaseUrl(urlStr)
|
||||
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("/")) {
|
||||
val fileName = href.substring(href.lastIndexOf("/") + 1)
|
||||
val webDavFile: WebDav
|
||||
|
||||
@@ -10,9 +10,11 @@ import io.legado.app.R
|
||||
import io.legado.app.base.VMBaseActivity
|
||||
import io.legado.app.databinding.ActivityImportBookBinding
|
||||
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.widget.SelectActionBar
|
||||
import io.legado.app.ui.widget.dialog.WaitDialog
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -72,9 +74,8 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
|
||||
|
||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_refresh -> {
|
||||
upPath()
|
||||
}
|
||||
R.id.menu_refresh -> upPath()
|
||||
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
||||
}
|
||||
return super.onCompatOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ class RemoteBookViewModel(application: Application): BaseViewModel(application){
|
||||
val bookList = RemoteBookWebDav.getRemoteBookList(path)
|
||||
dataCallback?.setItems(bookList)
|
||||
}.onError {
|
||||
AppLog.put("获取webDav书籍出错\n${it.localizedMessage}", it)
|
||||
context.toastOnUi("获取webDav书籍出错\n${it.localizedMessage}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import io.legado.app.utils.readBytes
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
import java.net.URLDecoder
|
||||
|
||||
object RemoteBookWebDav : RemoteBookManager() {
|
||||
val rootBookUrl get() = "${AppWebDav.rootWebDavUrl}${remoteBookFolder}"
|
||||
@@ -44,26 +43,23 @@ object RemoteBookWebDav : RemoteBookManager() {
|
||||
val remoteWebDavFileList: List<WebDavFile> = WebDav(path, it).listFiles()
|
||||
//转化远程文件信息到本地对象
|
||||
remoteWebDavFileList.forEach { webDavFile ->
|
||||
var webDavFileName = webDavFile.displayName
|
||||
webDavFileName = URLDecoder.decode(webDavFileName, "utf-8")
|
||||
|
||||
if (webDavFile.isDir) {
|
||||
remoteBooks.add(
|
||||
RemoteBook(
|
||||
webDavFileName, webDavFile.path, webDavFile.size,
|
||||
webDavFile.displayName, webDavFile.path, webDavFile.size,
|
||||
"folder", webDavFile.lastModify, false
|
||||
)
|
||||
)
|
||||
} else {
|
||||
//分割后缀
|
||||
val fileExtension = webDavFileName.substringAfterLast(".")
|
||||
val fileExtension = webDavFile.displayName.substringAfterLast(".")
|
||||
|
||||
//扩展名符合阅读的格式则认为是书籍
|
||||
if (bookFileRegex.matches(webDavFileName)) {
|
||||
val isOnBookShelf = LocalBook.isOnBookShelf(webDavFileName)
|
||||
if (bookFileRegex.matches(webDavFile.displayName)) {
|
||||
val isOnBookShelf = LocalBook.isOnBookShelf(webDavFile.displayName)
|
||||
remoteBooks.add(
|
||||
RemoteBook(
|
||||
webDavFileName, webDavFile.path, webDavFile.size,
|
||||
webDavFile.displayName, webDavFile.path, webDavFile.size,
|
||||
fileExtension, webDavFile.lastModify, isOnBookShelf
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
<?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">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:ignore="AlwaysShowAction">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_refresh"
|
||||
android:title="@string/refresh"
|
||||
android:icon="@drawable/ic_refresh_black_24dp"
|
||||
android:title="@string/refresh"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_log"
|
||||
android:title="@string/log"
|
||||
android:icon="@drawable/ic_cfg_about"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
Reference in New Issue
Block a user