diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index 2fffac981..baac1f201 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -43,7 +43,8 @@ class FileChooserDialog : DialogFragment(), isShowHomeDir: Boolean = false, isShowUpDir: Boolean = true, isShowHideDir: Boolean = false, - allowExtensions: Array? = null + allowExtensions: Array? = null, + menus: Array? = null ) { val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) ?: FileChooserDialog().apply { @@ -56,6 +57,7 @@ class FileChooserDialog : DialogFragment(), bundle.putBoolean("isShowHideDir", isShowHideDir) bundle.putString("initPath", initPath) bundle.putStringArray("allowExtensions", allowExtensions) + bundle.putStringArray("menus", menus) arguments = bundle } fragment.show(manager, tag) @@ -75,6 +77,7 @@ class FileChooserDialog : DialogFragment(), private var mode: Int = FILE private lateinit var fileAdapter: FileAdapter private lateinit var pathAdapter: PathAdapter + private var menus: Array? = null override fun onStart() { super.onStart() @@ -106,6 +109,7 @@ class FileChooserDialog : DialogFragment(), initPath = path } allowExtensions = it.getStringArray("allowExtensions") + menus = it.getStringArray("menus") } tool_bar.title = title ?: let { if (isOnlyListDir) { @@ -124,6 +128,11 @@ class FileChooserDialog : DialogFragment(), if (isOnlyListDir) { tool_bar.menu.findItem(R.id.menu_ok).isVisible = true } + menus?.let { + it.forEach { menuTitle -> + tool_bar.menu.add(menuTitle) + } + } tool_bar.menu.applyTint(requireContext(), false) tool_bar.setOnMenuItemClickListener(this) } @@ -148,6 +157,10 @@ class FileChooserDialog : DialogFragment(), (activity as? CallBack)?.onFilePicked(requestCode, it) dismiss() } + else -> item?.title?.let { + (parentFragment as? CallBack)?.onMenuClick(it.toString()) + (activity as? CallBack)?.onMenuClick(it.toString()) + } } return true } @@ -195,5 +208,6 @@ class FileChooserDialog : DialogFragment(), interface CallBack { fun onFilePicked(requestCode: Int, currentPath: String) + fun onMenuClick(menu: String) {} } } \ No newline at end of file