always set saveUri at editor activity

This commit is contained in:
tibbi 2017-10-27 14:02:11 +02:00
parent b3427c57ab
commit b6a266d436

View file

@ -24,7 +24,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
private val CROP = "crop" private val CROP = "crop"
lateinit var uri: Uri lateinit var uri: Uri
var saveUri: Uri? = null lateinit var saveUri: Uri
var resizeWidth = 0 var resizeWidth = 0
var resizeHeight = 0 var resizeHeight = 0
var isCropIntent = false var isCropIntent = false
@ -47,8 +47,10 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
return return
} }
if (intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true) { saveUri = if (intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true) {
saveUri = intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
} else {
uri
} }
isCropIntent = intent.extras?.get(CROP) == "true" isCropIntent = intent.extras?.get(CROP) == "true"
@ -128,7 +130,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) { override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
if (result.error == null) { if (result.error == null) {
if (isCropIntent && saveUri != null) { if (isCropIntent) {
var inputStream: InputStream? = null var inputStream: InputStream? = null
var outputStream: OutputStream? = null var outputStream: OutputStream? = null
try { try {
@ -143,12 +145,12 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
} }
setResult(RESULT_OK) setResult(RESULT_OK)
finish() finish()
} else if (saveUri?.scheme == "file") { } else if (saveUri.scheme == "file") {
SaveAsDialog(this, saveUri!!.path, true) { SaveAsDialog(this, saveUri.path, true) {
saveBitmapToFile(result.bitmap, it) saveBitmapToFile(result.bitmap, it)
} }
} else if (saveUri?.scheme == "content") { } else if (saveUri.scheme == "content") {
val newPath = applicationContext.getRealPathFromURI(saveUri!!) ?: "" val newPath = applicationContext.getRealPathFromURI(saveUri) ?: ""
if (!newPath.isEmpty()) { if (!newPath.isEmpty()) {
SaveAsDialog(this, newPath, true) { SaveAsDialog(this, newPath, true) {
saveBitmapToFile(result.bitmap, it) saveBitmapToFile(result.bitmap, it)