|
|
@ -19,18 +19,18 @@ object FilePicker { |
|
|
|
activity: AppCompatActivity, |
|
|
|
activity: AppCompatActivity, |
|
|
|
requestCode: Int, |
|
|
|
requestCode: Int, |
|
|
|
title: String = activity.getString(R.string.select_folder), |
|
|
|
title: String = activity.getString(R.string.select_folder), |
|
|
|
default: (() -> Unit)? = null |
|
|
|
otherActions: List<String>? = null, |
|
|
|
|
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
activity.alert(title = title) { |
|
|
|
activity.alert(title = title) { |
|
|
|
val selectList = |
|
|
|
val selectList = |
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
default ?: let { |
|
|
|
otherActions?.let { |
|
|
|
selectList.removeAt(0) |
|
|
|
selectList.addAll(otherActions) |
|
|
|
} |
|
|
|
} |
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (if (default == null) index + 1 else index) { |
|
|
|
when (index) { |
|
|
|
0 -> default?.invoke() |
|
|
|
0 -> { |
|
|
|
1 -> { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = createSelectDirIntent() |
|
|
|
val intent = createSelectDirIntent() |
|
|
|
activity.startActivityForResult(intent, requestCode) |
|
|
|
activity.startActivityForResult(intent, requestCode) |
|
|
@ -39,13 +39,14 @@ object FilePicker { |
|
|
|
activity.toast(e.localizedMessage ?: "ERROR") |
|
|
|
activity.toast(e.localizedMessage ?: "ERROR") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
2 -> checkPermissions(activity) { |
|
|
|
1 -> checkPermissions(activity) { |
|
|
|
FileChooserDialog.show( |
|
|
|
FileChooserDialog.show( |
|
|
|
activity.supportFragmentManager, |
|
|
|
activity.supportFragmentManager, |
|
|
|
requestCode, |
|
|
|
requestCode, |
|
|
|
mode = FileChooserDialog.DIRECTORY |
|
|
|
mode = FileChooserDialog.DIRECTORY |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint() |
|
|
|
}.show().applyTint() |
|
|
@ -55,19 +56,19 @@ object FilePicker { |
|
|
|
fragment: Fragment, |
|
|
|
fragment: Fragment, |
|
|
|
requestCode: Int, |
|
|
|
requestCode: Int, |
|
|
|
title: String = fragment.getString(R.string.select_folder), |
|
|
|
title: String = fragment.getString(R.string.select_folder), |
|
|
|
default: (() -> Unit)? = null |
|
|
|
otherActions: List<String>? = null, |
|
|
|
|
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
fragment.requireContext() |
|
|
|
fragment.requireContext() |
|
|
|
.alert(title = title) { |
|
|
|
.alert(title = title) { |
|
|
|
val selectList = |
|
|
|
val selectList = |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
default ?: let { |
|
|
|
otherActions?.let { |
|
|
|
selectList.removeAt(0) |
|
|
|
selectList.addAll(otherActions) |
|
|
|
} |
|
|
|
} |
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (if (default == null) index + 1 else index) { |
|
|
|
when (index) { |
|
|
|
0 -> default?.invoke() |
|
|
|
0 -> { |
|
|
|
1 -> { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = createSelectDirIntent() |
|
|
|
val intent = createSelectDirIntent() |
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
@ -76,13 +77,14 @@ object FilePicker { |
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
2 -> checkPermissions(fragment) { |
|
|
|
1 -> checkPermissions(fragment) { |
|
|
|
FileChooserDialog.show( |
|
|
|
FileChooserDialog.show( |
|
|
|
fragment.childFragmentManager, |
|
|
|
fragment.childFragmentManager, |
|
|
|
requestCode, |
|
|
|
requestCode, |
|
|
|
mode = FileChooserDialog.DIRECTORY |
|
|
|
mode = FileChooserDialog.DIRECTORY |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint() |
|
|
|
}.show().applyTint() |
|
|
@ -93,18 +95,18 @@ object FilePicker { |
|
|
|
requestCode: Int, |
|
|
|
requestCode: Int, |
|
|
|
title: String = activity.getString(R.string.select_file), |
|
|
|
title: String = activity.getString(R.string.select_file), |
|
|
|
allowExtensions: Array<String>, |
|
|
|
allowExtensions: Array<String>, |
|
|
|
default: (() -> Unit)? = null |
|
|
|
otherActions: List<String>? = null, |
|
|
|
|
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
activity.alert(title = title) { |
|
|
|
activity.alert(title = title) { |
|
|
|
val selectList = |
|
|
|
val selectList = |
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
default ?: let { |
|
|
|
otherActions?.let { |
|
|
|
selectList.removeAt(0) |
|
|
|
selectList.addAll(otherActions) |
|
|
|
} |
|
|
|
} |
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (if (default == null) index + 1 else index) { |
|
|
|
when (index) { |
|
|
|
0 -> default?.invoke() |
|
|
|
0 -> { |
|
|
|
1 -> { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = createSelectFileIntent() |
|
|
|
val intent = createSelectFileIntent() |
|
|
|
intent.putExtra( |
|
|
|
intent.putExtra( |
|
|
@ -117,7 +119,7 @@ object FilePicker { |
|
|
|
activity.toast(e.localizedMessage ?: "ERROR") |
|
|
|
activity.toast(e.localizedMessage ?: "ERROR") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
2 -> checkPermissions(activity) { |
|
|
|
1 -> checkPermissions(activity) { |
|
|
|
FileChooserDialog.show( |
|
|
|
FileChooserDialog.show( |
|
|
|
activity.supportFragmentManager, |
|
|
|
activity.supportFragmentManager, |
|
|
|
requestCode, |
|
|
|
requestCode, |
|
|
@ -125,6 +127,7 @@ object FilePicker { |
|
|
|
allowExtensions = allowExtensions |
|
|
|
allowExtensions = allowExtensions |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint() |
|
|
|
}.show().applyTint() |
|
|
@ -135,19 +138,19 @@ object FilePicker { |
|
|
|
requestCode: Int, |
|
|
|
requestCode: Int, |
|
|
|
title: String = fragment.getString(R.string.select_file), |
|
|
|
title: String = fragment.getString(R.string.select_file), |
|
|
|
allowExtensions: Array<String>, |
|
|
|
allowExtensions: Array<String>, |
|
|
|
default: (() -> Unit)? = null |
|
|
|
otherActions: List<String>? = null, |
|
|
|
|
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
fragment.requireContext() |
|
|
|
fragment.requireContext() |
|
|
|
.alert(title = title) { |
|
|
|
.alert(title = title) { |
|
|
|
val selectList = |
|
|
|
val selectList = |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
default ?: let { |
|
|
|
otherActions?.let { |
|
|
|
selectList.removeAt(0) |
|
|
|
selectList.addAll(otherActions) |
|
|
|
} |
|
|
|
} |
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (if (default == null) index + 1 else index) { |
|
|
|
when (index) { |
|
|
|
0 -> default?.invoke() |
|
|
|
0 -> { |
|
|
|
1 -> { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = createSelectFileIntent() |
|
|
|
val intent = createSelectFileIntent() |
|
|
|
intent.putExtra( |
|
|
|
intent.putExtra( |
|
|
@ -160,7 +163,7 @@ object FilePicker { |
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
2 -> checkPermissions(fragment) { |
|
|
|
1 -> checkPermissions(fragment) { |
|
|
|
FileChooserDialog.show( |
|
|
|
FileChooserDialog.show( |
|
|
|
fragment.childFragmentManager, |
|
|
|
fragment.childFragmentManager, |
|
|
|
requestCode, |
|
|
|
requestCode, |
|
|
@ -168,6 +171,7 @@ object FilePicker { |
|
|
|
allowExtensions = allowExtensions |
|
|
|
allowExtensions = allowExtensions |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint() |
|
|
|
}.show().applyTint() |
|
|
|