From 15b39b501d4772c0bf50c163c95680dc8ed271c8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Apr 2017 22:41:53 +0200 Subject: [PATCH] use the file output stream creator from Commons lib --- .../gallery/activities/EditActivity.kt | 20 ++++++------------- .../gallery/activities/ViewPagerActivity.kt | 15 ++------------ 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 1cc7ff603..ecc00aaa9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -8,7 +8,10 @@ import android.os.Bundle import android.util.Log import android.view.Menu 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.dialogs.ResizeDialog import com.simplemobiletools.gallery.dialogs.SaveAsDialog @@ -16,7 +19,6 @@ import com.simplemobiletools.gallery.extensions.getRealPathFromURI import com.theartofdev.edmodo.cropper.CropImageView import kotlinx.android.synthetic.main.view_crop_image.* import java.io.File -import java.io.FileOutputStream import java.io.OutputStream class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener { @@ -118,18 +120,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener val file = File(path) try { - if (needsStupidWritePermissions(path)) { - handleSAFDialog(file) { - 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) + getFileOutputStream(file) { + saveBitmap(file, bitmap, it) } } catch (e: Exception) { Log.e(TAG, "Crop compressing failed $path $e") diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 68e3ce1e9..cbbdc4897 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -36,7 +36,6 @@ import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_medium.* import java.io.File -import java.io.FileOutputStream import java.io.OutputStream import java.util.* @@ -241,18 +240,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } val bitmap = BitmapFactory.decodeFile(currPath) - if (needsStupidWritePermissions(it)) { - handleSAFDialog(file) { - 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) + getFileOutputStream(file) { + saveFile(file, bitmap, it) } } catch (e: OutOfMemoryError) { toast(R.string.out_of_memory_error)