From b0ee08fd521606acc49553b52567480e332f465e Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 20 Mar 2026 12:57:06 -0400 Subject: [PATCH 1/3] fix: fix issue where when editing outside the app and saving to gallery, the timestamp of the photo was in UTC --- .../ioncameralib/helper/IONCAMRExifHelper.kt | 19 +++++++++++++++++++ .../helper/IONCAMRExifHelperInterface.kt | 1 + .../manager/IONCAMRCameraManager.kt | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt b/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt index 8c6ebc5..335c01e 100644 --- a/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt +++ b/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt @@ -22,6 +22,9 @@ package io.ionic.libs.ioncameralib.helper import android.media.ExifInterface import android.net.Uri import java.io.IOException +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale class IONCAMRExifHelper : IONCAMRExifHelperInterface { @@ -203,4 +206,20 @@ class IONCAMRExifHelper : IONCAMRExifHelperInterface { ) } + override fun setCurrentDateTime() { + if (outFile == null) { + return + } + // Format datetime as EXIF expects: "yyyy:MM:dd HH:mm:ss" + val currentDateTime = SimpleDateFormat( + "yyyy:MM:dd HH:mm:ss", + Locale.getDefault() + ).format(Date()) + + outFile!!.setAttribute(ExifInterface.TAG_DATETIME, currentDateTime) + outFile!!.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, currentDateTime) + outFile!!.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, currentDateTime) + outFile!!.saveAttributes() + } + } \ No newline at end of file diff --git a/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelperInterface.kt b/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelperInterface.kt index 30a710b..8f766c5 100644 --- a/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelperInterface.kt +++ b/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelperInterface.kt @@ -13,4 +13,5 @@ interface IONCAMRExifHelperInterface { fun getOrientation(): Int fun resetOrientation() fun getOrientationFromExif(exif: ExifInterface): Int + fun setCurrentDateTime() } \ No newline at end of file diff --git a/src/main/kotlin/io/ionic/libs/ioncameralib/manager/IONCAMRCameraManager.kt b/src/main/kotlin/io/ionic/libs/ioncameralib/manager/IONCAMRCameraManager.kt index 7d0ad98..813eeb0 100644 --- a/src/main/kotlin/io/ionic/libs/ioncameralib/manager/IONCAMRCameraManager.kt +++ b/src/main/kotlin/io/ionic/libs/ioncameralib/manager/IONCAMRCameraManager.kt @@ -205,6 +205,13 @@ class IONCAMRCameraManager( try { exif.createInFile(sourcePath) exif.readExifData() + + // When editing externally, the external app may write EXIF datetime in UTC. + // Fix it by writing the current local datetime back to the file. + if (camParameters.allowEdit && !intentEditedPath.isNullOrEmpty()) { + exif.createOutFile(sourcePath) + exif.setCurrentDateTime() + } } catch (e: IOException) { e.printStackTrace() } From 103af3c5104bf3c597655fc32320b7229b06f87c Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 20 Mar 2026 12:57:56 -0400 Subject: [PATCH 2/3] chore: update unit tests --- .../io/ionic/libs/ioncameralib/mocks/IONExifHelperMock.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/kotlin/io/ionic/libs/ioncameralib/mocks/IONExifHelperMock.kt b/src/test/kotlin/io/ionic/libs/ioncameralib/mocks/IONExifHelperMock.kt index edc2af2..a85e9a0 100644 --- a/src/test/kotlin/io/ionic/libs/ioncameralib/mocks/IONExifHelperMock.kt +++ b/src/test/kotlin/io/ionic/libs/ioncameralib/mocks/IONExifHelperMock.kt @@ -43,4 +43,8 @@ class IONExifHelperMock: IONCAMRExifHelperInterface { override fun getOrientationFromExif(exif: ExifInterface): Int { return testOrientation } + + override fun setCurrentDateTime() { + // do nothing + } } \ No newline at end of file From d3f53521f681e2a89dab6f2840cbacca01200aa9 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 20 Mar 2026 13:45:39 -0400 Subject: [PATCH 3/3] refactor: use let instead of force unwrapping --- .../libs/ioncameralib/helper/IONCAMRExifHelper.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt b/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt index 335c01e..c5ee95e 100644 --- a/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt +++ b/src/main/kotlin/io/ionic/libs/ioncameralib/helper/IONCAMRExifHelper.kt @@ -207,19 +207,18 @@ class IONCAMRExifHelper : IONCAMRExifHelperInterface { } override fun setCurrentDateTime() { - if (outFile == null) { - return - } // Format datetime as EXIF expects: "yyyy:MM:dd HH:mm:ss" val currentDateTime = SimpleDateFormat( "yyyy:MM:dd HH:mm:ss", Locale.getDefault() ).format(Date()) - outFile!!.setAttribute(ExifInterface.TAG_DATETIME, currentDateTime) - outFile!!.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, currentDateTime) - outFile!!.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, currentDateTime) - outFile!!.saveAttributes() + outFile?.let { + it.setAttribute(ExifInterface.TAG_DATETIME, currentDateTime) + it.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, currentDateTime) + it.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, currentDateTime) + it.saveAttributes() + } } } \ No newline at end of file