Skip to content

Commit

Permalink
Bug: Instance of alarm screen appearing fixed on location activity (#240
Browse files Browse the repository at this point in the history
)

* moving the alarm ring ignore logic to splash screen controller

* removing an instance of alarm-ring-ignore path

* removing the alarm-ring-ignore directory

* removing the alarm-ring-ignore instance from app routes and pages
  • Loading branch information
superiorsd10 authored Dec 17, 2023
1 parent 3014a85 commit a646857
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 243 deletions.

This file was deleted.

This file was deleted.

102 changes: 0 additions & 102 deletions lib/app/modules/alarmRingIgnore/views/alarm_ring_ignore_view.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SplashScreenController extends GetxController {
bool shouldAlarmRing = true;
bool shouldNavigate = true;

final Rx<AlarmModel> currentlyRingingAlarm = Utils.genFakeAlarmModel().obs;

getCurrentlyRingingAlarm() async {
UserModel? _userModel = await SecureStorageProvider().retrieveUserModel();
AlarmModel _alarmRecord = Utils.genFakeAlarmModel();
Expand All @@ -32,6 +34,20 @@ class SplashScreenController extends GetxController {
return latestAlarm;
}

getNextAlarm() async {
UserModel? _userModel = await SecureStorageProvider().retrieveUserModel();
AlarmModel _alarmRecord = Utils.genFakeAlarmModel();
AlarmModel isarLatestAlarm =
await IsarDb.getLatestAlarm(_alarmRecord, true);
AlarmModel firestoreLatestAlarm =
await FirestoreDb.getLatestAlarm(_userModel, _alarmRecord, true);
AlarmModel latestAlarm =
Utils.getFirstScheduledAlarm(isarLatestAlarm, firestoreLatestAlarm);
debugPrint('LATEST : ${latestAlarm.alarmTime}');

return latestAlarm;
}

Future<bool> checkWeatherCondition(
LatLng location,
List<int> weatherTypeInt,
Expand Down Expand Up @@ -137,7 +153,70 @@ class SplashScreenController extends GetxController {
if (shouldAlarmRing) {
Get.offNamed('/alarm-ring');
} else {
Get.offNamed('/alarm-ring-ignore');
currentlyRingingAlarm.value = await getCurrentlyRingingAlarm();
// If the alarm is set to NEVER repeat, then it will be chosen as
// the next alarm to ring by default as it would ring the next day
if (currentlyRingingAlarm.value.days
.every((element) => element == false)) {
currentlyRingingAlarm.value.isEnabled = false;

if (currentlyRingingAlarm.value.isSharedAlarmEnabled == false) {
IsarDb.updateAlarm(currentlyRingingAlarm.value);
} else {
FirestoreDb.updateAlarm(
currentlyRingingAlarm.value.ownerId,
currentlyRingingAlarm.value,
);
}
} else if (currentlyRingingAlarm.value.isOneTime == true) {
// If the alarm has to repeat on one day, but ring just once,
// we will keep seting its days to false until it will never ring
int currentDay = DateTime.now().weekday - 1;
currentlyRingingAlarm.value.days[currentDay] = false;

if (currentlyRingingAlarm.value.days
.every((element) => element == false)) {
currentlyRingingAlarm.value.isEnabled = false;
}

if (currentlyRingingAlarm.value.isSharedAlarmEnabled == false) {
IsarDb.updateAlarm(currentlyRingingAlarm.value);
} else {
FirestoreDb.updateAlarm(
currentlyRingingAlarm.value.ownerId,
currentlyRingingAlarm.value,
);
}
}

AlarmModel latestAlarm = await getNextAlarm();

TimeOfDay latestAlarmTimeOfDay =
Utils.stringToTimeOfDay(latestAlarm.alarmTime);
// This condition will never satisfy because this will only occur if fake mode
// is returned as latest alarm
if (latestAlarm.isEnabled == false) {
debugPrint('STOPPED IF CONDITION with latest = '
'${latestAlarmTimeOfDay.toString()} and ');
await alarmChannel.invokeMethod('cancelAllScheduledAlarms');
} else {
int intervaltoAlarm = Utils.getMillisecondsToAlarm(
DateTime.now(),
Utils.timeOfDayToDateTime(latestAlarmTimeOfDay),
);

try {
await alarmChannel.invokeMethod(
'scheduleAlarm', {'milliSeconds': intervaltoAlarm});
print("Scheduled...");
} on PlatformException catch (e) {
print("Failed to schedule alarm: ${e.message}");
}
}

Get.offNamed('/home');

alarmChannel.invokeMethod('minimizeApp');
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions lib/app/routes/app_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import '../modules/alarmChallenge/bindings/alarm_challenge_binding.dart';
import '../modules/alarmChallenge/views/alarm_challenge_view.dart';
import '../modules/alarmRing/bindings/alarm_ring_binding.dart';
import '../modules/alarmRing/views/alarm_ring_view.dart';
import '../modules/alarmRingIgnore/bindings/alarm_ring_ignore_binding.dart';
import '../modules/alarmRingIgnore/views/alarm_ring_ignore_view.dart';
import '../modules/home/bindings/home_binding.dart';
import '../modules/home/views/home_view.dart';
import '../modules/settings/bindings/settings_binding.dart';
Expand Down Expand Up @@ -45,11 +43,6 @@ class AppPages {
page: () => AlarmControlView(),
binding: AlarmControlBinding(),
),
GetPage(
name: _Paths.ALARM_RING_IGNORE,
page: () => AlarmControlIgnoreView(),
binding: AlarmControlIgnoreBinding(),
),
GetPage(
name: _Paths.SETTINGS,
page: () => SettingsView(),
Expand All @@ -71,6 +64,5 @@ class AppPages {
page: () => AboutView(),
binding: AboutBinding(),
),

];
}
2 changes: 0 additions & 2 deletions lib/app/routes/app_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ abstract class Routes {
static const HOME = _Paths.HOME;
static const ADD_ALARM = _Paths.ADD_OR_UPDATE_ALARM;
static const ALARM_RING = _Paths.ALARM_RING;
static const ALARM_RING_IGNORE = _Paths.ALARM_RING_IGNORE;
static const SETTINGS = _Paths.SETTINGS;
static const ALARM_CHALLENGE = _Paths.ALARM_CHALLENGE;
static const ABOUT = _Paths.ABOUT;
Expand All @@ -19,7 +18,6 @@ abstract class _Paths {
static const HOME = '/home';
static const ADD_OR_UPDATE_ALARM = '/add-update-alarm';
static const ALARM_RING = '/alarm-ring';
static const ALARM_RING_IGNORE = '/alarm-ring-ignore';
static const SETTINGS = '/settings';
static const ALARM_CHALLENGE = '/alarm-challenge';
static const ABOUT = '/about';
Expand Down

0 comments on commit a646857

Please sign in to comment.