feat: 优化代码

pull/103/head
kunfei 5 years ago
parent e478e11f22
commit 96a9b5ffff
  1. 22
      app/src/main/java/io/legado/app/ui/download/DownloadViewModel.kt

@ -3,9 +3,11 @@ package io.legado.app.ui.download
import android.app.Application
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
import io.legado.app.utils.FileUtils
import io.legado.app.utils.isContentPath
import java.io.File
class DownloadViewModel(application: Application) : BaseViewModel(application) {
@ -13,18 +15,30 @@ class DownloadViewModel(application: Application) : BaseViewModel(application) {
fun export(path: String, book: Book) {
execute {
if (path.isContentPath()) {
val uri = Uri.parse(path)
DocumentFile.fromTreeUri(context, uri)
?.createFile("txt", book.name)
?.let {
context.contentResolver.openOutputStream(it.uri)?.let {
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach {
export(it.uri, book)
}
} else {
FileUtils.createFolderIfNotExist(path).let {
export(it, book)
}
}
}.onError {
toast(it.localizedMessage ?: "ERROR")
}
}
private fun export(uri: Uri, book: Book) {
}
private fun export(file: File, book: Book) {
}
}
Loading…
Cancel
Save