mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
make toast showing at rotating images optional
This commit is contained in:
parent
58fe410e85
commit
bffa42fe65
3 changed files with 20 additions and 10 deletions
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
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) {
|
||||
if (showToasts) {
|
||||
toast(R.string.out_of_memory_error)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
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()
|
||||
if (showToasts) {
|
||||
toast(R.string.file_saved)
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (showToasts) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue