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