From bffa42fe65103ea821ee69ca08cb2197f8fe92d9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 29 Jan 2019 12:14:08 +0100 Subject: [PATCH] make toast showing at rotating images optional --- .../pro/activities/ViewPagerActivity.kt | 2 +- .../gallery/pro/adapters/MediaAdapter.kt | 2 +- .../gallery/pro/extensions/Activity.kt | 26 +++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 78499a5d6..2e70b9ba7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -588,7 +588,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View handleSAFDialog(it) { toast(R.string.saving) Thread { - saveRotatedImageToFile(currPath, it, mRotationDegrees) { + saveRotatedImageToFile(currPath, it, mRotationDegrees, true) { toast(R.string.file_saved) mRotationDegrees = 0 invalidateOptionsMenu() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 183ad56c7..d103b748a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -281,7 +281,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, callback: (() -> Unit)? = nu } } -fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, degrees: Int, callback: () -> Unit) { +fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, degrees: Int, showToasts: Boolean, callback: () -> Unit) { if (oldPath == newPath && oldPath.isJpg()) { - if (tryRotateByExif(oldPath, degrees, callback)) { + if (tryRotateByExif(oldPath, degrees, showToasts, callback)) { return } } @@ -385,7 +385,9 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, try { getFileOutputStream(tmpFileDirItem) { if (it == null) { - toast(R.string.unknown_error_occurred) + if (showToasts) { + toast(R.string.unknown_error_occurred) + } return@getFileOutputStream } @@ -412,29 +414,37 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, callback.invoke() } } catch (e: OutOfMemoryError) { - toast(R.string.out_of_memory_error) + if (showToasts) { + toast(R.string.out_of_memory_error) + } } catch (e: Exception) { - showErrorToast(e) + if (showToasts) { + showErrorToast(e) + } } finally { tryDeleteFileDirItem(tmpFileDirItem, false, true) } } @TargetApi(Build.VERSION_CODES.N) -fun Activity.tryRotateByExif(path: String, degrees: Int, callback: () -> Unit): Boolean { +fun Activity.tryRotateByExif(path: String, degrees: Int, showToasts: Boolean, callback: () -> Unit): Boolean { return try { val file = File(path) val oldLastModified = file.lastModified() if (saveImageRotation(path, degrees)) { fileRotatedSuccessfully(path, oldLastModified) callback.invoke() - toast(R.string.file_saved) + if (showToasts) { + toast(R.string.file_saved) + } true } else { false } } catch (e: Exception) { - showErrorToast(e) + if (showToasts) { + showErrorToast(e) + } false } }