From 99bbdb558d23f29e684806c3963fc630641cf548 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 19 Feb 2020 14:17:17 +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/DownloadActivity.kt | 28 ++++++++++--------- .../app/ui/download/DownloadViewModel.kt | 6 ++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 20 insertions(+), 15 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 0eef856a6..ef1d87e68 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 @@ -8,6 +8,7 @@ import android.view.MenuItem import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager +import com.google.android.material.snackbar.Snackbar import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity @@ -19,10 +20,7 @@ import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.service.help.Download import io.legado.app.ui.filechooser.FileChooserDialog -import io.legado.app.utils.ACache -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModel -import io.legado.app.utils.observeEvent +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_download.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.IO @@ -137,9 +135,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow if (path.isNullOrEmpty()) { toast("没有默认路径") } else { - adapter.getItem(exportPosition)?.let { - viewModel.export(path, it) - } + startExport(path) } } 1 -> { @@ -170,13 +166,21 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow }.show() } + private fun startExport(path: String) { + adapter.getItem(exportPosition)?.let { book -> + Snackbar.make(title_bar, R.string.exporting, Snackbar.LENGTH_INDEFINITE) + .show() + viewModel.export(path, book) { + title_bar.snackbar(it) + } + } + } + override fun onFilePicked(requestCode: Int, currentPath: String) { when (requestCode) { exportRequestCode -> { ACache.get(this@DownloadActivity).put(exportBookPathKey, currentPath) - adapter.getItem(exportPosition)?.let { - viewModel.export(currentPath, it) - } + startExport(currentPath) } } } @@ -191,9 +195,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) ACache.get(this@DownloadActivity).put(exportBookPathKey, uri.toString()) - adapter.getItem(exportPosition)?.let { - viewModel.export(uri.toString(), it) - } + startExport(uri.toString()) } } 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 069acf6f4..dc001a17b 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 @@ -18,7 +18,7 @@ import java.io.File class DownloadViewModel(application: Application) : BaseViewModel(application) { - fun export(path: String, book: Book) { + fun export(path: String, book: Book, finally: (msg: String) -> Unit) { execute { if (path.isContentPath()) { val uri = Uri.parse(path) @@ -29,7 +29,9 @@ class DownloadViewModel(application: Application) : BaseViewModel(application) { export(FileUtils.createFolderIfNotExist(path), book) } }.onError { - toast(it.localizedMessage ?: "ERROR") + finally(it.localizedMessage ?: "ERROR") + }.onSuccess { + finally(context.getString(R.string.success)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c47e61a4e..2c8e51656 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -580,6 +580,7 @@ 音频 转到后台 正在导入 + 正在导出 自定义翻页按键 上一页按键 下一页按键