Skip to content

Title: Implement Comprehensive Alarm Sorting System #757

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 5 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
15 changes: 12 additions & 3 deletions lib/app/data/models/alarm_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class AlarmModel {
@ignore
Map? offsetDetails;

@Index()
late DateTime lastModifiedDate;

AlarmModel(
{required this.alarmTime,
required this.alarmID,
Expand Down Expand Up @@ -109,7 +112,10 @@ class AlarmModel {
required this.isGuardian,
required this.guardianTimer,
required this.guardian,
required this.isCall});
required this.isCall,
DateTime? lastModifiedDate}) {
this.lastModifiedDate = lastModifiedDate ?? DateTime.now();
}

AlarmModel.fromDocumentSnapshot({
required firestore.DocumentSnapshot documentSnapshot,
Expand Down Expand Up @@ -179,6 +185,9 @@ class AlarmModel {
guardianTimer = documentSnapshot['guardianTimer'];
guardian = documentSnapshot['guardian'];
isCall = documentSnapshot['isCall'];
lastModifiedDate = documentSnapshot['lastModifiedDate'] != null
? (documentSnapshot['lastModifiedDate'] as firestore.Timestamp).toDate()
: DateTime.now();
}

AlarmModel fromMapSQFlite(Map<String, dynamic> map) {
Expand Down Expand Up @@ -337,7 +346,6 @@ class AlarmModel {
guardianTimer = alarmData['guardianTimer'];
guardian = alarmData['guardian'];
isCall = alarmData['isCall'];
ringOn = alarmData['ringOn'];
}

AlarmModel.fromJson(String alarmData, UserModel? user) {
Expand Down Expand Up @@ -395,7 +403,8 @@ class AlarmModel {
'guardianTimer': alarmRecord.guardianTimer,
'guardian': alarmRecord.guardian,
'isCall': alarmRecord.isCall,
'ringOn': alarmRecord.ringOn
'ringOn': alarmRecord.ringOn,
'lastModifiedDate': firestore.Timestamp.fromDate(alarmRecord.lastModifiedDate),
};

if (alarmRecord.isSharedAlarmEnabled) {
Expand Down
39 changes: 39 additions & 0 deletions lib/app/data/models/sort_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
enum AlarmSortMode {
defaultSort,
timeOfDay,
label,
creationDate,
lastModified,
customOrder;

String get displayName {
switch (this) {
case AlarmSortMode.defaultSort:
return 'Smart Sort (Enabled + Next Occurrence)';
case AlarmSortMode.timeOfDay:
return 'Time of Day';
case AlarmSortMode.label:
return 'Alarm Label';
case AlarmSortMode.creationDate:
return 'Creation Date';
case AlarmSortMode.lastModified:
return 'Last Modified';
case AlarmSortMode.customOrder:
return 'Custom Order';
}
}
}

enum SortDirection {
ascending,
descending;

String get displayName {
switch (this) {
case SortDirection.ascending:
return 'Ascending';
case SortDirection.descending:
return 'Descending';
}
}
}
16 changes: 16 additions & 0 deletions lib/app/data/providers/secure_storage_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,20 @@ class SecureStorageProvider {
value: timerId.toString(),
);
}

Future<String?> readSortMode(String key) async {
return await _secureStorage.read(key: key);
}

Future<String?> readSortDirection(String key) async {
return await _secureStorage.read(key: key);
}

Future<void> writeSortMode(String key, String value) async {
await _secureStorage.write(key: key, value: value);
}

Future<void> writeSortDirection(String key, String value) async {
await _secureStorage.write(key: key, value: value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ class AddOrUpdateAlarmController extends GetxController {
guardian: guardian.value,
isCall: isCall.value,
ringOn: isFutureDate.value,
lastModifiedDate: DateTime.now(),
);
}

Expand Down Expand Up @@ -1351,7 +1352,6 @@ class AddOrUpdateAlarmController extends GetxController {
storage.writeProfile(profileModel.profileName);
homeController.writeProfileName(profileModel.profileName);
}
}

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

return int.parse(dialCodeA).compareTo(int.parse(dialCodeB));
}
}
139 changes: 68 additions & 71 deletions lib/app/modules/addOrUpdateAlarm/views/guardian_angel.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl_phone_number_input/intl_phone_number_input.dart';
import 'package:intl_phone_number_input/src/models/country_model.dart';
import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart';
import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart';
import 'package:ultimate_alarm_clock/app/utils/constants.dart';
Expand All @@ -17,95 +18,91 @@ class GuardianAngel extends StatelessWidget {
final AddOrUpdateAlarmController controller;
final ThemeController themeController;

static int orderedCountryCode(Country countryA, Country countryB) {
String dialCodeA = countryA.dialCode?.replaceAll('+', '') ?? '0';
String dialCodeB = countryB.dialCode?.replaceAll('+', '') ?? '0';
return int.parse(dialCodeA).compareTo(int.parse(dialCodeB));
}

@override
Widget build(BuildContext context) {
// Check if using Firestore and the current user is the owner
// and if not using, just show the tile

return Column(
children: [
ListTile(
onTap: () async {
var phonePerm =
await Permission.phone.request().isGranted;
var smsPerm = await Permission.sms.request().isGranted;
var phonePerm = await Permission.phone.request().isGranted;
var smsPerm = await Permission.sms.request().isGranted;

if (phonePerm && smsPerm) {
Get.dialog(
Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
),
backgroundColor: themeController
.secondaryBackgroundColor.value,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: InternationalPhoneNumberInput(
textFieldController: controller
.contactTextEditingController,
onInputChanged: (value) {},
onInputValidated: (value) {},
spaceBetweenSelectorAndTextField: 0,
selectorConfig: const SelectorConfig(
showFlags: true,
setSelectorButtonAsPrefixIcon: true,
leadingPadding: 0,
trailingSpace: false,
countryComparator: orderedCountryCode,
),
),
if (phonePerm && smsPerm) {
Get.dialog(
Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
),
Padding(
padding: EdgeInsets.symmetric(
vertical: controller
.homeController.scalingFactor *
8,
horizontal: controller
.homeController.scalingFactor *
4,
),
child: Row(
backgroundColor: themeController.secondaryBackgroundColor.value,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Option(0, Icons.sms, 'Text'),
Option(1, Icons.call, 'Call'),
const Spacer(),
Submit(),
Padding(
padding: const EdgeInsets.all(8.0),
child: InternationalPhoneNumberInput(
textFieldController: controller.contactTextEditingController,
onInputChanged: (value) {},
onInputValidated: (value) {},
spaceBetweenSelectorAndTextField: 0,
selectorConfig: const SelectorConfig(
showFlags: true,
setSelectorButtonAsPrefixIcon: true,
leadingPadding: 0,
trailingSpace: false,
countryComparator: orderedCountryCode,
),
),
),
Padding(
padding: EdgeInsets.symmetric(
vertical: controller.homeController.scalingFactor * 8,
horizontal: controller.homeController.scalingFactor * 4,
),
child: Row(
children: [
Option(0, Icons.sms, 'Text'),
Option(1, Icons.call, 'Call'),
const Spacer(),
Submit(),
],
),
),
],
),
),
],
),
),
),
);
}
},
title: Row(
children: [
FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Obx(
() => Text(
'Guardian Angel'.tr,
style: TextStyle(
color: themeController.primaryTextColor.value,
),
);
}
},
title: Row(
children: [
FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Obx(
() => Text(
'Guardian Angel'.tr,
style: TextStyle(
color: themeController.primaryTextColor.value,
),
),
),
),
),
Obx(
() => IconButton(
icon: Icon(
Icons.info_sharp,
size: 21,
color: themeController.primaryTextColor.value.withOpacity(0.3),
),
Icons.info_sharp,
size: 21,
color: themeController.primaryTextColor.value.withOpacity(0.3),
),
onPressed: () {
Utils.showModal(
context: context,
Expand Down
Loading