From d622823e93c756de1f2ee42ff09bc8aa4956a224 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 31 Oct 2020 22:45:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/filepicker/FilePickerDialog.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt index 3c26b4402..082143010 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt @@ -149,11 +149,7 @@ class FilePickerDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_ok -> fileAdapter.currentPath?.let { - val data = Intent().setData(Uri.fromFile(File(it))) - (parentFragment as? CallBack) - ?.onActivityResult(requestCode, Activity.RESULT_OK, data) - (activity as? CallBack) - ?.onActivityResult(requestCode, Activity.RESULT_OK, data) + setData(it) dismiss() } else -> item?.title?.let { @@ -176,11 +172,7 @@ class FilePickerDialog : DialogFragment(), } else if (allowExtensions == null || allowExtensions?.contains(FileUtils.getExtension(path)) == true ) { - val data = Intent().setData(Uri.fromFile(File(path))) - (parentFragment as? CallBack) - ?.onActivityResult(requestCode, Activity.RESULT_OK, data) - (activity as? CallBack) - ?.onActivityResult(requestCode, Activity.RESULT_OK, data) + setData(path) dismiss() } else { toast("不能打开此文件") @@ -215,6 +207,14 @@ class FilePickerDialog : DialogFragment(), } } + private fun setData(path: String) { + val data = Intent().setData(Uri.fromFile(File(path))) + (parentFragment as? CallBack) + ?.onActivityResult(requestCode, Activity.RESULT_OK, data) + (activity as? CallBack) + ?.onActivityResult(requestCode, Activity.RESULT_OK, data) + } + interface CallBack { fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) fun onMenuClick(menu: String) {}