Merge pull request #2436 from KryptKode/feat/manage_media

handle mange media for renaming
This commit is contained in:
Tibor Kaputa 2022-05-01 12:04:11 +02:00 committed by GitHub
commit cbfd8ad7b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 18 deletions

View file

@ -245,7 +245,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
R.id.menu_unhide -> toggleFileVisibility(false) R.id.menu_unhide -> toggleFileVisibility(false)
R.id.menu_share -> shareMediumPath(getCurrentPath()) R.id.menu_share -> shareMediumPath(getCurrentPath())
R.id.menu_delete -> checkDeleteConfirmation() R.id.menu_delete -> checkDeleteConfirmation()
R.id.menu_rename -> renameFile() R.id.menu_rename -> checkMediaManagementAndRename()
R.id.menu_print -> printFile() R.id.menu_print -> printFile()
R.id.menu_edit -> openEditor(getCurrentPath()) R.id.menu_edit -> openEditor(getCurrentPath())
R.id.menu_properties -> showProperties() R.id.menu_properties -> showProperties()
@ -900,7 +900,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
bottom_rename.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_RENAME != 0 && currentMedium?.getIsInRecycleBin() == false) bottom_rename.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_RENAME != 0 && currentMedium?.getIsInRecycleBin() == false)
bottom_rename.setOnLongClickListener { toast(R.string.rename); true } bottom_rename.setOnLongClickListener { toast(R.string.rename); true }
bottom_rename.setOnClickListener { bottom_rename.setOnClickListener {
renameFile() checkMediaManagementAndRename()
} }
bottom_set_as.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SET_AS != 0) bottom_set_as.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SET_AS != 0)
@ -1122,9 +1122,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) {
handleSAFDialogSdk30(fileDirItem.path) { checkManageMediaOrHandleSAFDialogSdk30(fileDirItem.path) {
if (!it) { if (!it) {
return@handleSAFDialogSdk30 return@checkManageMediaOrHandleSAFDialogSdk30
} }
mIgnoredPaths.add(fileDirItem.path) mIgnoredPaths.add(fileDirItem.path)
@ -1150,9 +1150,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun handleDeletion(fileDirItem: FileDirItem) { private fun handleDeletion(fileDirItem: FileDirItem) {
handleSAFDialogSdk30(fileDirItem.path) { checkManageMediaOrHandleSAFDialogSdk30(fileDirItem.path) {
if (!it) { if (!it) {
return@handleSAFDialogSdk30 return@checkManageMediaOrHandleSAFDialogSdk30
} }
mIgnoredPaths.add(fileDirItem.path) mIgnoredPaths.add(fileDirItem.path)
@ -1178,6 +1178,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
} }
private fun checkMediaManagementAndRename() {
handleMediaManagementPrompt {
renameFile()
}
}
private fun renameFile() { private fun renameFile() {
val oldPath = getCurrentPath() val oldPath = getCurrentPath()

View file

@ -161,7 +161,7 @@ class MediaAdapter(
when (id) { when (id) {
R.id.cab_confirm_selection -> confirmSelection() R.id.cab_confirm_selection -> confirmSelection()
R.id.cab_properties -> showProperties() R.id.cab_properties -> showProperties()
R.id.cab_rename -> renameFile() R.id.cab_rename -> checkMediaManagementAndRename()
R.id.cab_edit -> editFile() R.id.cab_edit -> editFile()
R.id.cab_hide -> toggleFileVisibility(true) R.id.cab_hide -> toggleFileVisibility(true)
R.id.cab_unhide -> toggleFileVisibility(false) R.id.cab_unhide -> toggleFileVisibility(false)
@ -234,6 +234,12 @@ class MediaAdapter(
} }
} }
private fun checkMediaManagementAndRename() {
activity.handleMediaManagementPrompt {
renameFile()
}
}
private fun renameFile() { private fun renameFile() {
val firstPath = getFirstSelectedItemPath() ?: return val firstPath = getFirstSelectedItemPath() ?: return
@ -485,9 +491,9 @@ class MediaAdapter(
} }
val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog val sdk30SafPath = selectedPaths.firstOrNull { activity.isAccessibleWithSAFSdk30(it) } ?: getFirstSelectedItemPath() ?: return@handleSAFDialog
activity.handleSAFDialogSdk30(sdk30SafPath) { activity.checkManageMediaOrHandleSAFDialogSdk30(sdk30SafPath) {
if (!it) { if (!it) {
return@handleSAFDialogSdk30 return@checkManageMediaOrHandleSAFDialogSdk30
} }
val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size) val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)

View file

@ -125,18 +125,11 @@ fun SimpleActivity.launchAbout() {
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
} }
@RequiresApi(Build.VERSION_CODES.S)
fun AppCompatActivity.launchMediaManagementIntent() {
Intent(Settings.ACTION_REQUEST_MANAGE_MEDIA).apply {
data = Uri.parse("package:$packageName")
startActivity(this)
}
}
fun AppCompatActivity.handleMediaManagementPrompt(callback: () -> Unit) { fun BaseSimpleActivity.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(callback)
} }
} else { } else {
callback() callback()