make use of real_file_path at the editor

This commit is contained in:
tibbi 2018-02-19 21:11:37 +01:00
parent fb493459de
commit 783d73cff4
4 changed files with 21 additions and 16 deletions

View File

@ -46,7 +46,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.12.6'
implementation 'com.simplemobiletools:commons:3.12.7'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.google.code.gson:gson:2.8.2'

View File

@ -12,6 +12,7 @@ import android.view.Menu
import android.view.MenuItem
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.models.FileDirItem
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.dialogs.ResizeDialog
@ -61,10 +62,10 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
return
}
saveUri = if (intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true) {
intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
} else {
uri
saveUri = when {
intent.extras?.containsKey(REAL_FILE_PATH) == true -> Uri.fromFile(File(intent.extras.get(REAL_FILE_PATH) as String))
intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
else -> uri
}
isCropIntent = intent.extras?.get(CROP) == "true"
@ -172,13 +173,15 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
saveBitmapToFile(result.bitmap, it)
}
} else if (saveUri.scheme == "content") {
val newPath = applicationContext.getRealPathFromURI(saveUri) ?: ""
if (!newPath.isEmpty()) {
SaveAsDialog(this, newPath, true) {
saveBitmapToFile(result.bitmap, it)
}
} else {
toast(R.string.image_editing_failed)
var newPath = applicationContext.getRealPathFromURI(saveUri) ?: ""
var shouldAppendFilename = true
if (newPath.isEmpty()) {
newPath = "$internalStoragePath/${getCurrentFormattedDateTime()}.${saveUri.toString().getFilenameExtension()}"
shouldAppendFilename = false
}
SaveAsDialog(this, newPath, shouldAppendFilename) {
saveBitmapToFile(result.bitmap, it)
}
} else {
toast(R.string.unknown_file_location)
@ -209,11 +212,12 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
}
private fun saveBitmap(file: File, bitmap: Bitmap, out: OutputStream) {
toast(R.string.saving)
if (resizeWidth > 0 && resizeHeight > 0) {
val resized = Bitmap.createScaledBitmap(bitmap, resizeWidth, resizeHeight, false)
resized.compress(file.getCompressionFormat(), 90, out)
resized.compress(file.absolutePath.getCompressionFormat(), 90, out)
} else {
bitmap.compress(file.getCompressionFormat(), 90, out)
bitmap.compress(file.absolutePath.getCompressionFormat(), 90, out)
}
setResult(Activity.RESULT_OK, intent)
scanFinalPath(file.absolutePath)

View File

@ -587,7 +587,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val matrix = Matrix()
matrix.postRotate(mRotationDegrees)
val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
bmp.compress(file.getCompressionFormat(), 90, out)
bmp.compress(file.absolutePath.getCompressionFormat(), 90, out)
}
private fun saveRotation(source: File, destination: File) {

View File

@ -13,7 +13,8 @@ import java.io.File
class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) {
init {
var realPath = File(path).parent.trimEnd('/')
var realPath = path.getParentPath().trimEnd('/')
val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply {
save_as_path.text = activity.humanizePath(realPath)