From 87481f12a1100a95e656795842791b3113208783 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 16 Feb 2020 19:24:12 +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 --- .../io/legado/app/ui/download/DownloadActivity.kt | 2 +- .../io/legado/app/ui/download/DownloadAdapter.kt | 10 +++++++++- .../io/legado/app/ui/download/DownloadViewModel.kt | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt index 0275873d4..a18e57ab5 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt @@ -131,7 +131,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow exportRequestCode -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> adapter.getItem(exportPosition)?.let { - viewModel.export(it, uri) + viewModel.export(uri, it) } } } diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt index 6dbbdfa78..d0161bd88 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt @@ -7,6 +7,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book import kotlinx.android.synthetic.main.item_download.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.toast class DownloadAdapter(context: Context, private val callBack: CallBack) : @@ -36,7 +37,14 @@ class DownloadAdapter(context: Context, private val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder) { holder.itemView.tv_export.onClick { - callBack.export(holder.layoutPosition) + getItem(holder.layoutPosition)?.let { + val cacheSize = cacheChapters[it.bookUrl]?.size ?: 0 + if (cacheSize < it.totalChapterNum) { + context.toast("未下载完成") + } else { + callBack.export(holder.layoutPosition) + } + } } } 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 0ce1eecf0..e6375cc09 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 @@ -2,6 +2,8 @@ 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 @@ -9,9 +11,17 @@ import io.legado.app.data.entities.Book class DownloadViewModel(application: Application) : BaseViewModel(application) { - fun export(book: Book, uri: Uri) { + fun export(uri: Uri, book: Book) { execute { - + DocumentFile.fromTreeUri(context, uri) + ?.createFile("txt", book.name) + ?.let { + context.contentResolver.openOutputStream(it.uri)?.let { + App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { + + } + } + } } }