Ongoing online
This commit is contained in:
@@ -2,11 +2,15 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'Data.dart';
|
||||
import 'Dialogs.dart';
|
||||
import 'User.dart' as User;
|
||||
|
||||
class NotificationManager{
|
||||
|
||||
static var fltrNotification;
|
||||
static void RescheduleNotifications() async{
|
||||
|
||||
if(!User.cacheEnabled){print('Sorry no notifications for: ');return;}
|
||||
@@ -17,10 +21,10 @@ class NotificationManager{
|
||||
|
||||
var initilizationsSettings =
|
||||
new InitializationSettings(android: androidInitilize, iOS: iOSinitilize);
|
||||
var fltrNotification = new FlutterLocalNotificationsPlugin();
|
||||
fltrNotification = new FlutterLocalNotificationsPlugin();
|
||||
fltrNotification.initialize(initilizationsSettings, onSelectNotification: notificationSelected);
|
||||
|
||||
await fltrNotification.cancelAll();
|
||||
await fltrNotification.cancel(0);
|
||||
|
||||
int notification_interval = await Settings.getNotificationInterval();
|
||||
bool adaptive_notification = await Settings.getAdaptiveNotification();
|
||||
@@ -30,6 +34,37 @@ class NotificationManager{
|
||||
var iSODetails = new IOSNotificationDetails();
|
||||
var generalNotificationDetails =
|
||||
new NotificationDetails(android: androidDetails, iOS: iSODetails);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if(prefs.containsKey('current_activity')) {
|
||||
String? ongoingActData = prefs.getString('current_activity');
|
||||
try {
|
||||
if (ongoingActData != null) {
|
||||
List<String> data = ongoingActData.split("<td>");
|
||||
const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails('0', 'Ongoing',
|
||||
ongoing: true,
|
||||
autoCancel: false);
|
||||
const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails);
|
||||
final List<PendingNotificationRequest> pendingNotificationRequests =await fltrNotification.pendingNotificationRequests();
|
||||
bool containsNotification = false;
|
||||
for (var element in pendingNotificationRequests) {
|
||||
if(element.id==1){
|
||||
containsNotification=true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(!containsNotification) {
|
||||
await fltrNotification.show(
|
||||
1, 'Currently doing : ${data[0]}', 'Click on this notification to stop and add this activity', notificationDetails,
|
||||
payload: 'ongoingActivity');
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
print("error ongoing activity");
|
||||
await fltrNotification.cancel(1);
|
||||
}
|
||||
}else{
|
||||
await fltrNotification.cancel(1);
|
||||
}
|
||||
|
||||
if(adaptive_notification && adaptive_notification_availabel){
|
||||
print("Smart!, Using adaptive huh?");
|
||||
@@ -87,7 +122,7 @@ class NotificationManager{
|
||||
thisTime = thisTime.add(Duration(days: 1));
|
||||
}
|
||||
print("Scheduling at $thisTime");
|
||||
fltrNotification.schedule(key, "Don't forget to add new activity", "Adaptive notifications suggests that you may have done by now to track.", thisTime, generalNotificationDetails);
|
||||
fltrNotification.schedule(0, "Don't forget to add new activity", "Adaptive notifications suggests that you may have done by now to track.", thisTime, generalNotificationDetails);
|
||||
|
||||
}
|
||||
});
|
||||
@@ -111,5 +146,9 @@ class NotificationManager{
|
||||
|
||||
static void notificationSelected(val){
|
||||
print("Selected notifications : $val");
|
||||
if(val=="ongoingActivity"){
|
||||
Dialogs.ongoing();
|
||||
}
|
||||
RescheduleNotifications();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user