From f2a38a420b3c94cd49352c4806f9f89d31a01e5a Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 18 Feb 2020 20:44:24 +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 --- .../java/io/legado/app/ui/download/DownloadActivity.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 2b78c4d6a..0eef856a6 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 @@ -36,6 +36,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow FileChooserDialog.CallBack, DownloadAdapter.CallBack { private val exportRequestCode = 32 + private val exportBookPathKey = "exportBookPath" lateinit var adapter: DownloadAdapter private var bookshelfLiveData: LiveData>? = null private var menu: Menu? = null @@ -132,7 +133,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> when (index) { 0 -> { - val path = ACache.get(this@DownloadActivity).getAsString("exportBookPath") + val path = ACache.get(this@DownloadActivity).getAsString(exportBookPathKey) if (path.isNullOrEmpty()) { toast("没有默认路径") } else { @@ -172,6 +173,7 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow 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) } @@ -184,6 +186,11 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow when (requestCode) { exportRequestCode -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> + contentResolver.takePersistableUriPermission( + uri, + 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) }