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 { + + } + } + } } }