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

View file

@ -587,7 +587,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val matrix = Matrix() val matrix = Matrix()
matrix.postRotate(mRotationDegrees) matrix.postRotate(mRotationDegrees)
val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) 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) { 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) { class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) {
init { init {
var realPath = File(path).parent.trimEnd('/') var realPath = path.getParentPath().trimEnd('/')
val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply { val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply {
save_as_path.text = activity.humanizePath(realPath) save_as_path.text = activity.humanizePath(realPath)