mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +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) {
|
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()
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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) {
|
||||||
toast(R.string.unknown_error_occurred)
|
if (showToasts) {
|
||||||
|
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) {
|
||||||
toast(R.string.out_of_memory_error)
|
if (showToasts) {
|
||||||
|
toast(R.string.out_of_memory_error)
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
if (showToasts) {
|
||||||
|
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()
|
||||||
toast(R.string.file_saved)
|
if (showToasts) {
|
||||||
|
toast(R.string.file_saved)
|
||||||
|
}
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
if (showToasts) {
|
||||||
|
showErrorToast(e)
|
||||||
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue