pull/457/head
gedoor 4 years ago
parent 0e4e5c7eda
commit d622823e93
  1. 20
      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) {}

Loading…
Cancel
Save