mirror of
https://github.com/usatiuk/PomoTime.git
synced 2025-10-28 08:27:48 +01:00
move all activation handling into MainPage
This commit is contained in:
@@ -24,7 +24,6 @@ namespace PomoTime
|
||||
/// </summary>
|
||||
sealed partial class App : Application
|
||||
{
|
||||
public RunningState RunningState = new RunningState();
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
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,
|
||||
// just ensure that the window is active
|
||||
if (rootFrame == null)
|
||||
@@ -78,7 +67,7 @@ namespace PomoTime
|
||||
// When the navigation stack isn't restored navigate to the first page,
|
||||
// configuring the new page by passing required information as a navigation
|
||||
// parameter
|
||||
rootFrame.Navigate(typeof(MainPage), RunningState);
|
||||
rootFrame.Navigate(typeof(MainPage), null);
|
||||
}
|
||||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
@@ -90,23 +79,12 @@ namespace PomoTime
|
||||
QueryString args = QueryString.Parse(toastActivationArgs.Argument);
|
||||
if (args.Contains("action"))
|
||||
{
|
||||
localSettings.Values["SuspendTime"] = (DateTime.Now + new TimeSpan(1, 0, 0)).Ticks;
|
||||
switch (args["action"])
|
||||
{
|
||||
case "continue":
|
||||
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), args["action"]);
|
||||
} else
|
||||
{
|
||||
rootFrame.Navigate(typeof(MainPage), null);
|
||||
}
|
||||
|
||||
rootFrame.Navigate(typeof(MainPage), RunningState);
|
||||
Window.Current.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace PomoTime
|
||||
|
||||
if (MainViewRunningState.MinutesLeft != 0 || MainViewRunningState.SecondsLeft != 0)
|
||||
{
|
||||
SchedulePeriodOverNotification();
|
||||
RescheduleNotification();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ namespace PomoTime
|
||||
AppBarButton b = sender as AppBarButton;
|
||||
MainViewRunningState.IsRunning = false;
|
||||
|
||||
ClearScheduledNotifications();
|
||||
RescheduleNotification();
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
@@ -280,7 +280,7 @@ namespace PomoTime
|
||||
MainViewRunningState.MinutesLeft = WorkMinutes;
|
||||
MainViewRunningState.SecondsLeft = 0;
|
||||
|
||||
ClearScheduledNotifications();
|
||||
RescheduleNotification();
|
||||
}
|
||||
|
||||
private void ResetButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -421,23 +421,61 @@ namespace PomoTime
|
||||
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)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
MainViewRunningState = (RunningState)e.Parameter;
|
||||
string action = (string)e.Parameter;
|
||||
|
||||
StopTimer();
|
||||
|
||||
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
|
||||
if (localSettings.Values["SuspendTime"] != null)
|
||||
{
|
||||
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
|
||||
{
|
||||
Reset();
|
||||
SaveLocalState();
|
||||
}
|
||||
|
||||
StartTimer();
|
||||
RescheduleNotification();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user