This commit is contained in:
kunfei
2022-06-20 22:05:27 +08:00
parent 6619a3a97c
commit c9ccda2ca7
4 changed files with 10 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ package io.legado.app.ui.book.remote
data class RemoteBook(
val filename: String,
val urlName: String,
val path: String,
val size: Long,
val contentType: String,
val lastModify: Long,

View File

@@ -67,6 +67,10 @@ class RemoteBookActivity : VMBaseActivity<ActivityRemoteBookBinding, RemoteBookV
return super.onCompatOptionsItemSelected(item)
}
override fun openDir(url: String) {
}
@SuppressLint("NotifyDataSetChanged")
override fun addToBookshelf(remoteBook: RemoteBook) {
waitDialog.show()

View File

@@ -51,7 +51,7 @@ class RemoteBookAdapter (context: Context, val callBack: CallBack) :
binding.btnDownload.setOnClickListener {
getItem(holder.layoutPosition)?.let {
if (it.isDir) {
callBack.openDir(it.path)
} else {
callBack.addToBookshelf(it)
}
@@ -61,6 +61,7 @@ class RemoteBookAdapter (context: Context, val callBack: CallBack) :
}
interface CallBack {
fun openDir(url: String)
fun addToBookshelf(remoteBook: RemoteBook)
}
}

View File

@@ -45,14 +45,12 @@ object RemoteBookWebDav : RemoteBookManager() {
//转化远程文件信息到本地对象
remoteWebDavFileList.forEach { webDavFile ->
var webDavFileName = webDavFile.displayName
var webDavUrlName = "${remoteBookUrl}${File.separator}${webDavFile.displayName}"
webDavFileName = URLDecoder.decode(webDavFileName, "utf-8")
webDavUrlName = URLDecoder.decode(webDavUrlName, "utf-8")
if (webDavFile.isDir) {
remoteBooks.add(
RemoteBook(
webDavFileName, webDavUrlName, webDavFile.size,
webDavFileName, webDavFile.path, webDavFile.size,
"folder", webDavFile.lastModify, false
)
)
@@ -65,7 +63,7 @@ object RemoteBookWebDav : RemoteBookManager() {
val isOnBookShelf = LocalBook.isOnBookShelf(webDavFileName)
remoteBooks.add(
RemoteBook(
webDavFileName, webDavUrlName, webDavFile.size,
webDavFileName, webDavFile.path, webDavFile.size,
fileExtension, webDavFile.lastModify, isOnBookShelf
)
)
@@ -81,7 +79,7 @@ object RemoteBookWebDav : RemoteBookManager() {
*/
override suspend fun getRemoteBook(remoteBook: RemoteBook): Uri? {
return AppWebDav.authorization?.let {
val webdav = WebDav(remoteBook.urlName, it)
val webdav = WebDav(remoteBook.path, it)
webdav.download().let { bytes ->
LocalBook.saveBookFile(bytes, remoteBook.filename)
}