mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
replace sending real_file_path with extra_output at the editor
This commit is contained in:
parent
f0af8777a3
commit
98bee4022e
2 changed files with 22 additions and 22 deletions
|
@ -14,7 +14,6 @@ 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.*
|
||||
|
@ -25,6 +24,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
private val CROP = "crop"
|
||||
|
||||
lateinit var uri: Uri
|
||||
var saveUri: Uri? = null
|
||||
var resizeWidth = 0
|
||||
var resizeHeight = 0
|
||||
var isCropIntent = false
|
||||
|
@ -40,17 +40,15 @@ 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
|
||||
}
|
||||
uri = intent.data
|
||||
if (uri.scheme != "file" && uri.scheme != "content") {
|
||||
toast(R.string.unknown_file_location)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
if (intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true) {
|
||||
saveUri = intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
|
||||
}
|
||||
|
||||
isCropIntent = intent.extras?.get(CROP) == "true"
|
||||
|
@ -130,15 +128,14 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
|
||||
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
|
||||
if (result.error == null) {
|
||||
if (isCropIntent && intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true) {
|
||||
val targetUri = intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
|
||||
if (isCropIntent && saveUri != null) {
|
||||
var inputStream: InputStream? = null
|
||||
var outputStream: OutputStream? = null
|
||||
try {
|
||||
val stream = ByteArrayOutputStream()
|
||||
result.bitmap.compress(CompressFormat.JPEG, 100, stream)
|
||||
inputStream = ByteArrayInputStream(stream.toByteArray())
|
||||
outputStream = contentResolver.openOutputStream(targetUri)
|
||||
outputStream = contentResolver.openOutputStream(saveUri)
|
||||
inputStream.copyTo(outputStream)
|
||||
} finally {
|
||||
inputStream?.close()
|
||||
|
@ -146,12 +143,12 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
}
|
||||
setResult(RESULT_OK)
|
||||
finish()
|
||||
} else if (uri.scheme == "file") {
|
||||
SaveAsDialog(this, uri.path, true) {
|
||||
} else if (saveUri?.scheme == "file") {
|
||||
SaveAsDialog(this, saveUri!!.path, true) {
|
||||
saveBitmapToFile(result.bitmap, it)
|
||||
}
|
||||
} else if (uri.scheme == "content") {
|
||||
val newPath = applicationContext.getRealPathFromURI(uri) ?: ""
|
||||
} else if (saveUri?.scheme == "content") {
|
||||
val newPath = applicationContext.getRealPathFromURI(saveUri!!) ?: ""
|
||||
if (!newPath.isEmpty()) {
|
||||
SaveAsDialog(this, newPath, true) {
|
||||
saveBitmapToFile(result.bitmap, it)
|
||||
|
|
|
@ -18,7 +18,10 @@ 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.*
|
||||
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.models.Directory
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import com.simplemobiletools.gallery.views.MySquareImageView
|
||||
|
@ -103,8 +106,8 @@ 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 (isNougatPlus()) {
|
||||
putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||
}
|
||||
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
|
|
Loading…
Reference in a new issue