mirror of
https://github.com/usatiuk/PomoTime.git
synced 2025-10-29 00:47:48 +01:00
move all activation handling into MainPage
This commit is contained in:
@@ -24,7 +24,6 @@ namespace PomoTime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed partial class App : Application
|
sealed partial class App : Application
|
||||||
{
|
{
|
||||||
public RunningState RunningState = new RunningState();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the singleton application object. This is the first line of authored code
|
/// Initializes the singleton application object. This is the first line of authored code
|
||||||
@@ -44,16 +43,6 @@ namespace PomoTime
|
|||||||
{
|
{
|
||||||
Frame rootFrame = Window.Current.Content as Frame;
|
Frame rootFrame = Window.Current.Content as Frame;
|
||||||
|
|
||||||
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
|
|
||||||
if (localSettings.Values["MinutesLeft"] != null)
|
|
||||||
{
|
|
||||||
RunningState.MinutesLeft = (int)localSettings.Values["MinutesLeft"];
|
|
||||||
RunningState.SecondsLeft = (int)localSettings.Values["SecondsLeft"];
|
|
||||||
RunningState.IsRunning = (bool)localSettings.Values["IsRunning"];
|
|
||||||
RunningState.PreviousShortBreaks = (int)localSettings.Values["PreviousShortBreaks"];
|
|
||||||
RunningState.CurrentPeriod = (Period)localSettings.Values["CurrentPeriod"];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not repeat app initialization when the Window already has content,
|
// Do not repeat app initialization when the Window already has content,
|
||||||
// just ensure that the window is active
|
// just ensure that the window is active
|
||||||
if (rootFrame == null)
|
if (rootFrame == null)
|
||||||
@@ -78,7 +67,7 @@ namespace PomoTime
|
|||||||
// When the navigation stack isn't restored navigate to the first page,
|
// When the navigation stack isn't restored navigate to the first page,
|
||||||
// configuring the new page by passing required information as a navigation
|
// configuring the new page by passing required information as a navigation
|
||||||
// parameter
|
// parameter
|
||||||
rootFrame.Navigate(typeof(MainPage), RunningState);
|
rootFrame.Navigate(typeof(MainPage), null);
|
||||||
}
|
}
|
||||||
// Ensure the current window is active
|
// Ensure the current window is active
|
||||||
Window.Current.Activate();
|
Window.Current.Activate();
|
||||||
@@ -90,23 +79,12 @@ namespace PomoTime
|
|||||||
QueryString args = QueryString.Parse(toastActivationArgs.Argument);
|
QueryString args = QueryString.Parse(toastActivationArgs.Argument);
|
||||||
if (args.Contains("action"))
|
if (args.Contains("action"))
|
||||||
{
|
{
|
||||||
localSettings.Values["SuspendTime"] = (DateTime.Now + new TimeSpan(1, 0, 0)).Ticks;
|
rootFrame.Navigate(typeof(MainPage), args["action"]);
|
||||||
switch (args["action"])
|
} else
|
||||||
{
|
{
|
||||||
case "continue":
|
rootFrame.Navigate(typeof(MainPage), null);
|
||||||
RunningState.IsRunning = true;
|
|
||||||
RunningState.MinutesLeft = 0;
|
|
||||||
RunningState.SecondsLeft = 0;
|
|
||||||
break;
|
|
||||||
case "5minutes":
|
|
||||||
RunningState.MinutesLeft = 5;
|
|
||||||
RunningState.SecondsLeft = 0;
|
|
||||||
RunningState.IsRunning = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rootFrame.Navigate(typeof(MainPage), RunningState);
|
|
||||||
Window.Current.Activate();
|
Window.Current.Activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ namespace PomoTime
|
|||||||
|
|
||||||
if (MainViewRunningState.MinutesLeft != 0 || MainViewRunningState.SecondsLeft != 0)
|
if (MainViewRunningState.MinutesLeft != 0 || MainViewRunningState.SecondsLeft != 0)
|
||||||
{
|
{
|
||||||
SchedulePeriodOverNotification();
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ namespace PomoTime
|
|||||||
AppBarButton b = sender as AppBarButton;
|
AppBarButton b = sender as AppBarButton;
|
||||||
MainViewRunningState.IsRunning = false;
|
MainViewRunningState.IsRunning = false;
|
||||||
|
|
||||||
ClearScheduledNotifications();
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Reset()
|
private void Reset()
|
||||||
@@ -280,7 +280,7 @@ namespace PomoTime
|
|||||||
MainViewRunningState.MinutesLeft = WorkMinutes;
|
MainViewRunningState.MinutesLeft = WorkMinutes;
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
MainViewRunningState.SecondsLeft = 0;
|
||||||
|
|
||||||
ClearScheduledNotifications();
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetButton_Click(object sender, RoutedEventArgs e)
|
private void ResetButton_Click(object sender, RoutedEventArgs e)
|
||||||
@@ -421,23 +421,61 @@ namespace PomoTime
|
|||||||
StopTimer();
|
StopTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LoadRunningState()
|
||||||
|
{
|
||||||
|
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
|
||||||
|
if (localSettings.Values["MinutesLeft"] != null)
|
||||||
|
{
|
||||||
|
MainViewRunningState.MinutesLeft = (int)localSettings.Values["MinutesLeft"];
|
||||||
|
MainViewRunningState.SecondsLeft = (int)localSettings.Values["SecondsLeft"];
|
||||||
|
MainViewRunningState.IsRunning = (bool)localSettings.Values["IsRunning"];
|
||||||
|
MainViewRunningState.PreviousShortBreaks = (int)localSettings.Values["PreviousShortBreaks"];
|
||||||
|
MainViewRunningState.CurrentPeriod = (Period)localSettings.Values["CurrentPeriod"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnNavigatedTo(e);
|
base.OnNavigatedTo(e);
|
||||||
|
string action = (string)e.Parameter;
|
||||||
MainViewRunningState = (RunningState)e.Parameter;
|
|
||||||
StopTimer();
|
StopTimer();
|
||||||
|
|
||||||
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
|
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
|
||||||
if (localSettings.Values["SuspendTime"] != null)
|
if (localSettings.Values["SuspendTime"] != null)
|
||||||
{
|
{
|
||||||
SuspendTime = new DateTime((long)localSettings.Values["SuspendTime"]);
|
SuspendTime = new DateTime((long)localSettings.Values["SuspendTime"]);
|
||||||
FastForwardTime(SuspendTime);
|
LoadRunningState();
|
||||||
|
|
||||||
|
if(action != null)
|
||||||
|
{
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case "5minutes":
|
||||||
|
MainViewRunningState.MinutesLeft = 5;
|
||||||
|
MainViewRunningState.SecondsLeft = 0;
|
||||||
|
MainViewRunningState.IsRunning = true;
|
||||||
|
break;
|
||||||
|
case "continue":
|
||||||
|
MainViewRunningState.MinutesLeft = 0;
|
||||||
|
MainViewRunningState.SecondsLeft = 0;
|
||||||
|
// Onto the next period
|
||||||
|
PlusSecond();
|
||||||
|
MainViewRunningState.IsRunning = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
FastForwardTime(SuspendTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
SaveLocalState();
|
SaveLocalState();
|
||||||
}
|
}
|
||||||
|
|
||||||
StartTimer();
|
StartTimer();
|
||||||
RescheduleNotification();
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user