From f0af8777a34f55dc7e23ee60a76875c917e94e07 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 27 Oct 2017 10:07:58 +0200 Subject: [PATCH] send the real file path with edit intent --- .../gallery/activities/EditActivity.kt | 36 ++++++++++--------- .../gallery/extensions/activity.kt | 9 ++--- .../gallery/extensions/context.kt | 2 -- .../gallery/helpers/Constants.kt | 1 + 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 2f02fd847..b0391e7a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -7,7 +7,6 @@ import android.graphics.Point import android.net.Uri import android.os.Bundle import android.provider.MediaStore -import android.util.Log import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.extensions.* @@ -15,15 +14,15 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.ResizeDialog import com.simplemobiletools.gallery.dialogs.SaveAsDialog import com.simplemobiletools.gallery.extensions.openEditor +import com.simplemobiletools.gallery.helpers.REAL_FILE_PATH import com.theartofdev.edmodo.cropper.CropImageView import kotlinx.android.synthetic.main.view_crop_image.* import java.io.* class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener { - val TAG = EditActivity::class.java.simpleName - val ASPECT_X = "aspectX" - val ASPECT_Y = "aspectY" - val CROP = "crop" + private val ASPECT_X = "aspectX" + private val ASPECT_Y = "aspectY" + private val CROP = "crop" lateinit var uri: Uri var resizeWidth = 0 @@ -41,18 +40,24 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener return } - uri = intent.data - if (uri.scheme != "file" && uri.scheme != "content") { - toast(R.string.unknown_file_location) - finish() - return + val realPath = intent.extras?.get(REAL_FILE_PATH)?.toString() ?: "" + if (realPath.isNotEmpty()) { + val file = File(realPath) + uri = Uri.fromFile(file) + } else { + uri = intent.data + if (uri.scheme != "file" && uri.scheme != "content") { + toast(R.string.unknown_file_location) + finish() + return + } } isCropIntent = intent.extras?.get(CROP) == "true" crop_image_view.apply { setOnCropImageCompleteListener(this@EditActivity) - setImageUriAsync(intent.data) + setImageUriAsync(uri) if (isCropIntent && shouldCropSquare()) setFixedAspectRatio(true) @@ -66,8 +71,9 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener override fun onStop() { super.onStop() - if (isEditingWithThirdParty) + if (isEditingWithThirdParty) { finish() + } } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -152,11 +158,9 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } } else { toast(R.string.image_editing_failed) - finish() } } else { toast(R.string.unknown_file_location) - finish() } } else { toast("${getString(R.string.image_editing_failed)}: ${result.error.message}") @@ -175,9 +179,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } } } catch (e: Exception) { - Log.e(TAG, "Crop compressing failed $path $e") - toast(R.string.image_editing_failed) - finish() + showErrorToast(e) } catch (e: OutOfMemoryError) { toast(R.string.out_of_memory_error) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 32cd94836..84165cca9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -18,10 +18,7 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.helpers.IS_FROM_GALLERY -import com.simplemobiletools.gallery.helpers.NOMEDIA -import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE -import com.simplemobiletools.gallery.helpers.REQUEST_SET_AS +import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.views.MySquareImageView @@ -106,6 +103,10 @@ fun Activity.openEditor(uri: Uri) { setDataAndType(newUri, getMimeTypeFromUri(newUri)) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + if (uri.scheme == "file" && isNougatPlus()) { + putExtra(REAL_FILE_PATH, uri.path) + } + if (resolveActivity(packageManager) != null) { val chooser = Intent.createChooser(this, getString(R.string.edit_image_with)) startActivityForResult(chooser, REQUEST_EDIT_IMAGE) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 82c101a89..922ad88ff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -10,7 +10,6 @@ import android.os.Build import android.view.WindowManager import com.simplemobiletools.commons.extensions.getFilePublicUri import com.simplemobiletools.commons.extensions.getMimeTypeFromPath -import com.simplemobiletools.commons.extensions.getRealPathFromURI import com.simplemobiletools.commons.extensions.humanizePath import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.activities.SettingsActivity @@ -81,7 +80,6 @@ fun Context.getSortedDirectories(source: ArrayList): ArrayList