优化
This commit is contained in:
@@ -2,7 +2,7 @@ package io.legado.app.ui.book.remote
|
|||||||
|
|
||||||
data class RemoteBook(
|
data class RemoteBook(
|
||||||
val filename: String,
|
val filename: String,
|
||||||
val urlName: String,
|
val path: String,
|
||||||
val size: Long,
|
val size: Long,
|
||||||
val contentType: String,
|
val contentType: String,
|
||||||
val lastModify: Long,
|
val lastModify: Long,
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ class RemoteBookActivity : VMBaseActivity<ActivityRemoteBookBinding, RemoteBookV
|
|||||||
return super.onCompatOptionsItemSelected(item)
|
return super.onCompatOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun openDir(url: String) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun addToBookshelf(remoteBook: RemoteBook) {
|
override fun addToBookshelf(remoteBook: RemoteBook) {
|
||||||
waitDialog.show()
|
waitDialog.show()
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class RemoteBookAdapter (context: Context, val callBack: CallBack) :
|
|||||||
binding.btnDownload.setOnClickListener {
|
binding.btnDownload.setOnClickListener {
|
||||||
getItem(holder.layoutPosition)?.let {
|
getItem(holder.layoutPosition)?.let {
|
||||||
if (it.isDir) {
|
if (it.isDir) {
|
||||||
|
callBack.openDir(it.path)
|
||||||
} else {
|
} else {
|
||||||
callBack.addToBookshelf(it)
|
callBack.addToBookshelf(it)
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,7 @@ class RemoteBookAdapter (context: Context, val callBack: CallBack) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface CallBack {
|
interface CallBack {
|
||||||
|
fun openDir(url: String)
|
||||||
fun addToBookshelf(remoteBook: RemoteBook)
|
fun addToBookshelf(remoteBook: RemoteBook)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,14 +45,12 @@ object RemoteBookWebDav : RemoteBookManager() {
|
|||||||
//转化远程文件信息到本地对象
|
//转化远程文件信息到本地对象
|
||||||
remoteWebDavFileList.forEach { webDavFile ->
|
remoteWebDavFileList.forEach { webDavFile ->
|
||||||
var webDavFileName = webDavFile.displayName
|
var webDavFileName = webDavFile.displayName
|
||||||
var webDavUrlName = "${remoteBookUrl}${File.separator}${webDavFile.displayName}"
|
|
||||||
webDavFileName = URLDecoder.decode(webDavFileName, "utf-8")
|
webDavFileName = URLDecoder.decode(webDavFileName, "utf-8")
|
||||||
webDavUrlName = URLDecoder.decode(webDavUrlName, "utf-8")
|
|
||||||
|
|
||||||
if (webDavFile.isDir) {
|
if (webDavFile.isDir) {
|
||||||
remoteBooks.add(
|
remoteBooks.add(
|
||||||
RemoteBook(
|
RemoteBook(
|
||||||
webDavFileName, webDavUrlName, webDavFile.size,
|
webDavFileName, webDavFile.path, webDavFile.size,
|
||||||
"folder", webDavFile.lastModify, false
|
"folder", webDavFile.lastModify, false
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -65,7 +63,7 @@ object RemoteBookWebDav : RemoteBookManager() {
|
|||||||
val isOnBookShelf = LocalBook.isOnBookShelf(webDavFileName)
|
val isOnBookShelf = LocalBook.isOnBookShelf(webDavFileName)
|
||||||
remoteBooks.add(
|
remoteBooks.add(
|
||||||
RemoteBook(
|
RemoteBook(
|
||||||
webDavFileName, webDavUrlName, webDavFile.size,
|
webDavFileName, webDavFile.path, webDavFile.size,
|
||||||
fileExtension, webDavFile.lastModify, isOnBookShelf
|
fileExtension, webDavFile.lastModify, isOnBookShelf
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -81,7 +79,7 @@ object RemoteBookWebDav : RemoteBookManager() {
|
|||||||
*/
|
*/
|
||||||
override suspend fun getRemoteBook(remoteBook: RemoteBook): Uri? {
|
override suspend fun getRemoteBook(remoteBook: RemoteBook): Uri? {
|
||||||
return AppWebDav.authorization?.let {
|
return AppWebDav.authorization?.let {
|
||||||
val webdav = WebDav(remoteBook.urlName, it)
|
val webdav = WebDav(remoteBook.path, it)
|
||||||
webdav.download().let { bytes ->
|
webdav.download().let { bytes ->
|
||||||
LocalBook.saveBookFile(bytes, remoteBook.filename)
|
LocalBook.saveBookFile(bytes, remoteBook.filename)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user