From 8441e51f84701b0d1517d99b8c0102be15f76f93 Mon Sep 17 00:00:00 2001 From: Space-FuCheng <73419850+Space-FuCheng@users.noreply.github.com> Date: Tue, 15 Sep 2026 09:16:46 +0000 Subject: [PATCH 1/2] Fix CSV UTF-8 encoding detection in Excel --- .../data_local/file/CsvRepoImpl.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt index da1a5f54bc..e2f6ea5cf9 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt @@ -61,6 +61,9 @@ class CsvRepoImpl @Inject constructor( fileOutputStream = fileDescriptor?.fileDescriptor ?.let(::FileOutputStream)?.buffered() + // Write UTF-8 BOM so Excel can detect the CSV encoding correctly. + fileOutputStream?.write(UTF8_BOM) + // Write csv header fileOutputStream?.write(CSV_HEADER.toByteArray()) @@ -176,20 +179,22 @@ class CsvRepoImpl @Inject constructor( note = "", ) val newTypeId = recordTypeRepo.add(newType) - newType.copy(id = newTypeId).let(newAddedTypes::add) + newAddedTypes.add(newType.copy(id = newTypeId)) newTypeId } - val record = Record( - typeId = typeId, - timeStarted = timeStarted, - timeEnded = timeEnded, - comment = comment, - tags = emptyList(), + recordRepo.add( + Record( + typeId = typeId, + timeStarted = timeStarted, + timeEnded = timeEnded, + comment = comment, + tags = emptyList(), + ), ) - recordRepo.add(record) addedRecords++ } } + val messageText = resourceRepo.getString(R.string.message_import_complete) val messageHint = resourceRepo.getString(R.string.message_import_complete_hint, addedRecords) ResultCode.Success("$messageText\n$messageHint") @@ -279,7 +284,8 @@ class CsvRepoImpl @Inject constructor( companion object { private const val QUOTE = "\"" + private val UTF8_BOM = byteArrayOf(0xEF.toByte(), 0xBB.toByte(), 0xBF.toByte()) private const val CSV_HEADER = "activity name,time started,time ended,comment,categories,record tags,duration,duration minutes\n" } -} \ No newline at end of file +} From 340cdceaf33f33bb32307f1786b1dfd9faedb623 Mon Sep 17 00:00:00 2001 From: Space-FuCheng <73419850+Space-FuCheng@users.noreply.github.com> Date: Tue, 15 Sep 2026 09:17:49 +0000 Subject: [PATCH 2/2] Keep CSV BOM change minimal --- .../data_local/file/CsvRepoImpl.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt index e2f6ea5cf9..41752fbe00 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/file/CsvRepoImpl.kt @@ -179,22 +179,20 @@ class CsvRepoImpl @Inject constructor( note = "", ) val newTypeId = recordTypeRepo.add(newType) - newAddedTypes.add(newType.copy(id = newTypeId)) + newType.copy(id = newTypeId).let(newAddedTypes::add) newTypeId } - recordRepo.add( - Record( - typeId = typeId, - timeStarted = timeStarted, - timeEnded = timeEnded, - comment = comment, - tags = emptyList(), - ), + val record = Record( + typeId = typeId, + timeStarted = timeStarted, + timeEnded = timeEnded, + comment = comment, + tags = emptyList(), ) + recordRepo.add(record) addedRecords++ } } - val messageText = resourceRepo.getString(R.string.message_import_complete) val messageHint = resourceRepo.getString(R.string.message_import_complete_hint, addedRecords) ResultCode.Success("$messageText\n$messageHint") @@ -288,4 +286,4 @@ class CsvRepoImpl @Inject constructor( private const val CSV_HEADER = "activity name,time started,time ended,comment,categories,record tags,duration,duration minutes\n" } -} +} \ No newline at end of file