|
|
@ -43,7 +43,8 @@ class FileChooserDialog : DialogFragment(), |
|
|
|
isShowHomeDir: Boolean = false, |
|
|
|
isShowHomeDir: Boolean = false, |
|
|
|
isShowUpDir: Boolean = true, |
|
|
|
isShowUpDir: Boolean = true, |
|
|
|
isShowHideDir: Boolean = false, |
|
|
|
isShowHideDir: Boolean = false, |
|
|
|
allowExtensions: Array<String?>? = null |
|
|
|
allowExtensions: Array<String?>? = null, |
|
|
|
|
|
|
|
menus: Array<String>? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) |
|
|
|
val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) |
|
|
|
?: FileChooserDialog().apply { |
|
|
|
?: FileChooserDialog().apply { |
|
|
@ -56,6 +57,7 @@ class FileChooserDialog : DialogFragment(), |
|
|
|
bundle.putBoolean("isShowHideDir", isShowHideDir) |
|
|
|
bundle.putBoolean("isShowHideDir", isShowHideDir) |
|
|
|
bundle.putString("initPath", initPath) |
|
|
|
bundle.putString("initPath", initPath) |
|
|
|
bundle.putStringArray("allowExtensions", allowExtensions) |
|
|
|
bundle.putStringArray("allowExtensions", allowExtensions) |
|
|
|
|
|
|
|
bundle.putStringArray("menus", menus) |
|
|
|
arguments = bundle |
|
|
|
arguments = bundle |
|
|
|
} |
|
|
|
} |
|
|
|
fragment.show(manager, tag) |
|
|
|
fragment.show(manager, tag) |
|
|
@ -75,6 +77,7 @@ class FileChooserDialog : DialogFragment(), |
|
|
|
private var mode: Int = FILE |
|
|
|
private var mode: Int = FILE |
|
|
|
private lateinit var fileAdapter: FileAdapter |
|
|
|
private lateinit var fileAdapter: FileAdapter |
|
|
|
private lateinit var pathAdapter: PathAdapter |
|
|
|
private lateinit var pathAdapter: PathAdapter |
|
|
|
|
|
|
|
private var menus: Array<String>? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
override fun onStart() { |
|
|
|
super.onStart() |
|
|
|
super.onStart() |
|
|
@ -106,6 +109,7 @@ class FileChooserDialog : DialogFragment(), |
|
|
|
initPath = path |
|
|
|
initPath = path |
|
|
|
} |
|
|
|
} |
|
|
|
allowExtensions = it.getStringArray("allowExtensions") |
|
|
|
allowExtensions = it.getStringArray("allowExtensions") |
|
|
|
|
|
|
|
menus = it.getStringArray("menus") |
|
|
|
} |
|
|
|
} |
|
|
|
tool_bar.title = title ?: let { |
|
|
|
tool_bar.title = title ?: let { |
|
|
|
if (isOnlyListDir) { |
|
|
|
if (isOnlyListDir) { |
|
|
@ -124,6 +128,11 @@ class FileChooserDialog : DialogFragment(), |
|
|
|
if (isOnlyListDir) { |
|
|
|
if (isOnlyListDir) { |
|
|
|
tool_bar.menu.findItem(R.id.menu_ok).isVisible = true |
|
|
|
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.menu.applyTint(requireContext(), false) |
|
|
|
tool_bar.setOnMenuItemClickListener(this) |
|
|
|
tool_bar.setOnMenuItemClickListener(this) |
|
|
|
} |
|
|
|
} |
|
|
@ -148,6 +157,10 @@ class FileChooserDialog : DialogFragment(), |
|
|
|
(activity as? CallBack)?.onFilePicked(requestCode, it) |
|
|
|
(activity as? CallBack)?.onFilePicked(requestCode, it) |
|
|
|
dismiss() |
|
|
|
dismiss() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else -> item?.title?.let { |
|
|
|
|
|
|
|
(parentFragment as? CallBack)?.onMenuClick(it.toString()) |
|
|
|
|
|
|
|
(activity as? CallBack)?.onMenuClick(it.toString()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
@ -195,5 +208,6 @@ class FileChooserDialog : DialogFragment(), |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun onFilePicked(requestCode: Int, currentPath: String) |
|
|
|
fun onFilePicked(requestCode: Int, currentPath: String) |
|
|
|
|
|
|
|
fun onMenuClick(menu: String) {} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |