|
|
@ -1,4 +1,4 @@ |
|
|
|
package io.legado.app.ui.filechooser |
|
|
|
package io.legado.app.ui.filepicker |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Intent |
|
|
|
import android.content.Intent |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
@ -22,12 +22,12 @@ object FilePicker { |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
val selectList = |
|
|
|
|
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
|
|
|
|
otherActions?.let { |
|
|
|
|
|
|
|
selectList.addAll(otherActions) |
|
|
|
|
|
|
|
} |
|
|
|
activity.alert(title = title) { |
|
|
|
activity.alert(title = title) { |
|
|
|
val selectList = |
|
|
|
|
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
|
|
|
|
otherActions?.let { |
|
|
|
|
|
|
|
selectList.addAll(otherActions) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (index) { |
|
|
|
when (index) { |
|
|
|
0 -> { |
|
|
|
0 -> { |
|
|
@ -40,10 +40,10 @@ object FilePicker { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
1 -> checkPermissions(activity) { |
|
|
|
1 -> checkPermissions(activity) { |
|
|
|
FileChooserDialog.show( |
|
|
|
FilePickerDialog.show( |
|
|
|
activity.supportFragmentManager, |
|
|
|
activity.supportFragmentManager, |
|
|
|
requestCode, |
|
|
|
requestCode, |
|
|
|
mode = FileChooserDialog.DIRECTORY |
|
|
|
mode = FilePickerDialog.DIRECTORY |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
@ -59,35 +59,34 @@ object FilePicker { |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
fragment.requireContext() |
|
|
|
val selectList = |
|
|
|
.alert(title = title) { |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
val selectList = |
|
|
|
otherActions?.let { |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
selectList.addAll(otherActions) |
|
|
|
otherActions?.let { |
|
|
|
} |
|
|
|
selectList.addAll(otherActions) |
|
|
|
fragment.alert(title = title) { |
|
|
|
} |
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (index) { |
|
|
|
when (index) { |
|
|
|
0 -> { |
|
|
|
0 -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = createSelectDirIntent() |
|
|
|
val intent = createSelectDirIntent() |
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
e.printStackTrace() |
|
|
|
e.printStackTrace() |
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
1 -> checkPermissions(fragment) { |
|
|
|
|
|
|
|
FileChooserDialog.show( |
|
|
|
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
|
|
|
requestCode, |
|
|
|
|
|
|
|
mode = FileChooserDialog.DIRECTORY |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
1 -> checkPermissions(fragment) { |
|
|
|
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
|
|
|
requestCode, |
|
|
|
|
|
|
|
mode = FilePickerDialog.DIRECTORY |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint() |
|
|
|
} |
|
|
|
|
|
|
|
}.show().applyTint() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun selectFile( |
|
|
|
fun selectFile( |
|
|
@ -98,12 +97,12 @@ object FilePicker { |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
val selectList = |
|
|
|
|
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
|
|
|
|
otherActions?.let { |
|
|
|
|
|
|
|
selectList.addAll(otherActions) |
|
|
|
|
|
|
|
} |
|
|
|
activity.alert(title = title) { |
|
|
|
activity.alert(title = title) { |
|
|
|
val selectList = |
|
|
|
|
|
|
|
activity.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
|
|
|
|
otherActions?.let { |
|
|
|
|
|
|
|
selectList.addAll(otherActions) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (index) { |
|
|
|
when (index) { |
|
|
|
0 -> { |
|
|
|
0 -> { |
|
|
@ -120,10 +119,10 @@ object FilePicker { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
1 -> checkPermissions(activity) { |
|
|
|
1 -> checkPermissions(activity) { |
|
|
|
FileChooserDialog.show( |
|
|
|
FilePickerDialog.show( |
|
|
|
activity.supportFragmentManager, |
|
|
|
activity.supportFragmentManager, |
|
|
|
requestCode, |
|
|
|
requestCode, |
|
|
|
mode = FileChooserDialog.FILE, |
|
|
|
mode = FilePickerDialog.FILE, |
|
|
|
allowExtensions = allowExtensions |
|
|
|
allowExtensions = allowExtensions |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
@ -141,40 +140,39 @@ object FilePicker { |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherActions: List<String>? = null, |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
otherFun: ((action: String) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
fragment.requireContext() |
|
|
|
val selectList = |
|
|
|
.alert(title = title) { |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
val selectList = |
|
|
|
otherActions?.let { |
|
|
|
fragment.resources.getStringArray(R.array.select_folder).toMutableList() |
|
|
|
selectList.addAll(otherActions) |
|
|
|
otherActions?.let { |
|
|
|
} |
|
|
|
selectList.addAll(otherActions) |
|
|
|
fragment.alert(title = title) { |
|
|
|
} |
|
|
|
items(selectList) { _, index -> |
|
|
|
items(selectList) { _, index -> |
|
|
|
when (index) { |
|
|
|
when (index) { |
|
|
|
0 -> { |
|
|
|
0 -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = createSelectFileIntent() |
|
|
|
val intent = createSelectFileIntent() |
|
|
|
intent.putExtra( |
|
|
|
intent.putExtra( |
|
|
|
Intent.EXTRA_MIME_TYPES, |
|
|
|
Intent.EXTRA_MIME_TYPES, |
|
|
|
typesOfExtensions(allowExtensions) |
|
|
|
typesOfExtensions(allowExtensions) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
|
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
|
|
|
|
e.printStackTrace() |
|
|
|
|
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
1 -> checkPermissions(fragment) { |
|
|
|
|
|
|
|
FileChooserDialog.show( |
|
|
|
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
|
|
|
requestCode, |
|
|
|
|
|
|
|
mode = FileChooserDialog.FILE, |
|
|
|
|
|
|
|
allowExtensions = allowExtensions |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
|
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
|
|
|
|
e.printStackTrace() |
|
|
|
|
|
|
|
fragment.toast(e.localizedMessage ?: "ERROR") |
|
|
|
} |
|
|
|
} |
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
1 -> checkPermissions(fragment) { |
|
|
|
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
|
|
|
requestCode, |
|
|
|
|
|
|
|
mode = FilePickerDialog.FILE, |
|
|
|
|
|
|
|
allowExtensions = allowExtensions |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> otherFun?.invoke(selectList[index]) |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint() |
|
|
|
} |
|
|
|
|
|
|
|
}.show().applyTint() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun createSelectFileIntent(): Intent { |
|
|
|
private fun createSelectFileIntent(): Intent { |