use the file output stream creator from Commons lib
This commit is contained in:
parent
49f7fc389a
commit
15b39b501d
2 changed files with 8 additions and 27 deletions
|
@ -8,7 +8,10 @@ import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.getCompressionFormat
|
||||||
|
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
||||||
|
import com.simplemobiletools.commons.extensions.scanPath
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.dialogs.ResizeDialog
|
import com.simplemobiletools.gallery.dialogs.ResizeDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
|
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
|
||||||
|
@ -16,7 +19,6 @@ import com.simplemobiletools.gallery.extensions.getRealPathFromURI
|
||||||
import com.theartofdev.edmodo.cropper.CropImageView
|
import com.theartofdev.edmodo.cropper.CropImageView
|
||||||
import kotlinx.android.synthetic.main.view_crop_image.*
|
import kotlinx.android.synthetic.main.view_crop_image.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
||||||
|
@ -118,18 +120,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (needsStupidWritePermissions(path)) {
|
getFileOutputStream(file) {
|
||||||
handleSAFDialog(file) {
|
saveBitmap(file, bitmap, it)
|
||||||
var document = getFileDocument(path) ?: return@handleSAFDialog
|
|
||||||
if (!file.exists()) {
|
|
||||||
document = document.createFile("", file.name)
|
|
||||||
}
|
|
||||||
val out = contentResolver.openOutputStream(document.uri)
|
|
||||||
saveBitmap(file, bitmap, out)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val out = FileOutputStream(file)
|
|
||||||
saveBitmap(file, bitmap, out)
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Crop compressing failed $path $e")
|
Log.e(TAG, "Crop compressing failed $path $e")
|
||||||
|
|
|
@ -36,7 +36,6 @@ import com.simplemobiletools.gallery.helpers.*
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.activity_medium.*
|
import kotlinx.android.synthetic.main.activity_medium.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -241,18 +240,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
val bitmap = BitmapFactory.decodeFile(currPath)
|
val bitmap = BitmapFactory.decodeFile(currPath)
|
||||||
if (needsStupidWritePermissions(it)) {
|
getFileOutputStream(file) {
|
||||||
handleSAFDialog(file) {
|
saveFile(file, bitmap, it)
|
||||||
var document = getFileDocument(it) ?: return@handleSAFDialog
|
|
||||||
if (!file.exists()) {
|
|
||||||
document = document.createFile("", file.name)
|
|
||||||
}
|
|
||||||
val out = contentResolver.openOutputStream(document.uri)
|
|
||||||
saveFile(file, bitmap, out)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val out = FileOutputStream(file)
|
|
||||||
saveFile(file, bitmap, out)
|
|
||||||
}
|
}
|
||||||
} catch (e: OutOfMemoryError) {
|
} catch (e: OutOfMemoryError) {
|
||||||
toast(R.string.out_of_memory_error)
|
toast(R.string.out_of_memory_error)
|
||||||
|
|
Loading…
Reference in a new issue