From 96a9b5ffffef561aace0be7738b4394b1c65b3b6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 16 Feb 2020 20:43:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/download/DownloadViewModel.kt | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadViewModel.kt b/app/src/main/java/io/legado/app/ui/download/DownloadViewModel.kt index d65e37492..2763132eb 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadViewModel.kt +++ b/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 { - 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 { - - } + if (path.isContentPath()) { + val uri = Uri.parse(path) + DocumentFile.fromTreeUri(context, uri) + ?.createFile("txt", book.name) + ?.let { + 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) { + + } + } \ No newline at end of file