Skip to content

Commit

Permalink
Added limit on nofication
Browse files Browse the repository at this point in the history
  • Loading branch information
iqfareez committed Jan 21, 2021
1 parent ce10962 commit df47ffa
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 87 deletions.
3 changes: 3 additions & 0 deletions lib/CONSTANTS.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const kStoredTimeIs12 = "storedTimeFormat";
const kStoredShowOtherPrayerTime = "storedshowothertime";
const kStoredApiPrayerCall = "storedApiPrayCall";
const kStoredApiLocationCall = "storedApiLocCall";
const kStoredShouldUpdateNotif = "storedShouldUpdateNotif";
const kStoredLastUpdateNotif = "storedLastUpdateNotif";
const kStoredNotificationLimit = "storedNotificationLimit";

//Network image
const kAppIconUrl =
Expand Down
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ void initGetStorage() {
GetStorage().writeIfNull(kStoredFirstRun, true);
GetStorage().writeIfNull(kStoredTimeIs12, true);
GetStorage().writeIfNull(kStoredShowOtherPrayerTime, false);
GetStorage().writeIfNull(kStoredShouldUpdateNotif, true);
GetStorage().writeIfNull(kStoredLastUpdateNotif, 0);
GetStorage().writeIfNull(kStoredNotificationLimit, false);
}

Future<void> _configureLocalTimeZone() async {
Expand Down
19 changes: 17 additions & 2 deletions lib/utils/isolate_handler_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ void schedulePrayNotification(List<dynamic> times) async {

var currentTime = DateTime.now().millisecondsSinceEpoch;

for (int i = 0; i < times.length; i++) {
var howMuchToSchedule;

if (GetStorage().read(kStoredNotificationLimit)) {
//should limit to 7
//TODO: Check this logic wether work on not
howMuchToSchedule = times.length < 7 ? times.length : 7;
} else {
howMuchToSchedule = times.length;
}

print('howMuchToSchedule is $howMuchToSchedule');

for (int i = 0; i < howMuchToSchedule; i++) {
//i denotes the day relative for today
int subuhTimeEpoch = times[i][0] * 1000;
int syurukTimeEpoch = times[i][1] * 1000;
Expand Down Expand Up @@ -93,7 +105,7 @@ void schedulePrayNotification(List<dynamic> times) async {
DateTime.fromMillisecondsSinceEpoch(isyakTimeEpoch), tz.local));
}

print('Notification scheduled #$i');
print('Notification scheduled #${i + 1}');
print('Subuh @ $subuhTimeEpoch');
print('Syuruk @ $syurukTimeEpoch');
print('Zohor @ $zuhrTimeEpoch');
Expand All @@ -114,6 +126,9 @@ void schedulePrayNotification(List<dynamic> times) async {
);

print('DONE SCHEDULING NOTIFS');
//This timestamp is later used to determine wether notification should be updated or not
GetStorage()
.write(kStoredLastUpdateNotif, DateTime.now().millisecondsSinceEpoch);

killCurrentScheduleNotifications();
}
Expand Down
20 changes: 18 additions & 2 deletions lib/views/GetPrayerTime.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
Expand Down Expand Up @@ -39,6 +40,19 @@ class _GetPrayerTimeState extends State<GetPrayerTime> {
.getMptLocationCode(GetStorage().read(kStoredGlobalIndex));
prayerBloc = Mpti906PrayerBloc(location);
print('$location');
//If less than 3 days, since the last notif is scheduled, do not rescehdule
if ((DateTime.now().millisecondsSinceEpoch -
GetStorage().read(kStoredLastUpdateNotif)) <
259200000) {
print('Notification should not update');
//TODO: Rremove when release, toast is for debug purposes
Fluttertoast.showToast(msg: 'Notification should not update');
GetStorage().write(kStoredShouldUpdateNotif, false);
} else {
GetStorage().write(kStoredLastUpdateNotif, true);
print('Notification should update');
Fluttertoast.showToast(msg: 'Notification should update');
}
}

@override
Expand Down Expand Up @@ -97,8 +111,10 @@ class _PrayTimeListState extends State<PrayTimeList> {
Widget build(BuildContext context) {
var prayerTimeData = widget.prayerTime.data;
handler = PrayDataHandler(prayerTimeData.times);
schedulePrayNotification(
handler.getPrayDataCurrentDateOnwards()); //schedule notification
if (!kIsWeb && GetStorage().read(kStoredShouldUpdateNotif)) {
schedulePrayNotification(
handler.getPrayDataCurrentDateOnwards()); //schedule notification
}

return Container(child: Consumer<SettingProvider>(
builder: (context, setting, child) {
Expand Down
2 changes: 1 addition & 1 deletion lib/views/Settings part/AboutPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class AboutAppPage extends StatelessWidget {
),
),
Text(
'\n© Copyright 2020 Fareez Iqmal\n',
'\n© Copyright 2020-2021 Fareez Iqmal\n',
textAlign: TextAlign.center,
),
Container(
Expand Down
187 changes: 105 additions & 82 deletions lib/views/Settings part/NotificationSettingPage.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// at the moment, this feature is not readily implemented
import 'package:app_settings/app_settings.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:waktusolatmalaysia/CONSTANTS.dart';
import 'package:waktusolatmalaysia/utils/cupertinoSwitchListTile.dart';
import 'package:waktusolatmalaysia/utils/prayerName.dart';

Expand All @@ -21,96 +22,118 @@ class _NotificationPageSettingState extends State<NotificationPageSetting> {
appBar: AppBar(
title: Text('Notification Settings'),
centerTitle: true,
actions: [
FlatButton(
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
textColor: Colors.white,
onPressed: !isAnythingChanged
? null
: () {
print('Save button clicked');
print(prayerNotification);
Navigator.pop(context);
},
child: Text(
'SAVE',
),
)
],
// actions: [
// FlatButton(
// shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
// textColor: Colors.white,
// onPressed: !isAnythingChanged
// ? null
// : () {
// print('Save button clicked');
// print(prayerNotification);
// Navigator.pop(context);
// },
// child: Text(
// 'SAVE',
// ),
// )
// ],
),
body: ListView(
padding: EdgeInsets.all(16),
children: [
//Turned of for a while
// Text('Basic'),
// Card(
// child: Column(children: [
// CupertinoSwitchListTile(
// title: Text(PrayerName.prayerName[0]),
// value: prayerNotification[0],
// onChanged: (bool value) {
// setState(() {
// isAnythingChanged = true;
// prayerNotification[0] = value;
// });
// }),
// CupertinoSwitchListTile(
// title: Text(PrayerName.prayerName[1]),
// value: prayerNotification[1],
// onChanged: (bool value) {
// setState(() {
// isAnythingChanged = true;
// prayerNotification[1] = value;
// });
// }),
// CupertinoSwitchListTile(
// title: Text(PrayerName.prayerName[2]),
// value: prayerNotification[2],
// onChanged: (bool value) {
// setState(() {
// isAnythingChanged = true;
// prayerNotification[2] = value;
// });
// }),
// CupertinoSwitchListTile(
// title: Text(PrayerName.prayerName[3]),
// value: prayerNotification[3],
// onChanged: (bool value) {
// setState(() {
// isAnythingChanged = true;
// prayerNotification[3] = value;
// });
// }),
// CupertinoSwitchListTile(
// title: Text(PrayerName.prayerName[4]),
// value: prayerNotification[4],
// onChanged: (bool value) {
// setState(() {
// isAnythingChanged = true;
// prayerNotification[4] = value;
// });
// }),
// CupertinoSwitchListTile(
// title: Text(PrayerName.prayerName[5]),
// value: prayerNotification[5],
// onChanged: (bool value) {
// setState(() {
// isAnythingChanged = true;
// prayerNotification[5] = value;
// });
// }),
// ]),
// ),
Text('Basic'),
Card(
child: Column(children: [
CupertinoSwitchListTile(
title: Text(PrayerName.prayerName[0]),
value: prayerNotification[0],
onChanged: (bool value) {
setState(() {
isAnythingChanged = true;
prayerNotification[0] = value;
});
}),
CupertinoSwitchListTile(
title: Text(PrayerName.prayerName[1]),
value: prayerNotification[1],
onChanged: (bool value) {
setState(() {
isAnythingChanged = true;
prayerNotification[1] = value;
});
}),
CupertinoSwitchListTile(
title: Text(PrayerName.prayerName[2]),
value: prayerNotification[2],
onChanged: (bool value) {
setState(() {
isAnythingChanged = true;
prayerNotification[2] = value;
});
}),
CupertinoSwitchListTile(
title: Text(PrayerName.prayerName[3]),
value: prayerNotification[3],
onChanged: (bool value) {
setState(() {
isAnythingChanged = true;
prayerNotification[3] = value;
});
}),
CupertinoSwitchListTile(
title: Text(PrayerName.prayerName[4]),
value: prayerNotification[4],
onChanged: (bool value) {
setState(() {
isAnythingChanged = true;
prayerNotification[4] = value;
});
}),
CupertinoSwitchListTile(
title: Text(PrayerName.prayerName[5]),
value: prayerNotification[5],
onChanged: (bool value) {
setState(() {
isAnythingChanged = true;
prayerNotification[5] = value;
});
}),
]),
child: ListTile(
title: Text('App notification System Setting'),
subtitle:
Text('Change sound, vibration of prayer notification etc.'),
trailing: Icon(Icons.launch_rounded),
onTap: () async {
await AppSettings.openNotificationSettings();
},
),
),
SizedBox(
height: 10,
),
Text('Advanced'),
Card(
child: ListTile(
title: Text('App notification System Setting'),
subtitle:
Text('Change sound, vibration of prayer notification etc.'),
trailing: Icon(Icons.launch_rounded),
onTap: () async {
await AppSettings.openNotificationSettings();
},
))
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: CupertinoSwitchListTile(
title: Text('Limit notification scheduling'),
subtitle: Text(
'Only you are experiencing extreme slowdown in app. Notification will schedule weekly basis. Default is OFF (monthly).'),
value: GetStorage().read(kStoredNotificationLimit),
onChanged: (value) {
// print(value);
setState(() {
GetStorage().write(kStoredNotificationLimit, value);
});
}),
),
)
],
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/views/ZoneChooser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class _LocationChooserState extends State<LocationChooser> {
var shortCode = locationDatabase.getJakimCode(globalIndex);

void _updateUI() {
GetStorage().write(kStoredShouldUpdateNotif,
true); //if zone changes, update the notification
//this setState will be called when user select a new location, this will update the Text short code
setState(() {
shortCode = locationDatabase.getJakimCode(globalIndex);
Expand Down

0 comments on commit df47ffa

Please sign in to comment.