sdk 30+ changes

- handle WRITE_STORAGE permission in EditActivity
- in PickDirectoryDialog replace error message when users select a restricted system directory to R.string.system_folder_restriction
- in SaveDialog
    - if path is a restricted path, automatically change it to {CURRENT_VOLUME}/Pictures directory.
    - if there is conflict and the file is direct child of the Download folder, show the user a prompt to grant WRITE request permission
- remove unused string R.string.copy_to_restricted_folder_message
- in NewPhotoEditActivity and NewVideoEditActivity, only delete SD Card file on conflict for devices running lower than SDK 30
- update commons module
This commit is contained in:
darthpaul 2022-04-09 23:34:52 +01:00
parent 7b0476690c
commit 8da45dcfbb
7 changed files with 44 additions and 10 deletions

View file

@ -77,7 +77,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:b16cc87e63'
implementation 'com.github.SimpleMobileTools:Simple-Commons:69ac8d3f2f'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'

View file

@ -28,6 +28,7 @@ import com.bumptech.glide.request.target.Target
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isNougatPlus
@ -101,7 +102,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
return
}
initEditActivity()
handlePermission(PERMISSION_WRITE_STORAGE){
if (!it) {
toast(R.string.no_storage_permissions)
finish()
}
initEditActivity()
}
}
override fun onResume() {

View file

@ -112,7 +112,7 @@ class PickDirectoryDialog(
activity.toast(R.string.source_and_destination_same)
return@DirectoryAdapter
} else if (isRPlus() && path.isBasePath(activity)) {
activity.toast(R.string.copy_to_restricted_folder_message)
activity.toast(R.string.system_folder_restriction)
return@DirectoryAdapter
} else {
activity.handleLockedFolderOpening(path) { success ->

View file

@ -5,7 +5,9 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.gallery.pro.R
import java.io.File
import kotlinx.android.synthetic.main.dialog_save_as.view.*
class SaveAsDialog(
@ -15,6 +17,9 @@ class SaveAsDialog(
init {
var realPath = path.getParentPath()
if (activity.isRestrictedWithSAFSdk30(realPath) && !activity.isInDownloadDir(realPath)) {
realPath = activity.getPicturesDirectoryPath(realPath)
}
val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply {
save_as_path.text = "${activity.humanizePath(realPath).trimEnd('/')}/"
@ -74,15 +79,36 @@ class SaveAsDialog(
if (activity.getDoesFilePathExist(newPath)) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
ConfirmationDialog(activity, title) {
callback(newPath)
dismiss()
val newFile = File(newPath)
val isInDownloadDir = activity.isInDownloadDir(newPath)
val isInSubFolderInDownloadDir = activity.isInSubFolderInDownloadDir(newPath)
if (isRPlus() && isInDownloadDir && !isInSubFolderInDownloadDir && !newFile.canWrite()) {
val fileDirItem = arrayListOf(File(newPath).toFileDirItem(activity))
val fileUris = activity.getFileUrisFromFileDirItems(fileDirItem).second
activity.updateSDK30Uris(fileUris) { success ->
if (success) {
selectPath(this, newPath)
}
}
} else {
selectPath(this, newPath)
}
}
} else {
callback(newPath)
dismiss()
selectPath(this, newPath)
}
}
}
}
}
private fun selectPath(alertDialog: AlertDialog, newPath: String) {
activity.handleSAFDialogSdk30(newPath) {
if (!it) {
return@handleSAFDialogSdk30
}
callback(newPath)
alertDialog.dismiss()
}
}
}

View file

@ -33,7 +33,6 @@
<string name="set_as_default_folder">Set as default folder</string>
<string name="unset_as_default_folder">Unset as default folder</string>
<string name="reorder_by_dragging">Reorder folders by dragging</string>
<string name="copy_to_restricted_folder_message">The system does not allow copying to this folder.</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -13,6 +13,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog
@ -207,7 +208,7 @@ class NewPhotoEditActivity : SimpleActivity() {
// In case the user wants to overwrite the original file and it is on an SD card, delete it manually first. Else the system just appends (1)
private fun handleFileOverwriting(path: String, callback: () -> Unit) {
if (getDoesFilePathExist(path) && isPathOnSD(path)) {
if (!isRPlus() && getDoesFilePathExist(path) && isPathOnSD(path)) {
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
tryDeleteFileDirItem(fileDirItem, false, true) { success ->
if (success) {

View file

@ -13,6 +13,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog
@ -198,7 +199,7 @@ class NewVideoEditActivity : SimpleActivity() {
// In case the user wants to overwrite the original file and it is on an SD card, delete it manually first. Else the system just appends (1)
private fun handleFileOverwriting(path: String, callback: () -> Unit) {
if (getDoesFilePathExist(path) && isPathOnSD(path)) {
if (!isRPlus() && getDoesFilePathExist(path) && isPathOnSD(path)) {
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
tryDeleteFileDirItem(fileDirItem, false, true) { success ->
if (success) {