Merge pull request #1322 from KryptKode/feat/saf-dialog
Refactor `WritePermissionDialog` to support sdk 30 SAF selection
This commit is contained in:
commit
ec74a7c44f
3 changed files with 35 additions and 19 deletions
|
@ -33,6 +33,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
|||
import com.simplemobiletools.commons.dialogs.ExportSettingsDialog
|
||||
import com.simplemobiletools.commons.dialogs.FileConflictDialog
|
||||
import com.simplemobiletools.commons.dialogs.WritePermissionDialog
|
||||
import com.simplemobiletools.commons.dialogs.WritePermissionDialog.Mode
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.interfaces.CopyMoveListener
|
||||
|
@ -457,7 +458,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
funAfterSAFPermission = callback
|
||||
WritePermissionDialog(this, true) {
|
||||
WritePermissionDialog(this, Mode.OTG) {
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
|
||||
try {
|
||||
startActivityForResult(this, OPEN_DOCUMENT_TREE_OTG)
|
||||
|
|
|
@ -10,31 +10,45 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
|
|||
import kotlinx.android.synthetic.main.dialog_write_permission.view.*
|
||||
import kotlinx.android.synthetic.main.dialog_write_permission_otg.view.*
|
||||
|
||||
class WritePermissionDialog(activity: Activity, val isOTG: Boolean, val callback: () -> Unit) {
|
||||
class WritePermissionDialog(activity: Activity, val mode: Mode, val callback: () -> Unit) {
|
||||
enum class Mode {
|
||||
OTG,
|
||||
SD_CARD,
|
||||
SDK_30
|
||||
}
|
||||
|
||||
var dialog: AlertDialog
|
||||
|
||||
init {
|
||||
val layout = if (isOTG) R.layout.dialog_write_permission_otg else R.layout.dialog_write_permission
|
||||
val layout = if (mode == Mode.OTG || mode == Mode.SDK_30) R.layout.dialog_write_permission_otg else R.layout.dialog_write_permission
|
||||
val view = activity.layoutInflater.inflate(layout, null)
|
||||
|
||||
val glide = Glide.with(activity)
|
||||
val crossFade = DrawableTransitionOptions.withCrossFade()
|
||||
if (isOTG) {
|
||||
glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(view.write_permissions_dialog_otg_image)
|
||||
} else {
|
||||
glide.load(R.drawable.img_write_storage).transition(crossFade).into(view.write_permissions_dialog_image)
|
||||
glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(view.write_permissions_dialog_image_sd)
|
||||
when (mode) {
|
||||
Mode.OTG -> {
|
||||
view.write_permissions_dialog_otg_text.setText(R.string.confirm_usb_storage_access_text)
|
||||
glide.load(R.drawable.img_write_storage_otg).transition(crossFade).into(view.write_permissions_dialog_otg_image)
|
||||
}
|
||||
Mode.SD_CARD -> {
|
||||
glide.load(R.drawable.img_write_storage).transition(crossFade).into(view.write_permissions_dialog_image)
|
||||
glide.load(R.drawable.img_write_storage_sd).transition(crossFade).into(view.write_permissions_dialog_image_sd)
|
||||
}
|
||||
Mode.SDK_30 -> {
|
||||
view.write_permissions_dialog_otg_text.setText(R.string.confirm_storage_access_android_text)
|
||||
glide.load(R.drawable.img_write_storage_sdk_30).transition(crossFade).into(view.write_permissions_dialog_otg_image)
|
||||
}
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||
.setOnCancelListener {
|
||||
BaseSimpleActivity.funAfterSAFPermission?.invoke(false)
|
||||
BaseSimpleActivity.funAfterSAFPermission = null
|
||||
}
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.confirm_storage_access_title)
|
||||
}
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||
.setOnCancelListener {
|
||||
BaseSimpleActivity.funAfterSAFPermission?.invoke(false)
|
||||
BaseSimpleActivity.funAfterSAFPermission = null
|
||||
}
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.confirm_storage_access_title)
|
||||
}
|
||||
}
|
||||
|
||||
private fun dialogConfirmed() {
|
||||
|
|
|
@ -33,6 +33,7 @@ import androidx.fragment.app.FragmentActivity
|
|||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.*
|
||||
import com.simplemobiletools.commons.dialogs.WritePermissionDialog.Mode
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.*
|
||||
import com.simplemobiletools.commons.views.MyTextView
|
||||
|
@ -124,7 +125,7 @@ fun BaseSimpleActivity.isShowingSAFDialog(path: String): Boolean {
|
|||
return if ((!isRPlus() && isPathOnSD(path) && !isSDCardSetAsDefaultStorage() && (baseConfig.sdTreeUri.isEmpty() || !hasProperStoredTreeUri(false)))) {
|
||||
runOnUiThread {
|
||||
if (!isDestroyed && !isFinishing) {
|
||||
WritePermissionDialog(this, false) {
|
||||
WritePermissionDialog(this, Mode.SD_CARD) {
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
|
||||
putExtra("android.content.extra.SHOW_ADVANCED", true)
|
||||
try {
|
||||
|
@ -156,7 +157,7 @@ fun BaseSimpleActivity.isShowingSAFDialogForDeleteSdk30(path: String): Boolean {
|
|||
return if (!hasProperStoredFirstParentUri(path)) {
|
||||
runOnUiThread {
|
||||
if (!isDestroyed && !isFinishing) {
|
||||
WritePermissionDialog(this, false) {
|
||||
WritePermissionDialog(this, Mode.SDK_30) {
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
|
||||
putExtra("android.content.extra.SHOW_ADVANCED", true)
|
||||
putExtra(DocumentsContract.EXTRA_INITIAL_URI, createFirstParentDocumentUri(path))
|
||||
|
@ -230,7 +231,7 @@ fun BaseSimpleActivity.isShowingOTGDialog(path: String): Boolean {
|
|||
fun BaseSimpleActivity.showOTGPermissionDialog(path: String) {
|
||||
runOnUiThread {
|
||||
if (!isDestroyed && !isFinishing) {
|
||||
WritePermissionDialog(this, true) {
|
||||
WritePermissionDialog(this, Mode.OTG) {
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
|
||||
try {
|
||||
startActivityForResult(this, OPEN_DOCUMENT_TREE_OTG)
|
||||
|
|
Loading…
Reference in a new issue