mirror of
https://github.com/vleeuwenmenno/supplements.git
synced 2025-09-11 18:29:12 +02:00
bugfix: retry notification should now only show up if you did NOT yet
take the supplement on that day.
This commit is contained in:
@@ -173,20 +173,35 @@ class NotificationService {
|
|||||||
// Call the callback to record the intake
|
// Call the callback to record the intake
|
||||||
if (_onTakeSupplementCallback != null) {
|
if (_onTakeSupplementCallback != null) {
|
||||||
print('SupplementsLog: 📱 Calling supplement callback...');
|
print('SupplementsLog: 📱 Calling supplement callback...');
|
||||||
_onTakeSupplementCallback!(supplementId, supplementName, units, unitType);
|
_onTakeSupplementCallback!(
|
||||||
|
supplementId, supplementName, units, unitType);
|
||||||
print('SupplementsLog: 📱 Callback completed');
|
print('SupplementsLog: 📱 Callback completed');
|
||||||
} else {
|
} else {
|
||||||
print('SupplementsLog: 📱 ERROR: No callback registered!');
|
print('SupplementsLog: 📱 ERROR: No callback registered!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For retry notifications, the original notification ID is in the payload
|
||||||
|
int originalNotificationId;
|
||||||
|
if (parts.length > 4 && int.tryParse(parts[4]) != null) {
|
||||||
|
originalNotificationId = int.parse(parts[4]);
|
||||||
|
print(
|
||||||
|
'SupplementsLog: 📱 Retry notification detected. Original ID: $originalNotificationId');
|
||||||
|
} else if (notificationId != null) {
|
||||||
|
originalNotificationId = notificationId;
|
||||||
|
} else {
|
||||||
|
print(
|
||||||
|
'SupplementsLog: 📱 ERROR: Could not determine notification ID to cancel.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Mark notification as taken in database (this will cancel any pending retries)
|
// Mark notification as taken in database (this will cancel any pending retries)
|
||||||
if (notificationId != null) {
|
print(
|
||||||
print('SupplementsLog: 📱 Marking notification $notificationId as taken');
|
'SupplementsLog: 📱 Marking notification $originalNotificationId as taken');
|
||||||
await DatabaseHelper.instance.markNotificationTaken(notificationId);
|
await DatabaseHelper.instance
|
||||||
|
.markNotificationTaken(originalNotificationId);
|
||||||
|
|
||||||
// Cancel any pending retry notifications for this notification
|
// Cancel any pending retry notifications for this notification
|
||||||
_cancelRetryNotifications(notificationId);
|
_cancelRetryNotifications(originalNotificationId);
|
||||||
}
|
|
||||||
|
|
||||||
// Show a confirmation notification
|
// Show a confirmation notification
|
||||||
print('SupplementsLog: 📱 Showing confirmation notification...');
|
print('SupplementsLog: 📱 Showing confirmation notification...');
|
||||||
@@ -195,7 +210,8 @@ class NotificationService {
|
|||||||
'$supplementName has been recorded at ${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')}',
|
'$supplementName has been recorded at ${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')}',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print('SupplementsLog: 📱 ERROR: Invalid payload format - not enough parts');
|
print(
|
||||||
|
'SupplementsLog: 📱 ERROR: Invalid payload format - not enough parts');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('SupplementsLog: 📱 ERROR in _handleTakeAction: $e');
|
print('SupplementsLog: 📱 ERROR in _handleTakeAction: $e');
|
||||||
|
Reference in New Issue
Block a user