@@ -10,8 +10,8 @@ import android.util.Log
1010import androidx.core.app.NotificationCompat
1111import kotlinx.coroutines.CoroutineScope
1212import kotlinx.coroutines.Dispatchers
13- import kotlinx.coroutines.NonCancellable.isCompleted
1413import kotlinx.coroutines.launch
14+ import kotlinx.coroutines.withContext
1515import neth.iecal.questphone.MainActivity
1616import neth.iecal.questphone.data.quest.QuestDatabaseProvider
1717import neth.iecal.questphone.utils.getCurrentDate
@@ -33,18 +33,20 @@ class ReminderBroadcastReceiver : BroadcastReceiver() {
3333 val dao = QuestDatabaseProvider .getInstance(context).questDao()
3434 CoroutineScope (Dispatchers .Default ).launch {
3535 val quest = dao.getQuestById(reminderId)
36- if (quest!= null ){
37- val isNotCompleted = quest.last_completed_on != getCurrentDate()
38- generateReminders(context,quest)
39- if (reminderId.isNotEmpty()) {
40- if (isCompleted) {
41- // Display the notification using the extracted details
42- showNotification(it, reminderId.hashCode(), title, description)
43- Log .d(" ReminderBroadcastReceiver" , " Received alarm for reminder ID: $reminderId , Title: '$title '" )
44- }
36+ withContext(Dispatchers .Main ) {
37+ if (quest!= null ){
38+ val isNotCompleted = quest.last_completed_on != getCurrentDate()
39+ generateReminders(context,quest)
40+ if (reminderId.isNotEmpty()) {
41+ if (isNotCompleted) {
42+ // Display the notification using the extracted details
43+ showNotification(it, reminderId.hashCode(), title, description)
44+ Log .d(" ReminderBroadcastReceiver" , " Received alarm for reminder ID: $reminderId , Title: '$title '" )
45+ }
4546 } else {
4647 Log .e(" ReminderBroadcastReceiver" , " Received intent with an invalid reminder ID." )
4748 }
49+ }
4850 }
4951 }
5052
@@ -86,22 +88,9 @@ class ReminderBroadcastReceiver : BroadcastReceiver() {
8688 .setPriority(NotificationCompat .PRIORITY_HIGH ) // Set the priority (visual prominence)
8789 .setCategory(NotificationCompat .CATEGORY_REMINDER ) // Categorize as a reminder
8890 .setContentIntent(pendingIntent) // Set the action when notification is clicked
91+ .setGroup(null ) // avoid accidental grouping
92+ .setGroupSummary(false )
8993 .setAutoCancel(false ) // Automatically dismisses the notification when tapped by the user
90- .apply {
91- // Optional: Add action buttons to the notification (e.g., "Mark as Done", "Snooze")
92- // Example for a "Mark as Done" action:
93- // val doneIntent = Intent(context, ReminderActionReceiver::class.java).apply {
94- // action = "ACTION_MARK_DONE"
95- // putExtra(NotificationScheduler.EXTRA_REMINDER_ID, reminderId)
96- // }
97- // val donePendingIntent = PendingIntent.getBroadcast(
98- // context,
99- // reminderId + 1000, // Use a different request code for actions
100- // doneIntent,
101- // PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
102- // )
103- // addAction(R.drawable.ic_done, "Mark Done", donePendingIntent)
104- }
10594 .build()
10695
10796 // Display the notification.
0 commit comments