send the real file path with edit intent
This commit is contained in:
parent
b98b6e6cb9
commit
f0af8777a3
4 changed files with 25 additions and 23 deletions
|
@ -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
|
||||
}
|
||||
|
||||
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,9 +71,10 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (isEditingWithThirdParty)
|
||||
if (isEditingWithThirdParty) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_editor, menu)
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Directory>): ArrayList<Direct
|
|||
}
|
||||
|
||||
fun Context.getMimeTypeFromUri(uri: Uri): String {
|
||||
val path = getRealPathFromURI(uri)
|
||||
var mimetype = uri.path.getMimeTypeFromPath()
|
||||
if (mimetype.isEmpty()) {
|
||||
mimetype = contentResolver.getType(uri)
|
||||
|
|
|
@ -67,6 +67,7 @@ val DIRECTORIES = "directories2"
|
|||
val IS_VIEW_INTENT = "is_view_intent"
|
||||
val IS_FROM_GALLERY = "is_from_gallery"
|
||||
val PICKED_PATHS = "picked_paths"
|
||||
val REAL_FILE_PATH = "real_file_path"
|
||||
|
||||
val REQUEST_EDIT_IMAGE = 1
|
||||
val REQUEST_SET_AS = 2
|
||||
|
|
Loading…
Reference in a new issue