make toast showing at rotating images optional

This commit is contained in:
tibbi 2019-01-29 12:14:08 +01:00
parent 58fe410e85
commit bffa42fe65
3 changed files with 20 additions and 10 deletions

View file

@ -588,7 +588,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
handleSAFDialog(it) { handleSAFDialog(it) {
toast(R.string.saving) toast(R.string.saving)
Thread { Thread {
saveRotatedImageToFile(currPath, it, mRotationDegrees) { saveRotatedImageToFile(currPath, it, mRotationDegrees, true) {
toast(R.string.file_saved) toast(R.string.file_saved)
mRotationDegrees = 0 mRotationDegrees = 0
invalidateOptionsMenu() invalidateOptionsMenu()

View file

@ -281,7 +281,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
val paths = getSelectedPaths().filter { it.isImageFast() } val paths = getSelectedPaths().filter { it.isImageFast() }
var fileCnt = paths.size var fileCnt = paths.size
paths.forEach { paths.forEach {
activity.saveRotatedImageToFile(it, it, degrees) { activity.saveRotatedImageToFile(it, it, degrees, true) {
fileCnt-- fileCnt--
if (fileCnt == 0) { if (fileCnt == 0) {
activity.runOnUiThread { activity.runOnUiThread {

View file

@ -373,9 +373,9 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, 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 (oldPath == newPath && oldPath.isJpg()) {
if (tryRotateByExif(oldPath, degrees, callback)) { if (tryRotateByExif(oldPath, degrees, showToasts, callback)) {
return return
} }
} }
@ -385,7 +385,9 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String,
try { try {
getFileOutputStream(tmpFileDirItem) { getFileOutputStream(tmpFileDirItem) {
if (it == null) { if (it == null) {
if (showToasts) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
}
return@getFileOutputStream return@getFileOutputStream
} }
@ -412,29 +414,37 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String,
callback.invoke() callback.invoke()
} }
} catch (e: OutOfMemoryError) { } catch (e: OutOfMemoryError) {
if (showToasts) {
toast(R.string.out_of_memory_error) toast(R.string.out_of_memory_error)
}
} catch (e: Exception) { } catch (e: Exception) {
if (showToasts) {
showErrorToast(e) showErrorToast(e)
}
} finally { } finally {
tryDeleteFileDirItem(tmpFileDirItem, false, true) tryDeleteFileDirItem(tmpFileDirItem, false, true)
} }
} }
@TargetApi(Build.VERSION_CODES.N) @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 { return try {
val file = File(path) val file = File(path)
val oldLastModified = file.lastModified() val oldLastModified = file.lastModified()
if (saveImageRotation(path, degrees)) { if (saveImageRotation(path, degrees)) {
fileRotatedSuccessfully(path, oldLastModified) fileRotatedSuccessfully(path, oldLastModified)
callback.invoke() callback.invoke()
if (showToasts) {
toast(R.string.file_saved) toast(R.string.file_saved)
}
true true
} else { } else {
false false
} }
} catch (e: Exception) { } catch (e: Exception) {
if (showToasts) {
showErrorToast(e) showErrorToast(e)
}
false false
} }
} }