Skip to content

Commit aa250cd

Browse files
committed
fix reminder
1 parent b5ef9a9 commit aa250cd

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

app/src/main/java/neth/iecal/questphone/ui/screens/quest/templates/SelectFromTemplates.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.compose.material.icons.Icons
2626
import androidx.compose.material.icons.filled.Add
2727
import androidx.compose.material.icons.filled.Clear
2828
import androidx.compose.material.icons.filled.Search
29+
import androidx.compose.material3.AlertDialog
2930
import androidx.compose.material3.Card
3031
import androidx.compose.material3.CardDefaults
3132
import androidx.compose.material3.CircularProgressIndicator
@@ -38,6 +39,7 @@ import androidx.compose.material3.MaterialTheme
3839
import androidx.compose.material3.OutlinedTextField
3940
import androidx.compose.material3.Scaffold
4041
import androidx.compose.material3.Text
42+
import androidx.compose.material3.TextButton
4143
import androidx.compose.material3.TopAppBar
4244
import androidx.compose.material3.TopAppBarDefaults
4345
import androidx.compose.runtime.Composable
@@ -59,6 +61,7 @@ import androidx.core.graphics.toColorInt
5961
import androidx.navigation.NavController
6062
import kotlinx.serialization.Serializable
6163
import neth.iecal.questphone.data.IntegrationId
64+
import neth.iecal.questphone.data.game.User
6265
import neth.iecal.questphone.ui.navigation.Screen
6366
import neth.iecal.questphone.utils.fetchUrlContent
6467
import neth.iecal.questphone.utils.json
@@ -147,6 +150,26 @@ fun SelectFromTemplates(
147150
.fillMaxSize()
148151
.padding(paddingValues)
149152
) {
153+
val showLoginRequiredDialog = remember { mutableStateOf(false) }
154+
if (showLoginRequiredDialog.value) {
155+
AlertDialog(
156+
onDismissRequest = { showLoginRequiredDialog.value = false },
157+
title = {
158+
Text(text = "Login Required For this quest")
159+
},
160+
text = {
161+
Text("This quest can only be performed by signed up users to prevent abuse. Please Logout and try again!\n\n HomeScreen > Open profile > 3 dots > Logout")
162+
},
163+
confirmButton = {
164+
TextButton(onClick = {
165+
showLoginRequiredDialog.value = false
166+
}) {
167+
Text("Okay")
168+
}
169+
}
170+
)
171+
}
172+
150173
LazyColumn(
151174
modifier = Modifier.fillMaxSize(),
152175
verticalArrangement = Arrangement.spacedBy(12.dp)
@@ -264,7 +287,11 @@ fun SelectFromTemplates(
264287
activity = activity,
265288
modifier = Modifier.padding(horizontal = 16.dp),
266289
onClick = {
267-
navController.navigate(Screen.SetupTemplate.route + activity.id)
290+
if(activity.integration == IntegrationId.AI_SNAP && User.userInfo.isAnonymous){
291+
showLoginRequiredDialog.value = true
292+
}else {
293+
navController.navigate(Screen.SetupTemplate.route + activity.id)
294+
}
268295
}
269296
)
270297
}

app/src/main/java/neth/iecal/questphone/utils/reminder/ReminderBroadcastReciever.kt

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import android.util.Log
1010
import androidx.core.app.NotificationCompat
1111
import kotlinx.coroutines.CoroutineScope
1212
import kotlinx.coroutines.Dispatchers
13-
import kotlinx.coroutines.NonCancellable.isCompleted
1413
import kotlinx.coroutines.launch
14+
import kotlinx.coroutines.withContext
1515
import neth.iecal.questphone.MainActivity
1616
import neth.iecal.questphone.data.quest.QuestDatabaseProvider
1717
import 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

Comments
 (0)