Skip to content

Commit 3e62d99

Browse files
refactor: Extract event key Intent format to single source of truth (#231)
Added toIntentString() and fromIntentString() methods to EventAlertRecordKey class to ensure the event key format used in Intent extras is defined in one place. This prevents format mismatches between serialization and parsing. - EventAlertRecordKey.toIntentString(): Serializes key for Intent extras - EventAlertRecordKey.fromIntentString(): Parses key from Intent extras - Updated ActiveEventsFragment to use toIntentString() - Updated ApplicationController to use fromIntentString() Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent a7c42c1 commit 3e62d99

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

android/app/src/main/java/com/github/quarck/calnotify/app/ApplicationController.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -976,17 +976,10 @@ object ApplicationController : ApplicationControllerInterface, EventMovedHandler
976976
): SnoozeResult? {
977977
if (eventKeys.isEmpty()) return null
978978

979-
// Parse event keys into (eventId, instanceStartTime) pairs
980-
val keyPairs = eventKeys.mapNotNull { key ->
981-
val parts = key.split(":")
982-
if (parts.size == 2) {
983-
val eventId = parts[0].toLongOrNull()
984-
val instanceStartTime = parts[1].toLongOrNull()
985-
if (eventId != null && instanceStartTime != null) {
986-
Pair(eventId, instanceStartTime)
987-
} else null
988-
} else null
989-
}.toSet()
979+
// Parse event keys into (eventId, instanceStartTime) pairs using the shared format
980+
val keyPairs = eventKeys.mapNotNull { EventAlertRecordKey.fromIntentString(it) }
981+
.map { Pair(it.eventId, it.instanceStartTime) }
982+
.toSet()
990983

991984
return snoozeEvents(context, { event ->
992985
keyPairs.contains(Pair(event.eventId, event.instanceStartTime))

android/app/src/main/java/com/github/quarck/calnotify/calendar/EventAlertRecord.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,22 @@ fun Long.setFlag(flag: Long, value: Boolean)
110110
else
111111
this and flag.inv()
112112

113-
data class EventAlertRecordKey(val eventId: Long, val instanceStartTime: Long)
113+
data class EventAlertRecordKey(val eventId: Long, val instanceStartTime: Long) {
114+
115+
/** Serialize for Intent extras */
116+
fun toIntentString(): String = "$eventId:$instanceStartTime"
117+
118+
companion object {
119+
/** Parse from Intent extras */
120+
fun fromIntentString(key: String): EventAlertRecordKey? {
121+
val parts = key.split(":")
122+
if (parts.size != 2) return null
123+
val eventId = parts[0].toLongOrNull() ?: return null
124+
val instanceStartTime = parts[1].toLongOrNull() ?: return null
125+
return EventAlertRecordKey(eventId, instanceStartTime)
126+
}
127+
}
128+
}
114129

115130
data class EventAlertRecord(
116131
val calendarId: Long,

android/app/src/main/java/com/github/quarck/calnotify/ui/ActiveEventsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class ActiveEventsFragment : Fragment(), EventListCallback, SearchableFragment,
182182
val isChange = !hasActiveEvents
183183

184184
// Pass selected event keys to SnoozeAllActivity via intent
185-
val eventKeys = selectedEvents.map { "${it.eventId}:${it.instanceStartTime}" }.toTypedArray()
185+
val eventKeys = selectedEvents.map { it.key.toIntentString() }.toTypedArray()
186186

187187
// Get filter/search context for display
188188
val filterState = getFilterState()

0 commit comments

Comments
 (0)