From 2ab03229f6773e89950c14aef2990de316658e5a Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 30 Oct 2020 20:17:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Android=2011=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/local/ImportBookActivity.kt | 41 +++++++++---------- .../io/legado/app/ui/filepicker/FilePicker.kt | 8 ++-- .../main/res/layout/activity_import_book.xml | 36 ---------------- 3 files changed, 23 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 1663c38dd..c7209e31b 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -4,11 +4,11 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.net.Uri +import android.os.Build import android.os.Bundle import android.provider.DocumentsContract import android.view.Menu import android.view.MenuItem -import android.view.View import androidx.appcompat.widget.PopupMenu import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData @@ -119,36 +119,32 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } private fun upRootDoc() { - AppConfig.importBookPath?.let { - if (it.isContentPath()) { - val rootUri = Uri.parse(it) - rootDoc = DocumentFile.fromTreeUri(this, rootUri) - subDocs.clear() - } else { - rootDoc = null - subDocs.clear() - path = it - } - } ?: let { - // 没有权限就显示一个授权提示和按钮 - if (PermissionsCompat.check(this, *Permissions.Group.STORAGE)) { - hint_per.visibility = View.GONE - } else { - hint_per.visibility = View.VISIBLE - tv_request_per.onClick { + AppConfig.importBookPath?.let { lastPath -> + when { + lastPath.isContentPath() -> { + val rootUri = Uri.parse(lastPath) + rootDoc = DocumentFile.fromTreeUri(this, rootUri) + subDocs.clear() + upPath() + } + Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> { + FilePicker.selectFolder(this, requestCodeSelectFolder) + } + lastPath.isNotBlank() -> { PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) .onGranted { - hint_per.visibility = View.GONE - initData() - upRootDoc() + rootDoc = null + subDocs.clear() + path = lastPath + upPath() } .request() } + else -> FilePicker.selectFolder(this, requestCodeSelectFolder) } } - upPath() } @SuppressLint("SetTextI18n") @@ -183,6 +179,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } } } ?: let { + if (path.isBlank()) return tv_path.text = path.replace(sdPath, "SD") val docList = arrayListOf() File(path).listFiles()?.forEach { diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt index 3a60cf157..3f1116b89 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt @@ -24,7 +24,7 @@ object FilePicker { otherFun: ((action: String) -> Unit)? = null ) { val selectList = arrayListOf(activity.getString(R.string.sys_folder_picker)) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { selectList.add(activity.getString(R.string.app_folder_picker)) } otherActions?.let { @@ -69,7 +69,7 @@ object FilePicker { otherFun: ((action: String) -> Unit)? = null ) { val selectList = arrayListOf(fragment.getString(R.string.sys_folder_picker)) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { selectList.add(fragment.getString(R.string.app_folder_picker)) } otherActions?.let { @@ -115,7 +115,7 @@ object FilePicker { otherFun: ((action: String) -> Unit)? = null ) { val selectList = arrayListOf(activity.getString(R.string.sys_file_picker)) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { selectList.add(activity.getString(R.string.app_file_picker)) } otherActions?.let { @@ -174,7 +174,7 @@ object FilePicker { otherFun: ((action: String) -> Unit)? = null ) { val selectList = arrayListOf(fragment.getString(R.string.sys_file_picker)) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { selectList.add(fragment.getString(R.string.app_file_picker)) } otherActions?.let { diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index a15b4fd87..73b289294 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -73,40 +73,4 @@ android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" /> - - - - - - - - - - \ No newline at end of file