mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user