fixed bug when clicking on a notification would reset timer if app wasn't suspended before
better notifications
This commit is contained in:
2020-05-08 13:06:39 +03:00
parent 9d76132299
commit 43e54e3280
6 changed files with 102 additions and 39 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Microsoft.QueryStringDotNET;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -84,6 +85,8 @@ namespace PomoTime
}
if (e is ToastNotificationActivatedEventArgs)
{
var toastActivationArgs = e as ToastNotificationActivatedEventArgs;
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
if (localSettings.Values["MinutesLeft"] != null)
{
@@ -94,6 +97,22 @@ namespace PomoTime
RunningState.CurrentPeriod = (Period)localSettings.Values["CurrentPeriod"];
}
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;
break;
case "5minutes":
RunningState.MinutesLeft += 5;
RunningState.IsRunning = true;
break;
}
}
rootFrame.Navigate(typeof(MainPage), RunningState);
Window.Current.Activate();
}

View File

@@ -109,7 +109,7 @@ namespace PomoTime
}
}
void timer_Tick()
void TimerTick()
{
if (!MainViewRunningState.IsRunning)
{
@@ -167,25 +167,12 @@ namespace PomoTime
{
MainViewRunningState.SecondsLeft--;
}
SaveLocalState();
}
void SchedulePeriodOverNotification()
{
string header;
switch (MainViewRunningState.CurrentPeriod)
{
case Period.LongBreak:
header = "Long break time over!";
break;
case Period.ShortBreak:
header = "Short break time over!";
break;
case Period.Work:
header = "Work time over!";
break;
default:
throw new ArgumentOutOfRangeException();
}
string header = $"{MainViewRunningState.CurrentPeriod.Name()} is over!";
ToastVisual visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
@@ -206,9 +193,27 @@ namespace PomoTime
}
};
ToastActionsCustom actions = new ToastActionsCustom()
{
Buttons =
{
new ToastButton("Continue", "action=continue")
{
ActivationType = ToastActivationType.Foreground
},
new ToastButton("Add 5 minutes", "action=5minutes")
{
ActivationType = ToastActivationType.Foreground
}
}
};
ToastContent toastContent = new ToastContent()
{
Visual = visual,
Actions = actions,
Scenario = ToastScenario.Alarm,
};
TimeSpan WaitTime = new TimeSpan(0, MainViewRunningState.MinutesLeft, MainViewRunningState.SecondsLeft);
@@ -231,6 +236,8 @@ namespace PomoTime
{
AppBarButton b = sender as AppBarButton;
MainViewRunningState.IsRunning = true;
MainViewRunningState.StartTime = DateTime.Now;
SaveLocalState();
if (MainViewRunningState.MinutesLeft != 0 || MainViewRunningState.SecondsLeft != 0)
{
@@ -291,21 +298,31 @@ namespace PomoTime
minutes["LongBreakMinutes"] = LongBreakMinutes;
roamingSettings.Values["Minutes"] = minutes;
SaveLocalState();
deferral.Complete();
}
private void SaveLocalState()
{
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
SuspendTime = DateTime.Now;
localSettings.Values["SuspendTime"] = SuspendTime.Ticks;
localSettings.Values["StartTime"] = MainViewRunningState.StartTime.Ticks;
localSettings.Values["MinutesLeft"] = MainViewRunningState.MinutesLeft;
localSettings.Values["SecondsLeft"] = MainViewRunningState.SecondsLeft;
localSettings.Values["IsRunning"] = MainViewRunningState.IsRunning;
localSettings.Values["PreviousShortBreaks"] = MainViewRunningState.PreviousShortBreaks;
localSettings.Values["CurrentPeriod"] = (int)MainViewRunningState.CurrentPeriod;
deferral.Complete();
}
private void FastForwardTime(DateTime since)
{
TimeSpan TimeFromSuspend = DateTime.Now - since;
if(TimeFromSuspend.TotalMilliseconds < 0)
{
return;
}
if (!MainViewRunningState.IsRunning)
{
return;
@@ -349,7 +366,7 @@ namespace PomoTime
await Dispatcher.RunAsync(CoreDispatcherPriority.High,
() =>
{
timer_Tick();
TimerTick();
});
}, TimeSpan.FromSeconds(1));
}
@@ -375,6 +392,7 @@ namespace PomoTime
else
{
Reset();
SaveLocalState();
}
}

View File

@@ -9,7 +9,7 @@
<Identity
Name="44844StepanUsatyuk.PomoTime"
Publisher="CN=D7EE55C2-4D4B-40F8-8EE5-CC4CEBCE2133"
Version="1.0.5.0" />
Version="1.0.6.0" />
<mp:PhoneIdentity PhoneProductId="4d8bddac-8ab7-4c19-b3c7-7b5a27b87594" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

View File

@@ -19,24 +19,7 @@ namespace PomoTime
{
// The value parameter is the data from the source object.
Period period = (Period)value;
string output;
switch (period)
{
case Period.LongBreak:
output = "Long break";
break;
case Period.ShortBreak:
output = "Short break";
break;
case Period.Work:
output = "Work";
break;
default:
throw new ArgumentOutOfRangeException();
}
// Return the month value to pass to the target.
return output;
return period.Name();
}
// ConvertBack is not implemented for a OneWay binding.

View File

@@ -222,6 +222,9 @@
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.3.200213001</Version>
</PackageReference>
<PackageReference Include="QueryString.NET">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>

View File

@@ -8,6 +8,29 @@ using System.Threading.Tasks;
namespace PomoTime
{
public static class PeriodExtensions
{
public static string Name(this Period period)
{
string output;
switch (period)
{
case Period.LongBreak:
output = "Long break";
break;
case Period.ShortBreak:
output = "Short break";
break;
case Period.Work:
output = "Work";
break;
default:
throw new ArgumentOutOfRangeException();
}
return output;
}
}
public enum Period
{
Work, ShortBreak, LongBreak
@@ -69,6 +92,18 @@ namespace PomoTime
}
public DateTime _start_time;
public DateTime StartTime
{
get { return _start_time; }
set
{
_start_time = value;
NotifyPropertyChanged("StartTime");
}
}
public int _previous_short_breaks;
public int PreviousShortBreaks
@@ -80,6 +115,11 @@ namespace PomoTime
NotifyPropertyChanged("PreviousShortBreaks");
}
}
public string CurrentPeriodName()
{
return CurrentPeriod.Name();
}
}