show the media management prompt at copy/move/delete too

This commit is contained in:
tibbi 2022-04-24 16:21:00 +02:00
parent 6428836c73
commit 91a71685bd
3 changed files with 36 additions and 19 deletions

View file

@ -238,7 +238,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
when (item.itemId) { when (item.itemId) {
R.id.menu_set_as -> setAs(getCurrentPath()) R.id.menu_set_as -> setAs(getCurrentPath())
R.id.menu_slideshow -> initSlideshow() R.id.menu_slideshow -> initSlideshow()
R.id.menu_copy_to -> copyMoveTo(true) R.id.menu_copy_to -> checkMediaManagementAndCopy(true)
R.id.menu_move_to -> moveFileTo() R.id.menu_move_to -> moveFileTo()
R.id.menu_open_with -> openPath(getCurrentPath(), true) R.id.menu_open_with -> openPath(getCurrentPath(), true)
R.id.menu_hide -> toggleFileVisibility(true) R.id.menu_hide -> toggleFileVisibility(true)
@ -642,7 +642,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun moveFileTo() { private fun moveFileTo() {
handleDeletePasswordProtection { handleDeletePasswordProtection {
copyMoveTo(false) checkMediaManagementAndCopy(false)
}
}
private fun checkMediaManagementAndCopy(isCopyOperation: Boolean) {
handleMediaManagementPrompt {
copyMoveTo(isCopyOperation)
} }
} }
@ -882,6 +888,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
bottom_toggle_file_visibility.setOnLongClickListener { bottom_toggle_file_visibility.setOnLongClickListener {
toast(if (currentMedium?.isHidden() == true) R.string.unhide else R.string.hide); true toast(if (currentMedium?.isHidden() == true) R.string.unhide else R.string.hide); true
} }
bottom_toggle_file_visibility.setOnClickListener { bottom_toggle_file_visibility.setOnClickListener {
currentMedium?.apply { currentMedium?.apply {
toggleFileVisibility(!isHidden()) { toggleFileVisibility(!isHidden()) {
@ -905,7 +912,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
bottom_copy.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_COPY != 0) bottom_copy.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_COPY != 0)
bottom_copy.setOnLongClickListener { toast(R.string.copy); true } bottom_copy.setOnLongClickListener { toast(R.string.copy); true }
bottom_copy.setOnClickListener { bottom_copy.setOnClickListener {
copyMoveTo(true) checkMediaManagementAndCopy(true)
} }
bottom_move.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_MOVE != 0) bottom_move.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_MOVE != 0)
@ -1078,14 +1085,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return return
} }
if (config.isDeletePasswordProtectionOn) { handleMediaManagementPrompt {
handleDeletePasswordProtection { if (config.isDeletePasswordProtectionOn) {
handleDeletePasswordProtection {
deleteConfirmed()
}
} else if (config.tempSkipDeleteConfirmation || config.skipDeleteConfirmation) {
deleteConfirmed() deleteConfirmed()
} else {
askConfirmDelete()
} }
} else if (config.tempSkipDeleteConfirmation || config.skipDeleteConfirmation) {
deleteConfirmed()
} else {
askConfirmDelete()
} }
} }

View file

@ -172,7 +172,7 @@ class MediaAdapter(
R.id.cab_rotate_right -> rotateSelection(90) R.id.cab_rotate_right -> rotateSelection(90)
R.id.cab_rotate_left -> rotateSelection(270) R.id.cab_rotate_left -> rotateSelection(270)
R.id.cab_rotate_one_eighty -> rotateSelection(180) R.id.cab_rotate_one_eighty -> rotateSelection(180)
R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_copy_to -> checkMediaManagementAndCopy(true)
R.id.cab_move_to -> moveFilesTo() R.id.cab_move_to -> moveFilesTo()
R.id.cab_create_shortcut -> createShortcut() R.id.cab_create_shortcut -> createShortcut()
R.id.cab_select_all -> selectAll() R.id.cab_select_all -> selectAll()
@ -356,7 +356,13 @@ class MediaAdapter(
private fun moveFilesTo() { private fun moveFilesTo() {
activity.handleDeletePasswordProtection { activity.handleDeletePasswordProtection {
copyMoveTo(false) checkMediaManagementAndCopy(false)
}
}
private fun checkMediaManagementAndCopy(isCopyOperation: Boolean) {
activity.handleMediaManagementPrompt {
copyMoveTo(isCopyOperation)
} }
} }
@ -434,14 +440,16 @@ class MediaAdapter(
} }
private fun checkDeleteConfirmation() { private fun checkDeleteConfirmation() {
if (config.isDeletePasswordProtectionOn) { activity.handleMediaManagementPrompt {
activity.handleDeletePasswordProtection { if (config.isDeletePasswordProtectionOn) {
activity.handleDeletePasswordProtection {
deleteFiles()
}
} else if (config.tempSkipDeleteConfirmation || config.skipDeleteConfirmation) {
deleteFiles() deleteFiles()
} else {
askConfirmDelete()
} }
} else if (config.tempSkipDeleteConfirmation || config.skipDeleteConfirmation) {
deleteFiles()
} else {
askConfirmDelete()
} }
} }

View file

@ -126,14 +126,14 @@ fun SimpleActivity.launchAbout() {
} }
@RequiresApi(Build.VERSION_CODES.S) @RequiresApi(Build.VERSION_CODES.S)
fun SimpleActivity.launchMediaManagementIntent() { fun AppCompatActivity.launchMediaManagementIntent() {
Intent(Settings.ACTION_REQUEST_MANAGE_MEDIA).apply { Intent(Settings.ACTION_REQUEST_MANAGE_MEDIA).apply {
data = Uri.parse("package:$packageName") data = Uri.parse("package:$packageName")
startActivity(this) startActivity(this)
} }
} }
fun SimpleActivity.handleMediaManagementPrompt(callback: () -> Unit) { fun AppCompatActivity.handleMediaManagementPrompt(callback: () -> Unit) {
if (isSPlus() && !MediaStore.canManageMedia(this)) { if (isSPlus() && !MediaStore.canManageMedia(this)) {
ConfirmationDialog(this, "", R.string.media_management_prompt, R.string.ok, 0) { ConfirmationDialog(this, "", R.string.media_management_prompt, R.string.ok, 0) {
launchMediaManagementIntent() launchMediaManagementIntent()