Skip to content

Commit

Permalink
Update alarm schema
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Mar 27, 2024
1 parent b530ebd commit b0f607e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/alarm/data/alarm_settings_schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:clock_app/settings/types/setting_group.dart';
import 'package:clock_app/timer/types/time_duration.dart';
import 'package:flutter/material.dart';

const alarmSchemaVersion = 3;
const alarmSchemaVersion = 4;

SettingGroup alarmSettingsSchema = SettingGroup(
version: alarmSchemaVersion,
Expand Down
2 changes: 1 addition & 1 deletion lib/settings/data/settings_schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:clock_app/settings/screens/about_screen.dart';
import 'package:clock_app/settings/types/setting_group.dart';
import 'package:clock_app/settings/types/setting_link.dart';

const int settingsSchemaVersion = 1;
const int settingsSchemaVersion = 3;

SettingGroup appSettings = SettingGroup(
"Settings",
Expand Down
2 changes: 1 addition & 1 deletion lib/settings/logic/initialize_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Future<void> initializeStorage() async {

// Used to clear the preferences in case of a change in format of the data
// Comment this out after the preferences are cleared
if (kDebugMode) await _clearSettings();
// if (kDebugMode) await _clearSettings();

bool? firstLaunch = GetStorage().read('first_launch');
if (firstLaunch == null) {
Expand Down
27 changes: 14 additions & 13 deletions lib/settings/types/setting_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class SettingGroup extends SettingItem {
@override
void loadValueFromJson(dynamic value) {
if (value == null) return;
if (_version != null && value["version"] != _version) {
// if (_version != null && value["version"] != _version) {
//TODO: Add migration code

//In case of name change:
Expand All @@ -196,21 +196,22 @@ class SettingGroup extends SettingItem {

//Incase of removal
//value.remove("Old Setting");
print("$name: $value");

// if (name == "AlarmSettings") {
if (value["version"] == 1) {
final old1 = value["Snooze"]["Prevent Disabling while Snoozed"];
final old2 = value["Snooze"]["Prevent Deleting while Snoozed"];
if (old1) {
value["Snooze"]["While Snoozed"]["Prevent Disabling"] = old1;
}
if (old2) value["Snooze"]["While Snoozed"]["Prevent Deletion"] = old2;
}
// if (value["version"] == 1) {
// final old1 = value["Snooze"]["Prevent Disabling while Snoozed"];
// final old2 = value["Snooze"]["Prevent Deleting while Snoozed"];
// if (old1) {
// value["Snooze"]["While Snoozed"]["Prevent Disabling"] = old1;
// }
// if (old2) value["Snooze"]["While Snoozed"]["Prevent Deletion"] = old2;
// }
// }
}
for (var setting in _settingItems) {
if (value != null) setting.loadValueFromJson(value[setting.name]);
}
// }
// for (var setting in _settingItems) {
// if (value != null) setting.loadValueFromJson(value[setting.name]);
// }
}

Future<void> save() {
Expand Down

0 comments on commit b0f607e

Please sign in to comment.