Skip to content

Commit 1da2ebd

Browse files
authored
refactor: notification settings overhaul cleanup (#150)
1 parent e28c82b commit 1da2ebd

6 files changed

Lines changed: 51 additions & 104 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ object NotificationChannels {
3939
const val GROUP_ID_ALARM = "group_alarm"
4040
const val GROUP_ID_SILENT = "group_silent"
4141

42-
// Channel IDs - these are user-visible in system settings
42+
// Channel IDs - IMPORTANT: These must match the string resources in strings.xml
43+
// (channel_id_default, channel_id_alarm, etc.) which are used by XML preferences.
44+
// See NotificationChannelsRobolectricTest for sync verification.
4345
const val CHANNEL_ID_DEFAULT = "calendar_events"
4446
const val CHANNEL_ID_ALARM = "calendar_alarm"
4547
const val CHANNEL_ID_SILENT = "calendar_silent"

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

Lines changed: 0 additions & 101 deletions
This file was deleted.

android/app/src/main/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@
373373
<string name="alarm_tag">#alarm</string>
374374
<string name="create_event">Create Event</string>
375375

376+
<!-- Notification channel IDs (not translatable - must match NotificationChannels.kt constants) -->
377+
<string name="channel_id_default" translatable="false">calendar_events</string>
378+
<string name="channel_id_alarm" translatable="false">calendar_alarm</string>
379+
<string name="channel_id_silent" translatable="false">calendar_silent</string>
380+
<string name="channel_id_reminders" translatable="false">calendar_reminders</string>
381+
<string name="channel_id_alarm_reminders" translatable="false">calendar_alarm_reminders</string>
382+
383+
<!-- Notification channel display names -->
376384
<string name="notification_channel_default">Calendar Events</string>
377385
<string name="notification_channel_default_desc">Default channel for calendar events</string>
378386
<string name="notification_channel_alarm">Alarm Notifications</string>

android/app/src/main/res/xml/notification_preferences_x.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
android:key="pref_key_ringtone"
2323
android:title="@string/ringtone_calendar_events"
2424
android:ringtoneType="notification"
25-
app:channelId="calendar_events" />
25+
app:channelId="@string/channel_id_default" />
2626

2727
<Preference
2828
android:key="pref_all_sound_notification_channels"

android/app/src/main/res/xml/reminder_preferences_x.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
android:title="@string/ringtone_reminder"
3535
android:ringtoneType="notification"
3636
android:dependency="reminders_custom_ringtone"
37-
app:channelId="calendar_reminders" />
37+
app:channelId="@string/channel_id_reminders" />
3838

3939
<CheckBoxPreference
4040
android:key="reminders_custom_vibration"

android/app/src/test/java/com/github/quarck/calnotify/notification/NotificationChannelsRobolectricTest.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,43 @@ class NotificationChannelsRobolectricTest {
261261
// Assert
262262
assertEquals("Silent", title)
263263
}
264+
265+
// === String resource sync tests ===
266+
// These tests ensure the Kotlin constants match the string resources used in XML preferences
267+
268+
@Test
269+
fun `channel ID constants match string resources - default`() {
270+
val stringResource = context.getString(com.github.quarck.calnotify.R.string.channel_id_default)
271+
assertEquals("Channel ID constant must match string resource",
272+
NotificationChannels.CHANNEL_ID_DEFAULT, stringResource)
273+
}
274+
275+
@Test
276+
fun `channel ID constants match string resources - alarm`() {
277+
val stringResource = context.getString(com.github.quarck.calnotify.R.string.channel_id_alarm)
278+
assertEquals("Channel ID constant must match string resource",
279+
NotificationChannels.CHANNEL_ID_ALARM, stringResource)
280+
}
281+
282+
@Test
283+
fun `channel ID constants match string resources - silent`() {
284+
val stringResource = context.getString(com.github.quarck.calnotify.R.string.channel_id_silent)
285+
assertEquals("Channel ID constant must match string resource",
286+
NotificationChannels.CHANNEL_ID_SILENT, stringResource)
287+
}
288+
289+
@Test
290+
fun `channel ID constants match string resources - reminders`() {
291+
val stringResource = context.getString(com.github.quarck.calnotify.R.string.channel_id_reminders)
292+
assertEquals("Channel ID constant must match string resource",
293+
NotificationChannels.CHANNEL_ID_REMINDERS, stringResource)
294+
}
295+
296+
@Test
297+
fun `channel ID constants match string resources - alarm reminders`() {
298+
val stringResource = context.getString(com.github.quarck.calnotify.R.string.channel_id_alarm_reminders)
299+
assertEquals("Channel ID constant must match string resource",
300+
NotificationChannels.CHANNEL_ID_ALARM_REMINDERS, stringResource)
301+
}
264302
}
265303

0 commit comments

Comments
 (0)