Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
51 changes: 26 additions & 25 deletions lib/app/data/providers/isar_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class IsarDb {
label TEXT,
isOneTime INTEGER NOT NULL DEFAULT 0,
snoozeDuration INTEGER,
Comment thread
NihalDR marked this conversation as resolved.
maxSnoozeCount INTEGER DEFAULT 3,
gradient INTEGER,
ringtoneName TEXT,
note TEXT,
Expand Down Expand Up @@ -252,7 +251,6 @@ class IsarDb {
final isarProvider = IsarDb();
final sql = await IsarDb().getAlarmSQLiteDatabase();
final db = await isarProvider.db;

await db.writeTxn(() async {
await db.alarmModels.put(alarmRecord);
});
Expand All @@ -273,6 +271,31 @@ class IsarDb {
return profileModel;
}

static void deleteProfile(String profileName) async {
final isarProvider = IsarDb();
final db = await isarProvider.db;

final profile = await db.profileModels.filter().
profileNameEqualTo(profileName).findFirst();

if (profile == null) return;

final deletedAlarms = await db.alarmModels.filter().
profileEqualTo(profileName).findAll();

try {
await db.writeTxn(() async {
for (final alarm in deletedAlarms) {
await db.alarmModels.delete(alarm.isarId);
}
await db.profileModels.delete(profile.isarId);
});
} catch (e) {
debugPrint('Error deleting profile: $e');
rethrow;
}
}

static Stream<List<ProfileModel>> getProfiles() async* {
try {
final isarProvider = IsarDb();
Expand Down Expand Up @@ -426,7 +449,6 @@ class IsarDb {

return aTimeUntilNextAlarm < bTimeUntilNextAlarm ? a : b;
});

return closestAlarm;
}
}
Expand All @@ -447,27 +469,6 @@ class IsarDb {
);
}


static Future<void> fixMaxSnoozeCountInAlarms() async {
final isarProvider = IsarDb();
final db = await isarProvider.db;
final sql = await IsarDb().getAlarmSQLiteDatabase();


final alarms = await db.alarmModels.where().findAll();


for (final alarm in alarms) {

await sql!.update(
'alarms',
{'maxSnoozeCount': alarm.maxSnoozeCount},
where: 'alarmID = ?',
whereArgs: [alarm.alarmID],
);
}
}

static Future<AlarmModel?> getAlarm(int id) async {
Comment thread
NihalDR marked this conversation as resolved.
final isarProvider = IsarDb();
final db = await isarProvider.db;
Expand Down Expand Up @@ -797,4 +798,4 @@ class IsarDb {
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,29 @@ class RingtoneSelectionPage extends GetView<AddOrUpdateAlarmController> {
);
}

// Widget _buildSystemRingtonesTab() {
// return SystemRingtonePicker(
// isFullScreen: true,
// );
// }
Comment thread
NihalDR marked this conversation as resolved.
Widget _buildSystemRingtonesTab() {
if (GetPlatform.isIOS) {
return Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text(
'System ringtones are currently only supported on Android.\n\nPlease upload a custom ringtone to use this feature.',
textAlign: TextAlign.center,
style: TextStyle(
color: themeController.primaryTextColor.value.withOpacity(0.7),
fontSize: 16,
height: 1.5,
),
),
),
);
}

return SystemRingtonePicker(
isFullScreen: true,
);
Expand Down
206 changes: 190 additions & 16 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,132 @@ class HomeController extends GetxController {
String profileName = await storage.readProfile();
selectedProfile.value = profileName;
ProfileModel? p = await IsarDb.getProfile(profileName);
if (p != null)
{
profileModel.value = p!;
}

profileModel.value = p!;
Comment thread
NihalDR marked this conversation as resolved.
}

void writeProfileName(String name) async {
await storage.writeProfile(name);
selectedProfile.value = name;
ProfileModel? p = await IsarDb.getProfile(name);
if (p != null)
{
profileModel.value = p!;
profileModel.value = p!;
Comment thread
NihalDR marked this conversation as resolved.
}

void deleteProfile(ProfileModel profile, BuildContext context) async {
if (profile.profileName == 'Default') {
Get.snackbar(
'Error',
'Cannot delete the default profile',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
return;
}

if (profile.isSharedAlarmEnabled) {
Get.snackbar(
'Error',
'This profile contains shared alarms.',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
return;
}

Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(
vertical: 20,
),
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Delete Profile',
titleStyle: Theme.of(context).textTheme.displaySmall,
content: Column(
children: [
Text(
'This action will permanently delete '
'this profile and all its alarms.',
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(
top: 20,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () => Get.back(),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
kprimaryTextColor.withOpacity(0.5),
),
),
child: Text(
'Cancel',
style: Theme.of(context).textTheme.displaySmall!,
),
),
TextButton(
onPressed: () async {
ProfileModel deletedProfile = profile;
try{
IsarDb.deleteProfile(profile.profileName);
} catch (e) {
Get.snackbar(
'Error',
'Failed to delete profile',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
return;
}

if (profile.profileName == selectedProfile.value) {
writeProfileName('Default');
}
Get.back();
Get.snackbar(
'Success',
'Profile deleted successfully',
snackPosition: SnackPosition.BOTTOM,
colorText: Colors.white,
margin: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 15,
),
mainButton: TextButton(
onPressed: () async {
await IsarDb.addProfile(deletedProfile);
writeProfileName(deletedProfile.profileName);
// might want to add the alarms back to the profile
// however, patch alarm addition is not implemented yet
},
child: Text(
'Undo',
style: TextStyle(color: Colors.white),
),
),
);
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(kprimaryColor),
),
child: Text(
'Delete',
style: Theme.of(context).textTheme.displaySmall!.copyWith(
color: kprimaryBackgroundColor,
),
),
),
],
),
),
],
),
);
}

@override
Expand All @@ -260,20 +371,13 @@ class HomeController extends GetxController {
}
readProfileName();

userModel.value = await SecureStorageProvider().retrieveUserModel();
if (userModel.value == null){
FirebaseAuth.instance.authStateChanges().listen((user) {
if (user == null) {
isUserSignedIn.value = false;
} else {
isUserSignedIn.value = true;
Comment on lines 374 to 378
}
});
}
else {
isUserSignedIn.value = true;
}


isSortedAlarmListEnabled.value = await SecureStorageProvider()
.readSortedAlarmListValue(key: 'sorted_alarm_list');
Expand All @@ -288,6 +392,14 @@ class HomeController extends GetxController {
scalingFactor.value = (minFactor + (maxFactor - minFactor) * newFactor);
});

if (Get.arguments != null) {
bool showMotivationalQuote = Get.arguments.showMotivationalQuote;

if (showMotivationalQuote) {
Quote quote = Utils.getRandomQuote();
showQuotePopup(quote);
}
}
}

refreshUpcomingAlarms() async {
Expand Down Expand Up @@ -600,6 +712,68 @@ class HomeController extends GetxController {
}
}

void showQuotePopup(Quote quote) {
Get.defaultDialog(
title: 'Motivational Quote',
titlePadding: const EdgeInsets.only(
top: 20,
bottom: 10,
),
backgroundColor: themeController.secondaryBackgroundColor.value,
titleStyle: TextStyle(
color: themeController.primaryTextColor.value,
),
contentPadding: const EdgeInsets.all(20),
content: Column(
children: [
Obx(
() => Text(
quote.getQuote(),
style: TextStyle(
color: themeController.primaryTextColor.value,
),
),
),
const SizedBox(
height: 15,
),
Align(
alignment: Alignment.centerRight,
child: Obx(
() => Text(
quote.getAuthor(),
style: TextStyle(
color: themeController.primaryTextColor.value,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.italic,
),
),
),
),
const SizedBox(
height: 30,
),
TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
kprimaryColor,
),
),
onPressed: () {
Get.back();
},
child: Text(
'Dismiss',
style: TextStyle(
color: themeController.secondaryTextColor.value,
),
),
),
],
),
);
}

Future<void> swipeToDeleteAlarm(UserModel? user, AlarmModel alarm) async {
AlarmModel? alarmToDelete;

Expand Down Expand Up @@ -770,4 +944,4 @@ class HomeController extends GetxController {
isCall: profileModel.value.isCall,
ringOn: false);
}
}
}
Loading
Loading