-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsPage.xaml.cs
75 lines (60 loc) · 2.75 KB
/
SettingsPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace IntermittentFasting;
public partial class SettingsPage : ContentPage
{
private Settings settings = Settings.Default;
public SettingsPage()
{
InitializeComponent();
ToggleNotificationSwitch.IsToggled = Settings.Default.GetNotificationToggleState();
settings.intermittentFastingPeriod = settings.GetCustomFastingPeriod();
settings.eatingWindowPeriod = settings.GetCustomEatingWindowPeriod();
FastHoursEntry.Text = (settings.intermittentFastingPeriod / settings.OneHourInSeconds).ToString();
EatHoursEntry.Text = (settings.eatingWindowPeriod / settings.OneHourInSeconds).ToString();
}
private void OnNotificationsToggled(object sender, EventArgs e)
{
settings.IsNotificationToggleOn = ToggleNotificationSwitch.IsToggled;
settings.SaveNotificationToggleState();
if (!settings.IsNotificationToggleOn)
{
settings.CancelNotifications();
}
}
private void OnCustomizeFastBtnClicked(object sender, EventArgs e)
{
Int32.TryParse(FastHoursEntry.Text, out int fastHours);
Int32.TryParse(EatHoursEntry.Text, out int eatHours);
if (fastHours <= 0)
{
settings.DisplayAlertDialog("", "Invalid Fasting hours input", "Ok");
return;
}
if (eatHours <= 0)
{
settings.DisplayAlertDialog("", "Invalid Eating period input", "Ok");
return;
}
if ((fastHours + eatHours) != 24)
{
settings.DisplayAlertDialog("", "Invalid hours in a day inserted", "Ok");
return;
}
settings.intermittentFastingPeriod = fastHours * settings.OneHourInSeconds; //To seconds
settings.eatingWindowPeriod = eatHours * settings.OneHourInSeconds; //To seconds
settings.SaveCustomFastingPeriod(settings.intermittentFastingPeriod);
settings.SaveCustomEatingWindowPeriod(settings.eatingWindowPeriod);
settings.DisplayAlertDialog("", "Set custom fast of " + fastHours + " fasting hours with an eating window of " + eatHours + " hours. Aka a " + fastHours + ":" + eatHours + " fast", "Ok");
}
private void OnResetAllSettingsClicked(object sender, EventArgs e)
{
FastHoursEntry.Text = settings.DefaultIntermittentFastingPeriodInHours.ToString();
EatHoursEntry.Text = settings.DefaultEatingWindowPeriodInHours.ToString();
if(!ToggleNotificationSwitch.IsToggled) ToggleNotificationSwitch.IsToggled = true;
settings.ResetAllSettings();
settings.DisplayAlertDialog("", "Reset all settings", "Ok");
}
private void OnToMainPageButtonClicked(object sender, EventArgs e)
{
Application.Current.MainPage.Navigation.PushModalAsync(new MainPage(), true);
}
}