feat(book/remote): save remoteBookFile to defaultBookTreeUri

pull/1903/head
Xwite 3 years ago
parent 2649e1b6ba
commit 787393d83d
  1. 2
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookManager.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt
  4. 24
      app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt

@ -243,7 +243,7 @@ object LocalBook {
return type ?: fileType
}
private fun saveBookFile(
fun saveBookFile(
bytes: ByteArray,
fileName: String
): Uri {

@ -12,5 +12,5 @@ abstract class RemoteBookManager {
/**
* @return String下载到本地的路径
*/
abstract suspend fun getRemoteBook(remoteBook: RemoteBook): String?
abstract suspend fun getRemoteBook(remoteBook: RemoteBook): Uri?
}

@ -73,7 +73,7 @@ class RemoteBookViewModel(application: Application): BaseViewModel(application){
execute {
val downloadBookPath = RemoteBookWebDav.getRemoteBook(remoteBook)
downloadBookPath?.let {
LocalBook.importFile(Uri.parse(it))
LocalBook.importFile(it)
}
}.onFinally {
finally.invoke()

@ -9,6 +9,7 @@ import io.legado.app.help.AppWebDav
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.webdav.WebDav
import io.legado.app.lib.webdav.WebDavFile
import io.legado.app.model.localBook.LocalBook
import io.legado.app.ui.book.remote.RemoteBook
import io.legado.app.ui.book.remote.RemoteBookManager
import io.legado.app.utils.*
@ -18,7 +19,6 @@ import java.io.File
object RemoteBookWebDav : RemoteBookManager() {
private val remoteBookUrl get() = "${rootWebDavUrl}${remoteBookFolder}"
private val localSaveFolder get() = "${appCtx.externalFiles.absolutePath}${File.separator}${remoteBookFolder}"
init {
runBlocking {
@ -83,23 +83,21 @@ object RemoteBookWebDav : RemoteBookManager() {
return remoteBooks
}
override suspend fun getRemoteBook(remoteBook: RemoteBook): String? {
val saveFilePath= "${localSaveFolder}${File.separator}${remoteBook.filename}"
kotlin.runCatching {
override suspend fun getRemoteBook(remoteBook: RemoteBook): Uri? {
return kotlin.runCatching {
AppWebDav.authorization?.let {
FileUtils.createFolderIfNotExist(localSaveFolder).run {
val webdav = WebDav(
remoteBook.urlName,
it
)
webdav.downloadTo(saveFilePath, true)
val webdav = WebDav(
remoteBook.urlName,
it
)
webdav.download().let { bytes ->
LocalBook.saveBookFile(bytes, remoteBook.filename)
}
}
}.onFailure {
it.printStackTrace()
return null
}
return saveFilePath
null
}.getOrNull()
}
/**

Loading…
Cancel
Save