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 ecd6f6e8f..3ce47ee99 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 @@ -17,9 +17,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity -import io.legado.app.constant.EventBus import io.legado.app.help.AppConfig -import io.legado.app.help.ReadBookConfig import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.ui.filechooser.FileChooserDialog @@ -86,23 +84,6 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } }) - // 没有权限就显示一个授权提示和按钮 - if (PermissionsCompat.check(this, *Permissions.Group.STORAGE)) { - hint_per.visibility = View.GONE - } else { - hint_per.visibility = View.VISIBLE - tv_request_per.onClick { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - hint_per.visibility = View.GONE - initData() - upRootDoc() - } - .request() - } - } } private fun initEvent() { @@ -147,6 +128,24 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity 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 { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + hint_per.visibility = View.GONE + initData() + upRootDoc() + } + .request() + } + } } upPath() } diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt b/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt index 8f5549709..717ad8f11 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt @@ -31,7 +31,7 @@ object FilePicker { 0 -> default?.invoke() 1 -> { try { - val intent = getSelectDirIntent() + val intent = createSelectDirIntent() activity.startActivityForResult(intent, requestCode) } catch (e: java.lang.Exception) { e.printStackTrace() @@ -68,7 +68,7 @@ object FilePicker { 0 -> default?.invoke() 1 -> { try { - val intent = getSelectDirIntent() + val intent = createSelectDirIntent() fragment.startActivityForResult(intent, requestCode) } catch (e: java.lang.Exception) { e.printStackTrace() @@ -106,7 +106,7 @@ object FilePicker { 0 -> default?.invoke() 1 -> { try { - val intent = getSelectFileIntent() + val intent = createSelectFileIntent() intent.type = type//设置类型 activity.startActivityForResult(intent, requestCode) } catch (e: java.lang.Exception) { @@ -147,7 +147,7 @@ object FilePicker { 0 -> default?.invoke() 1 -> { try { - val intent = getSelectFileIntent() + val intent = createSelectFileIntent() intent.type = type//设置类型 fragment.startActivityForResult(intent, requestCode) } catch (e: java.lang.Exception) { @@ -168,14 +168,14 @@ object FilePicker { }.show() } - private fun getSelectFileIntent(): Intent { + private fun createSelectFileIntent(): Intent { val intent = Intent(Intent.ACTION_GET_CONTENT) intent.addCategory(Intent.CATEGORY_OPENABLE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) return intent } - private fun getSelectDirIntent(): Intent { + private fun createSelectDirIntent(): Intent { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) return intent