|
|
|
@ -2,11 +2,9 @@ package io.legado.app.ui.filepicker |
|
|
|
|
|
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Build |
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts |
|
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.constant.Permissions |
|
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
|
|
|
|
|
|
@Suppress("unused") |
|
|
|
@ -34,7 +32,6 @@ object FilePicker { |
|
|
|
|
val intent = createSelectDirIntent() |
|
|
|
|
activity.startActivityForResult(intent, requestCode) |
|
|
|
|
}.onFailure { |
|
|
|
|
checkPermissions(activity) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
activity.supportFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
@ -42,17 +39,14 @@ object FilePicker { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val selectText = selectList[index] |
|
|
|
|
if (selectText == activity.getString(R.string.app_folder_picker)) { |
|
|
|
|
checkPermissions(activity) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
activity.supportFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
|
mode = FilePickerDialog.DIRECTORY |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
otherFun?.invoke(selectText) |
|
|
|
|
} |
|
|
|
@ -84,7 +78,6 @@ object FilePicker { |
|
|
|
|
val intent = createSelectDirIntent() |
|
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
|
}.onFailure { |
|
|
|
|
checkPermissions(fragment) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
@ -92,17 +85,14 @@ object FilePicker { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val selectText = selectList[index] |
|
|
|
|
if (selectText == fragment.getString(R.string.app_folder_picker)) { |
|
|
|
|
checkPermissions(fragment) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
|
mode = FilePickerDialog.DIRECTORY |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
otherFun?.invoke(selectText) |
|
|
|
|
} |
|
|
|
@ -139,7 +129,6 @@ object FilePicker { |
|
|
|
|
) |
|
|
|
|
activity.startActivityForResult(intent, requestCode) |
|
|
|
|
}.onFailure { |
|
|
|
|
checkPermissions(activity) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
activity.supportFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
@ -148,18 +137,15 @@ object FilePicker { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val selectText = selectList[index] |
|
|
|
|
if (selectText == activity.getString(R.string.app_file_picker)) { |
|
|
|
|
checkPermissions(activity) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
activity.supportFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
|
mode = FilePickerDialog.FILE, |
|
|
|
|
allowExtensions = allowExtensions |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
otherFun?.invoke(selectText) |
|
|
|
|
} |
|
|
|
@ -196,7 +182,6 @@ object FilePicker { |
|
|
|
|
) |
|
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
|
}.onFailure { |
|
|
|
|
checkPermissions(fragment) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
@ -205,18 +190,15 @@ object FilePicker { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val selectText = selectList[index] |
|
|
|
|
if (selectText == fragment.getString(R.string.app_file_picker)) { |
|
|
|
|
checkPermissions(fragment) { |
|
|
|
|
FilePickerDialog.show( |
|
|
|
|
fragment.childFragmentManager, |
|
|
|
|
requestCode, |
|
|
|
|
mode = FilePickerDialog.FILE, |
|
|
|
|
allowExtensions = allowExtensions |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
otherFun?.invoke(selectText) |
|
|
|
|
} |
|
|
|
@ -246,18 +228,6 @@ object FilePicker { |
|
|
|
|
return intent |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun checkPermissions(fragment: Fragment, success: (() -> Unit)? = null) { |
|
|
|
|
fragment.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { |
|
|
|
|
success?.invoke() |
|
|
|
|
}.launch(Permissions.Group.STORAGE) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun checkPermissions(activity: AppCompatActivity, success: (() -> Unit)? = null) { |
|
|
|
|
activity.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { |
|
|
|
|
success?.invoke() |
|
|
|
|
}.launch(Permissions.Group.STORAGE) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun typesOfExtensions(allowExtensions: Array<String>): Array<String> { |
|
|
|
|
val types = hashSetOf<String>() |
|
|
|
|
if (allowExtensions.isNullOrEmpty()) { |
|
|
|
|