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) {
R.id.menu_set_as -> setAs(getCurrentPath())
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_open_with -> openPath(getCurrentPath(), true)
R.id.menu_hide -> toggleFileVisibility(true)
@ -642,7 +642,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun moveFileTo() {
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 {
toast(if (currentMedium?.isHidden() == true) R.string.unhide else R.string.hide); true
}
bottom_toggle_file_visibility.setOnClickListener {
currentMedium?.apply {
toggleFileVisibility(!isHidden()) {
@ -905,7 +912,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
bottom_copy.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_COPY != 0)
bottom_copy.setOnLongClickListener { toast(R.string.copy); true }
bottom_copy.setOnClickListener {
copyMoveTo(true)
checkMediaManagementAndCopy(true)
}
bottom_move.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_MOVE != 0)
@ -1078,6 +1085,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return
}
handleMediaManagementPrompt {
if (config.isDeletePasswordProtectionOn) {
handleDeletePasswordProtection {
deleteConfirmed()
@ -1088,6 +1096,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
askConfirmDelete()
}
}
}
private fun askConfirmDelete() {
val filename = "\"${getCurrentPath().getFilenameFromPath()}\""

View file

@ -172,7 +172,7 @@ class MediaAdapter(
R.id.cab_rotate_right -> rotateSelection(90)
R.id.cab_rotate_left -> rotateSelection(270)
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_create_shortcut -> createShortcut()
R.id.cab_select_all -> selectAll()
@ -356,7 +356,13 @@ class MediaAdapter(
private fun moveFilesTo() {
activity.handleDeletePasswordProtection {
copyMoveTo(false)
checkMediaManagementAndCopy(false)
}
}
private fun checkMediaManagementAndCopy(isCopyOperation: Boolean) {
activity.handleMediaManagementPrompt {
copyMoveTo(isCopyOperation)
}
}
@ -434,6 +440,7 @@ class MediaAdapter(
}
private fun checkDeleteConfirmation() {
activity.handleMediaManagementPrompt {
if (config.isDeletePasswordProtectionOn) {
activity.handleDeletePasswordProtection {
deleteFiles()
@ -444,6 +451,7 @@ class MediaAdapter(
askConfirmDelete()
}
}
}
private fun askConfirmDelete() {
val itemsCnt = selectedKeys.size

View file

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