refactor: Create a model to handle realtime push notification

This commit is contained in:
Andrea Busi
2023-07-13 16:35:50 +02:00
parent 2b98a4e292
commit b44a0a2e27
10 changed files with 265 additions and 186 deletions
@@ -116,14 +116,13 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) {
// controlliamo se c'è una notifica in tempo reale da mostrare
NSDate *date = [[NSUserDefaults standardUserDefaults] objectForKey:EQNUserDefaultRealTimeAlertDate];
NSDictionary *info = [EQNUtility loadDictionaryFromUserDefaultsForKey:EQNUserDefaultRealTimeAlertPayload];
if (date && info && [EQNUtility getDifferenceMinute:date] < EQNRealtimeAlertExpiration) {
EQNRealtimePushNotification *notification = [EQNRealtimePushNotification storedNotification];
if (date && notification && [EQNUtility getDifferenceMinute:date] < EQNRealtimeAlertExpiration) {
self.isNotificaAttiva = YES;
// mostriamo la schermata solo se il countdown non è a zero
EQNRealtimeAlert *alert = [[EQNRealtimeAlert alloc] initWithNotification:info];
if (alert != nil && ![alert isCountdownExpired]) {
RealtimeAlertViewController *controller = [[RealtimeAlertViewController alloc] initWithAlert:alert];
if (![notification isCountdownExpired]) {
RealtimeAlertViewController *controller = [[RealtimeAlertViewController alloc] initWithNotification:notification];
if (@available(iOS 13.0, *)) {
controller.modalInPresentation = YES;
}
@@ -161,7 +160,7 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) {
- (void)resetRealtimeAlert
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:EQNUserDefaultRealTimeAlertDate];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:EQNUserDefaultRealTimeAlertPayload];
[EQNRealtimePushNotification removeStoredNotification];
self.isNotificaAttiva = NO;
}
@@ -265,8 +264,8 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) {
} else if (tableRow == AllerteTableRowSismiRilevati) {
if (self.isNotificaAttiva) {
AlertsSeismicNotificationExpandedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SeismicNotificationExpandedCell" forIndexPath:indexPath];
NSDictionary *info = [EQNUtility loadDictionaryFromUserDefaultsForKey:EQNUserDefaultRealTimeAlertPayload];
cell.notification = info;
EQNRealtimePushNotification *notification = [EQNRealtimePushNotification storedNotification];
cell.notification = notification;
__weak AllerteViewController *weakSelf = self;
cell.onTapClose = ^{