Skip to content

Commit

Permalink
fix duplicate CONSTANTS import
Browse files Browse the repository at this point in the history
  • Loading branch information
iqfareez committed Aug 27, 2021
1 parent ae9c613 commit 979dd3f
Show file tree
Hide file tree
Showing 21 changed files with 281 additions and 79 deletions.
Binary file added assets/bam/Clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/bam/Message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/bam/Pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/bam/Tick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 3 additions & 14 deletions lib/CONSTANTS.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const kJsonCache = "jsonCache";
const kAppLaunchCount = "appLaunchCount";
const kHasOpenSharingDialog = "openedSharedDialog";
const kShowNotifPrompt = "notifPrompt";
const kNotificationType = "notiftype";
const kHaventIntroducedToNotifType =
"introducedNotifType"; // TODO: Temporary implementation

//Network image
const kAppIconUrl =
Expand Down Expand Up @@ -77,19 +80,5 @@ const kPaypalDonateShortLink = 'paypal.me/iqfareez';
const kPaypalDonateFullLink = 'https://www.paypal.com/paypalme/iqfareez';
const kMaybankAccNo = '162348620850';

//azan audio link
//https://www.onlineconverter.com/compress-mp3
//(mishary) kurd-2208, lamy-2205, bayati-2014
// const azansAudioFajr = [
// 'https://firebasestorage.googleapis.com/v0/b/malaysia-waktu-solat.appspot.com/o/Azan%2FFajr%2FKurd2008-FAJR.mp3?alt=media&token=587c9b4d-3427-42cc-956a-1a3ea44296ce',
// 'https://firebasestorage.googleapis.com/v0/b/malaysia-waktu-solat.appspot.com/o/Azan%2FFajr%2FLamy2005-FAJR.mp3?alt=media&token=3868ed15-05d1-458e-80c4-5c31ee3030dd',
// 'https://firebasestorage.googleapis.com/v0/b/malaysia-waktu-solat.appspot.com/o/Azan%2FFajr%2Fbayati2014-FAJR.mp3?alt=media&token=2ca1dcdd-5e4d-4d46-b781-44bcc46b7b2e'
// ];
// const azansAudioNormal = [
// 'https://firebasestorage.googleapis.com/v0/b/malaysia-waktu-solat.appspot.com/o/Azan%2FNormal%2FKurd2008.mp3?alt=media&token=7020643d-dcfd-4caa-9702-4c76d0d10c4b',
// 'https://firebasestorage.googleapis.com/v0/b/malaysia-waktu-solat.appspot.com/o/Azan%2FNormal%2FLamy2005.mp3?alt=media&token=0d718dfe-3c94-4938-b571-b4777714a85d',
// 'https://firebasestorage.googleapis.com/v0/b/malaysia-waktu-solat.appspot.com/o/Azan%2FNormal%2Fbayaty2014.mp3?alt=media&token=cf1fcb38-2a23-4902-95e9-9d2c34432c5c'
// ];

//hero tag
const kAppIconTag = 'appIconTag';
10 changes: 7 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import 'package:in_app_review/in_app_review.dart';
import 'package:provider/provider.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'views/Settings%20part/NotificationSettingPage.dart';
import 'CONSTANTS.dart';
import 'locationUtil/location_provider.dart';
import 'notificationUtil/notifications_helper.dart';
import 'providers/ThemeController.dart';
import 'providers/settingsProvider.dart';
import 'utils/sharing_fab.dart';
import 'views/Settings%20part/ThemeController.dart';
import 'views/Settings%20part/settingsProvider.dart';
import 'views/appBody.dart';
import 'views/bottomAppBar.dart';
import 'views/onboarding_page.dart';
Expand Down Expand Up @@ -64,7 +65,9 @@ class MyApp extends StatelessWidget {
bottomAppBarColor: Colors.teal.shade50,
visualDensity: VisualDensity.adaptivePlatformDensity,
appBarTheme: AppBarTheme(
color: _primaryColour, brightness: Brightness.dark),
color: _primaryColour,
// ssytem overlay style
),
),
darkTheme: ThemeData.dark().copyWith(
primaryColor: _primaryColour,
Expand Down Expand Up @@ -108,6 +111,7 @@ class MyHomePage extends StatelessWidget {
void initGetStorage() {
// init default settings
GetStorage _get = GetStorage();
_get.writeIfNull(kNotificationType, MyNotificationType.noazan.index);
_get.writeIfNull(kShowNotifPrompt, true);
_get.writeIfNull(kAppLaunchCount, 0);
_get.writeIfNull(kIsFirstRun, true);
Expand Down
159 changes: 128 additions & 31 deletions lib/notificationUtil/notification_scheduler.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get_storage/get_storage.dart';
import 'package:timezone/timezone.dart' hide LocationDatabase;
import '../views/Settings%20part/NotificationSettingPage.dart';
import '../utils/debug_toast.dart';
import '../CONSTANTS.dart';
import '../locationUtil/locationDatabase.dart';
Expand All @@ -18,12 +19,48 @@ class MyNotifScheduler {
if (GetStorage().read(kStoredNotificationLimit)) {
times = times.take(7).toList();
}

DebugToast.show('SCHEDULING ${times.length} notifications');

// for debug dialog
GetStorage().write(kNumberOfNotifsScheduled, times.length);

MyNotificationType _notifType =
MyNotificationType.values[GetStorage().read(kNotificationType)];

switch (_notifType) {
case MyNotificationType.noazan:
DebugToast.show('Notification: Default sound');
_defaultScheduler(times, _currentDateTime, currentLocation);
break;
case MyNotificationType.azan:
DebugToast.show('Notification: Azan');
_azanScheduler(times, _currentDateTime, currentLocation);
break;
}

scheduleAlertNotification(
id: 2190,
title: 'Monthly refresh reminder',
body:
'To continue receive prayer notification, open app at least once every month.',
payload: kPayloadMonthly,
// if month (12 + 1) = 13, it will auto-increment to next year
//2021-01-01 00:05:00.000+0800
scheduledTime: TZDateTime.local(
_currentDateTime.year, _currentDateTime.month + 1, 1, 0, 5),
);

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

var _endOperation = DateTime.now();
var _timeTaken = _endOperation.difference(_currentDateTime);
var _message = 'Finish schedule notif. after $_timeTaken';
print(_message);
DebugToast.show(_message);
}

static void _defaultScheduler(List<dynamic> times, DateTime currentDateTime,
String currentLocation) async {
for (var dayTime in times) {
DateTime subuhDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[0] * 1000);
Expand All @@ -38,7 +75,89 @@ class MyNotifScheduler {
DateTime isyakDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[5] * 1000);

if (subuhDateTime.isAfter(_currentDateTime)) {
if (subuhDateTime.isAfter(currentDateTime)) {
//to make sure the time is in future
await scheduleSinglePrayerNotification(
name: 'Fajr',
id: int.parse(
subuhDateTime.millisecondsSinceEpoch.toString().substring(5)),
title: 'It\'s Subuh',
scheduledTime: TZDateTime.from(subuhDateTime, local),
body: 'in ' + currentLocation,
);
}
if (syurukDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Syuruk',
id: int.parse(
syurukDateTime.millisecondsSinceEpoch.toString().substring(5)),
title: 'It\'s Syuruk',
body: 'in ' + currentLocation,
summary: 'Ends of Subuh',
scheduledTime: TZDateTime.from(syurukDateTime, local),
);
}
if (zuhrDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Zuhr',
id: int.parse(
zuhrDateTime.millisecondsSinceEpoch.toString().substring(5)),
title: 'It\'s Zohor',
body: 'in ' + currentLocation,
summary: zuhrDateTime.day == DateTime.friday ? 'Salam Jumaat' : null,
scheduledTime: TZDateTime.from(zuhrDateTime, local),
);
}
if (asarDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Asr',
id: int.parse(
asarDateTime.millisecondsSinceEpoch.toString().substring(5)),
title: 'It\'s Asar',
body: 'in ' + currentLocation,
scheduledTime: TZDateTime.from(asarDateTime, local),
);
}
if (maghribDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Maghrib',
id: int.parse(
maghribDateTime.millisecondsSinceEpoch.toString().substring(5)),
title: 'It\'s Maghrib',
body: 'in ' + currentLocation,
scheduledTime: TZDateTime.from(maghribDateTime, local),
);
}
if (isyakDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Isya\'',
id: int.parse(
isyakDateTime.millisecondsSinceEpoch.toString().substring(5)),
title: 'It\'s Isyak',
body: 'in ' + currentLocation,
scheduledTime: TZDateTime.from(isyakDateTime, local),
);
}
}
}

static void _azanScheduler(List<dynamic> times, DateTime currentDateTime,
String currentLocation) async {
for (var dayTime in times) {
DateTime subuhDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[0] * 1000);
DateTime syurukDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[1] * 1000);
DateTime zuhrDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[2] * 1000);
DateTime asarDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[3] * 1000);
DateTime maghribDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[4] * 1000);
DateTime isyakDateTime =
DateTime.fromMillisecondsSinceEpoch(dayTime[5] * 1000);

if (subuhDateTime.isAfter(currentDateTime)) {
//to make sure the time is in future
await scheduleSinglePrayerNotification(
name: 'Fajr',
Expand All @@ -49,7 +168,7 @@ class MyNotifScheduler {
body: 'in ' + currentLocation,
customSound: 'azan_hejaz2013_fajr');
}
if (syurukDateTime.isAfter(_currentDateTime)) {
if (syurukDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Syuruk',
id: int.parse(
Expand All @@ -60,7 +179,7 @@ class MyNotifScheduler {
scheduledTime: TZDateTime.from(syurukDateTime, local),
);
}
if (zuhrDateTime.isAfter(_currentDateTime)) {
if (zuhrDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Zuhr',
id: int.parse(
Expand All @@ -72,7 +191,7 @@ class MyNotifScheduler {
scheduledTime: TZDateTime.from(zuhrDateTime, local),
customSound: 'azan_kurdhi2010');
}
if (asarDateTime.isAfter(_currentDateTime)) {
if (asarDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Asr',
id: int.parse(
Expand All @@ -82,7 +201,7 @@ class MyNotifScheduler {
scheduledTime: TZDateTime.from(asarDateTime, local),
customSound: 'azan_kurdhi2010');
}
if (maghribDateTime.isAfter(_currentDateTime)) {
if (maghribDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Maghrib',
id: int.parse(
Expand All @@ -92,7 +211,7 @@ class MyNotifScheduler {
scheduledTime: TZDateTime.from(maghribDateTime, local),
customSound: 'azan_kurdhi2010');
}
if (isyakDateTime.isAfter(_currentDateTime)) {
if (isyakDateTime.isAfter(currentDateTime)) {
await scheduleSinglePrayerNotification(
name: 'Isya\'',
id: int.parse(
Expand All @@ -103,27 +222,5 @@ class MyNotifScheduler {
customSound: 'azan_kurdhi2010');
}
}

scheduleAlertNotification(
id: 2190,
title: 'Monthly refresh reminder',
body:
'To continue receive prayer notification, open app at least once every month.',
payload: kPayloadMonthly,
// if month (12 + 1) = 13, it will auto-increment to next year
//2021-01-01 00:05:00.000+0800
scheduledTime: TZDateTime.local(
_currentDateTime.year, _currentDateTime.month + 1, 1, 0, 5),
);

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

var _endOperation = DateTime.now();
var _timeTaken = _endOperation.difference(_currentDateTime);
var _message = 'Finish schedule notif. after $_timeTaken';
print(_message);
DebugToast.show(_message);
}
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/utils/sharing_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get_storage/get_storage.dart';
import 'package:provider/provider.dart';
import 'package:share/share.dart';
import '../providers/settingsProvider.dart';
import '../CONSTANTS.dart';
import '../views/Settings%20part/settingsProvider.dart';
import 'copyAndShare.dart';
import 'launchUrl.dart';

Expand Down
7 changes: 5 additions & 2 deletions lib/views/GetPrayerTime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get_storage/get_storage.dart';
import 'package:provider/provider.dart';
import 'Settings%20part/settingsProvider.dart';
import '../providers/settingsProvider.dart';
import '../CONSTANTS.dart';
import '../locationUtil/locationDatabase.dart';
import '../locationUtil/location_provider.dart';
Expand Down Expand Up @@ -175,6 +175,7 @@ class Error extends StatelessWidget {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const SizedBox(height: 15),
Text(
errorMessage!,
textAlign: TextAlign.center,
Expand All @@ -186,7 +187,8 @@ class Error extends StatelessWidget {
ElevatedButton(
child: const Text('Retry', style: TextStyle(color: Colors.black)),
onPressed: onRetryPressed as void Function()?,
)
),
// add some spacer (to distance the ads)
],
);
}
Expand All @@ -198,6 +200,7 @@ class Loading extends StatelessWidget {
Widget build(BuildContext context) {
return Column(
children: const [
SizedBox(height: 15),
Text(
'Fetching prayer time. Please wait.',
textAlign: TextAlign.center,
Expand Down
4 changes: 2 additions & 2 deletions lib/views/Settings part/AboutPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
import '../debug_widgets.dart';
import '../../providers/settingsProvider.dart';
import '../../CONSTANTS.dart';
import '../../utils/launchUrl.dart';
import '../Settings%20part/settingsProvider.dart';
import '../debug_widgets.dart';
import '../contributionPage.dart';
import '../faq.dart';

Expand Down
Loading

0 comments on commit 979dd3f

Please sign in to comment.