Skip to content

Fix "Rings On" feature - correct time display for future date alarms Implement Mutually Exclusive Scheduling Options for Alarms #830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ class AddOrUpdateAlarmController extends GetxController {
RxBool isWeekdaysSelected = false.obs;
RxBool isCustomSelected = false.obs;
RxBool isPlaying = false.obs; // Observable boolean to track playing state

final Map<String, dynamic> previousSettings = <String, dynamic>{}.obs;


void storePreviousSetting(String key, dynamic value) {
previousSettings[key] = value;
}


dynamic getPreviousSetting(String key) {
return previousSettings[key];
}

// to check whether alarm data is updated or not
Map<String, dynamic> initialValues = {};
Expand Down Expand Up @@ -155,6 +167,18 @@ class AddOrUpdateAlarmController extends GetxController {
if (value == true) {
isCustomSelected.value = false;
isWeekdaysSelected.value = false;

if (isFutureDate.value) {
isFutureDate.value = false;
Get.snackbar(
'Specific Date Disabled',
'Ring On specific date has been disabled since repeat pattern is selected.',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.orange,
colorText: Colors.white,
duration: const Duration(seconds: 3),
);
}
}
}

Expand All @@ -167,6 +191,18 @@ class AddOrUpdateAlarmController extends GetxController {
if (value == true) {
isCustomSelected.value = false;
isDailySelected.value = false;

if (isFutureDate.value) {
isFutureDate.value = false;
Get.snackbar(
'Specific Date Disabled',
'Ring On specific date has been disabled since repeat pattern is selected.',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.orange,
colorText: Colors.white,
duration: const Duration(seconds: 3),
);
}
}
}

Expand All @@ -175,6 +211,18 @@ class AddOrUpdateAlarmController extends GetxController {
if (value == true) {
isWeekdaysSelected.value = false;
isDailySelected.value = false;

if (isFutureDate.value) {
isFutureDate.value = false;
Get.snackbar(
'Specific Date Disabled',
'Ring On specific date has been disabled since repeat pattern is selected.',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.orange,
colorText: Colors.white,
duration: const Duration(seconds: 3),
);
}
}
}

Expand Down Expand Up @@ -740,6 +788,8 @@ class AddOrUpdateAlarmController extends GetxController {
timeToAlarm.value = Utils.timeUntilAlarm(
TimeOfDay.fromDateTime(selectedTime.value),
repeatDays,
ringOn: isFutureDate.value,
alarmDate: selectedDate.value.toString().substring(0, 11),
);

repeatDays.value = alarmRecord.value.days;
Expand Down Expand Up @@ -850,6 +900,8 @@ class AddOrUpdateAlarmController extends GetxController {
timeToAlarm.value = Utils.timeUntilAlarm(
TimeOfDay.fromDateTime(selectedTime.value),
repeatDays,
ringOn: isFutureDate.value,
alarmDate: selectedDate.value.toString().substring(0, 11),
);

// store initial values of the variables
Expand Down Expand Up @@ -891,12 +943,26 @@ class AddOrUpdateAlarmController extends GetxController {
}

void addListeners() {
// Updating UI to show time to alarm
selectedTime.listen((time) {
debugPrint('CHANGED CHANGED CHANGED CHANGED');
timeToAlarm.value =
Utils.timeUntilAlarm(TimeOfDay.fromDateTime(time), repeatDays);
_compareAndSetChange('selectedTime', time);
ever(selectedTime, (DateTime time) {
if (time != initialValues['selectedTime']) {
debugPrint('CHANGED CHANGED CHANGED CHANGED');
timeToAlarm.value = Utils.timeUntilAlarm(
TimeOfDay.fromDateTime(time),
repeatDays,
ringOn: isFutureDate.value,
alarmDate: selectedDate.value.toString().substring(0, 11)
);
_compareAndSetChange('selectedTime', time);
}
});

ever(isFutureDate, (bool enabled) {
timeToAlarm.value = Utils.timeUntilAlarm(
TimeOfDay.fromDateTime(selectedTime.value),
repeatDays,
ringOn: enabled,
alarmDate: selectedDate.value.toString().substring(0, 11),
);
});

//Updating UI to show repeated days
Expand Down Expand Up @@ -1261,8 +1327,47 @@ class AddOrUpdateAlarmController extends GetxController {
lastDate: DateTime.now().add(const Duration(days: 355)),
)) ??
DateTime.now();
isFutureDate.value =
selectedDate.value.difference(DateTime.now()).inHours > 0;

bool newFutureDate = selectedDate.value.difference(DateTime.now()).inHours > 0;


if (newFutureDate && !isFutureDate.value) {

List<bool> oldRepeatDays = List<bool>.from(repeatDays);


for (int i = 0; i < repeatDays.length; i++) {
repeatDays[i] = false;
}


isDailySelected.value = false;
isWeekdaysSelected.value = false;
isCustomSelected.value = false;


if (oldRepeatDays.any((enabled) => enabled)) {
Get.snackbar(
'Repeat Pattern Disabled',
'Repeat pattern has been disabled since specific date is selected.',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.orange,
colorText: Colors.white,
duration: const Duration(seconds: 3),
);
}
}


isFutureDate.value = newFutureDate;


timeToAlarm.value = Utils.timeUntilAlarm(
TimeOfDay.fromDateTime(selectedTime.value),
repeatDays,
ringOn: isFutureDate.value,
alarmDate: selectedDate.value.toString().substring(0, 11),
);
}

void showToast({
Expand Down Expand Up @@ -1408,7 +1513,6 @@ class AddOrUpdateAlarmController extends GetxController {
);
}
}
}

int orderedCountryCode(Country countryA, Country countryB) {
// `??` for null safety of 'dialCode'
Expand All @@ -1417,3 +1521,4 @@ class AddOrUpdateAlarmController extends GetxController {

return int.parse(dialCodeA).compareTo(int.parse(dialCodeB));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_cont
import 'package:ultimate_alarm_clock/app/utils/constants.dart';
import 'package:ultimate_alarm_clock/app/utils/utils.dart';
import '../controllers/add_or_update_alarm_controller.dart';
import 'alarm_date_tile.dart';
import 'guardian_angel.dart';
import 'scheduling_options_tile.dart';

class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
AddOrUpdateAlarmView({super.key}) {
Expand Down Expand Up @@ -792,15 +792,7 @@ class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
() => controller.alarmSettingType.value == 0
? Column(
children: [
AlarmDateTile(
controller: controller,
themeController: themeController,
),
Divider(
color: themeController
.primaryDisabledTextColor.value,
),
RepeatTile(
SchedulingOptionsTile(
controller: controller,
themeController: themeController,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/app/modules/addOrUpdateAlarm/views/guardian_angel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GuardianAngel extends StatelessWidget {
setSelectorButtonAsPrefixIcon: true,
leadingPadding: 0,
trailingSpace: false,
countryComparator: orderedCountryCode,
countryComparator: null,
),
),
),
Expand Down
24 changes: 24 additions & 0 deletions lib/app/modules/addOrUpdateAlarm/views/repeat_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ class RepeatTile extends StatelessWidget {
onTap: () {
Utils.hapticFeedback();
controller.repeatDays[dayIndex] = !controller.repeatDays[dayIndex];

if (controller.repeatDays[dayIndex] && controller.isFutureDate.value) {
controller.isFutureDate.value = false;
Get.snackbar(
'Specific Date Disabled',
'Ring On specific date has been disabled since repeat pattern is selected.',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.orange,
colorText: Colors.white,
duration: const Duration(seconds: 3),
);
}
},
child: Padding(
padding: const EdgeInsets.only(left: 10.0),
Expand All @@ -218,6 +230,18 @@ class RepeatTile extends StatelessWidget {
onChanged: (value) {
Utils.hapticFeedback();
controller.repeatDays[dayIndex] = value!;

if (value && controller.isFutureDate.value) {
controller.isFutureDate.value = false;
Get.snackbar(
'Specific Date Disabled',
'Ring On specific date has been disabled since repeat pattern is selected.',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.orange,
colorText: Colors.white,
duration: const Duration(seconds: 3),
);
}
},
),
Text(
Expand Down
Loading