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) {
toast(R.string.saving)
Thread {
saveRotatedImageToFile(currPath, it, mRotationDegrees) {
saveRotatedImageToFile(currPath, it, mRotationDegrees, true) {
toast(R.string.file_saved)
mRotationDegrees = 0
invalidateOptionsMenu()

View file

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