mirror of
https://github.com/usatiuk/PomoTime.git
synced 2025-10-29 00:47:48 +01:00
use only seconds internally
This commit is contained in:
@@ -12,8 +12,9 @@
|
|||||||
|
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||||
<converters:FormatStringConverter x:Key="FormatStringConverter" />
|
|
||||||
<local:PeriodToStringConverter x:Key="PeriodToStringConverter" />
|
<local:PeriodToStringConverter x:Key="PeriodToStringConverter" />
|
||||||
|
<local:SecondsLeftToMinutesConverter x:Key="SecondsLeftToMinutesConverter" />
|
||||||
|
<local:SecondsLeftToSecondsConverter x:Key="SecondsLeftToSecondsConverter" />
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
x:Name="MinutesText"
|
x:Name="MinutesText"
|
||||||
FontSize="60"
|
FontSize="60"
|
||||||
FontWeight="Bold"
|
FontWeight="Bold"
|
||||||
Text="{x:Bind MainViewRunningState.MinutesLeft, Converter={StaticResource FormatStringConverter}, Mode=OneWay, ConverterParameter='00'}" />
|
Text="{x:Bind MainViewRunningState.SecondsLeft, Converter={StaticResource SecondsLeftToMinutesConverter}, Mode=OneWay}" />
|
||||||
<Run
|
<Run
|
||||||
x:Name="Separator"
|
x:Name="Separator"
|
||||||
FontSize="30"
|
FontSize="30"
|
||||||
@@ -52,7 +53,7 @@
|
|||||||
x:Name="SecondsText"
|
x:Name="SecondsText"
|
||||||
FontSize="30"
|
FontSize="30"
|
||||||
FontWeight="SemiBold"
|
FontWeight="SemiBold"
|
||||||
Text="{x:Bind MainViewRunningState.SecondsLeft, Converter={StaticResource FormatStringConverter}, Mode=OneWay, ConverterParameter='00'}" />
|
Text="{x:Bind MainViewRunningState.SecondsLeft, Converter={StaticResource SecondsLeftToSecondsConverter}, Mode=OneWay}" />
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
</RichTextBlock>
|
</RichTextBlock>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace PomoTime
|
|||||||
{
|
{
|
||||||
if (!MainViewRunningState.IsRunning && MainViewRunningState.CurrentPeriod == Period.Work)
|
if (!MainViewRunningState.IsRunning && MainViewRunningState.CurrentPeriod == Period.Work)
|
||||||
{
|
{
|
||||||
MainViewRunningState.MinutesLeft = value;
|
MainViewRunningState.SecondsLeft = value * 60;
|
||||||
}
|
}
|
||||||
_work_minutes = value;
|
_work_minutes = value;
|
||||||
}
|
}
|
||||||
@@ -79,48 +79,36 @@ namespace PomoTime
|
|||||||
{
|
{
|
||||||
if (MainViewRunningState.SecondsLeft == 0)
|
if (MainViewRunningState.SecondsLeft == 0)
|
||||||
{
|
{
|
||||||
MainViewRunningState.SecondsLeft = 59;
|
switch (MainViewRunningState.CurrentPeriod)
|
||||||
if (MainViewRunningState.MinutesLeft == 0)
|
|
||||||
{
|
{
|
||||||
switch (MainViewRunningState.CurrentPeriod)
|
case Period.Work:
|
||||||
{
|
if (MainViewRunningState.PreviousShortBreaks < 4)
|
||||||
case Period.Work:
|
{
|
||||||
if (MainViewRunningState.PreviousShortBreaks != 4)
|
MainViewRunningState.CurrentPeriod = Period.ShortBreak;
|
||||||
{
|
MainViewRunningState.SecondsLeft = BreakMinutes * 60;
|
||||||
MainViewRunningState.CurrentPeriod = Period.ShortBreak;
|
}
|
||||||
MainViewRunningState.MinutesLeft = BreakMinutes;
|
else
|
||||||
}
|
{
|
||||||
else
|
MainViewRunningState.CurrentPeriod = Period.LongBreak;
|
||||||
{
|
MainViewRunningState.SecondsLeft = LongBreakMinutes * 60;
|
||||||
MainViewRunningState.CurrentPeriod = Period.LongBreak;
|
}
|
||||||
MainViewRunningState.MinutesLeft = LongBreakMinutes;
|
break;
|
||||||
}
|
case Period.ShortBreak:
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
MainViewRunningState.CurrentPeriod = Period.Work;
|
||||||
|
MainViewRunningState.PreviousShortBreaks += 1;
|
||||||
break;
|
MainViewRunningState.SecondsLeft = WorkMinutes * 60;
|
||||||
case Period.ShortBreak:
|
break;
|
||||||
MainViewRunningState.CurrentPeriod = Period.Work;
|
case Period.LongBreak:
|
||||||
MainViewRunningState.PreviousShortBreaks += 1;
|
MainViewRunningState.CurrentPeriod = Period.Work;
|
||||||
MainViewRunningState.MinutesLeft = WorkMinutes;
|
MainViewRunningState.PreviousShortBreaks = 0;
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
MainViewRunningState.SecondsLeft = WorkMinutes * 60;
|
||||||
break;
|
break;
|
||||||
case Period.LongBreak:
|
default:
|
||||||
MainViewRunningState.CurrentPeriod = Period.Work;
|
throw new ArgumentOutOfRangeException();
|
||||||
MainViewRunningState.PreviousShortBreaks = 0;
|
|
||||||
MainViewRunningState.MinutesLeft = WorkMinutes;
|
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
RescheduleNotification();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MainViewRunningState.MinutesLeft--;
|
|
||||||
}
|
}
|
||||||
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
else if (MainViewRunningState.SecondsLeft == 1 && MainViewRunningState.MinutesLeft == 0)
|
else if (MainViewRunningState.SecondsLeft == 1)
|
||||||
{
|
{
|
||||||
MainViewRunningState.IsRunning = false;
|
MainViewRunningState.IsRunning = false;
|
||||||
MainViewRunningState.SecondsLeft--;
|
MainViewRunningState.SecondsLeft--;
|
||||||
@@ -186,7 +174,7 @@ namespace PomoTime
|
|||||||
Scenario = ToastScenario.Alarm,
|
Scenario = ToastScenario.Alarm,
|
||||||
};
|
};
|
||||||
|
|
||||||
TimeSpan WaitTime = new TimeSpan(0, MainViewRunningState.MinutesLeft, MainViewRunningState.SecondsLeft);
|
TimeSpan WaitTime = new TimeSpan(0, 0, MainViewRunningState.SecondsLeft);
|
||||||
var toast = new Windows.UI.Notifications.ScheduledToastNotification(toastContent.GetXml(), DateTime.Now + WaitTime);
|
var toast = new Windows.UI.Notifications.ScheduledToastNotification(toastContent.GetXml(), DateTime.Now + WaitTime);
|
||||||
Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
|
Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
|
||||||
}
|
}
|
||||||
@@ -210,7 +198,7 @@ namespace PomoTime
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MainViewRunningState.MinutesLeft != 0 || MainViewRunningState.SecondsLeft != 0)
|
if (MainViewRunningState.SecondsLeft != 0)
|
||||||
{
|
{
|
||||||
SchedulePeriodOverNotification();
|
SchedulePeriodOverNotification();
|
||||||
}
|
}
|
||||||
@@ -224,10 +212,7 @@ namespace PomoTime
|
|||||||
MainViewRunningState.StartTime = DateTime.Now;
|
MainViewRunningState.StartTime = DateTime.Now;
|
||||||
SaveLocalState();
|
SaveLocalState();
|
||||||
|
|
||||||
if (MainViewRunningState.MinutesLeft != 0 || MainViewRunningState.SecondsLeft != 0)
|
RescheduleNotification();
|
||||||
{
|
|
||||||
RescheduleNotification();
|
|
||||||
}
|
|
||||||
RestartTimer();
|
RestartTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,8 +229,7 @@ namespace PomoTime
|
|||||||
MainViewRunningState.IsRunning = false;
|
MainViewRunningState.IsRunning = false;
|
||||||
|
|
||||||
MainViewRunningState.CurrentPeriod = Period.Work;
|
MainViewRunningState.CurrentPeriod = Period.Work;
|
||||||
MainViewRunningState.MinutesLeft = WorkMinutes;
|
MainViewRunningState.SecondsLeft = WorkMinutes * 60;
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
|
||||||
MainViewRunningState.PreviousShortBreaks = 0;
|
MainViewRunningState.PreviousShortBreaks = 0;
|
||||||
|
|
||||||
RescheduleNotification();
|
RescheduleNotification();
|
||||||
@@ -261,7 +245,7 @@ namespace PomoTime
|
|||||||
private void Plus1Button_Click(object sender, RoutedEventArgs e)
|
private void Plus1Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
AppBarButton b = sender as AppBarButton;
|
AppBarButton b = sender as AppBarButton;
|
||||||
MainViewRunningState.MinutesLeft += 1;
|
MainViewRunningState.SecondsLeft += 60;
|
||||||
|
|
||||||
RescheduleNotification();
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
@@ -269,7 +253,7 @@ namespace PomoTime
|
|||||||
private void Plus5Button_Click(object sender, RoutedEventArgs e)
|
private void Plus5Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
AppBarButton b = sender as AppBarButton;
|
AppBarButton b = sender as AppBarButton;
|
||||||
MainViewRunningState.MinutesLeft += 5;
|
MainViewRunningState.SecondsLeft += 5 * 60;
|
||||||
|
|
||||||
RescheduleNotification();
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
@@ -277,7 +261,7 @@ namespace PomoTime
|
|||||||
private void Plus10Button_Click(object sender, RoutedEventArgs e)
|
private void Plus10Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
AppBarButton b = sender as AppBarButton;
|
AppBarButton b = sender as AppBarButton;
|
||||||
MainViewRunningState.MinutesLeft += 10;
|
MainViewRunningState.SecondsLeft += 10 * 60;
|
||||||
|
|
||||||
RescheduleNotification();
|
RescheduleNotification();
|
||||||
}
|
}
|
||||||
@@ -295,7 +279,6 @@ namespace PomoTime
|
|||||||
DateTime SuspendTime = DateTime.Now;
|
DateTime SuspendTime = DateTime.Now;
|
||||||
localSettings.Values["SuspendTime"] = SuspendTime.Ticks;
|
localSettings.Values["SuspendTime"] = SuspendTime.Ticks;
|
||||||
localSettings.Values["StartTime"] = MainViewRunningState.StartTime.Ticks;
|
localSettings.Values["StartTime"] = MainViewRunningState.StartTime.Ticks;
|
||||||
localSettings.Values["MinutesLeft"] = MainViewRunningState.MinutesLeft;
|
|
||||||
localSettings.Values["SecondsLeft"] = MainViewRunningState.SecondsLeft;
|
localSettings.Values["SecondsLeft"] = MainViewRunningState.SecondsLeft;
|
||||||
localSettings.Values["IsRunning"] = MainViewRunningState.IsRunning;
|
localSettings.Values["IsRunning"] = MainViewRunningState.IsRunning;
|
||||||
localSettings.Values["PreviousShortBreaks"] = MainViewRunningState.PreviousShortBreaks;
|
localSettings.Values["PreviousShortBreaks"] = MainViewRunningState.PreviousShortBreaks;
|
||||||
@@ -330,24 +313,14 @@ namespace PomoTime
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TimeFromSuspend.TotalSeconds >= MainViewRunningState.MinutesLeft * 60 + MainViewRunningState.SecondsLeft)
|
if (TimeFromSuspend.TotalSeconds >= MainViewRunningState.SecondsLeft)
|
||||||
{
|
{
|
||||||
MainViewRunningState.IsRunning = false;
|
MainViewRunningState.IsRunning = false;
|
||||||
MainViewRunningState.MinutesLeft = 0;
|
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
MainViewRunningState.SecondsLeft = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TimeFromSuspend.Seconds > MainViewRunningState.SecondsLeft)
|
|
||||||
{
|
|
||||||
MainViewRunningState.MinutesLeft -= TimeFromSuspend.Minutes + 1;
|
|
||||||
MainViewRunningState.SecondsLeft = MainViewRunningState.SecondsLeft + 60 - TimeFromSuspend.Seconds;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MainViewRunningState.MinutesLeft -= TimeFromSuspend.Minutes;
|
|
||||||
MainViewRunningState.SecondsLeft -= TimeFromSuspend.Seconds;
|
MainViewRunningState.SecondsLeft -= TimeFromSuspend.Seconds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnResuming(object sender, Object e)
|
private void OnResuming(object sender, Object e)
|
||||||
@@ -399,9 +372,8 @@ namespace PomoTime
|
|||||||
private void LoadRunningState()
|
private void LoadRunningState()
|
||||||
{
|
{
|
||||||
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
|
ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
|
||||||
if (localSettings.Values["MinutesLeft"] != null)
|
if (localSettings.Values["SecondsLeft"] != null)
|
||||||
{
|
{
|
||||||
MainViewRunningState.MinutesLeft = (int)localSettings.Values["MinutesLeft"];
|
|
||||||
MainViewRunningState.SecondsLeft = (int)localSettings.Values["SecondsLeft"];
|
MainViewRunningState.SecondsLeft = (int)localSettings.Values["SecondsLeft"];
|
||||||
MainViewRunningState.IsRunning = (bool)localSettings.Values["IsRunning"];
|
MainViewRunningState.IsRunning = (bool)localSettings.Values["IsRunning"];
|
||||||
MainViewRunningState.PreviousShortBreaks = (int)localSettings.Values["PreviousShortBreaks"];
|
MainViewRunningState.PreviousShortBreaks = (int)localSettings.Values["PreviousShortBreaks"];
|
||||||
@@ -426,19 +398,16 @@ namespace PomoTime
|
|||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case "5minutes":
|
case "5minutes":
|
||||||
MainViewRunningState.MinutesLeft = 5;
|
MainViewRunningState.SecondsLeft = 5 * 60;
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
|
||||||
MainViewRunningState.IsRunning = true;
|
MainViewRunningState.IsRunning = true;
|
||||||
break;
|
break;
|
||||||
case "continue":
|
case "continue":
|
||||||
MainViewRunningState.MinutesLeft = 0;
|
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
MainViewRunningState.SecondsLeft = 0;
|
||||||
// Onto the next period
|
// Onto the next period
|
||||||
PlusSecond();
|
PlusSecond();
|
||||||
MainViewRunningState.IsRunning = true;
|
MainViewRunningState.IsRunning = true;
|
||||||
break;
|
break;
|
||||||
case "nothing":
|
case "nothing":
|
||||||
MainViewRunningState.MinutesLeft = 0;
|
|
||||||
MainViewRunningState.SecondsLeft = 0;
|
MainViewRunningState.SecondsLeft = 0;
|
||||||
MainViewRunningState.IsRunning = false;
|
MainViewRunningState.IsRunning = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -133,6 +133,8 @@
|
|||||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Period.cs" />
|
<Compile Include="Period.cs" />
|
||||||
|
<Compile Include="SecondsLeftToMinutesConverter.cs" />
|
||||||
|
<Compile Include="SecondsLeftToSecondsConverter.cs" />
|
||||||
<Compile Include="PeriodToStringConverter.cs" />
|
<Compile Include="PeriodToStringConverter.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RunningState.cs" />
|
<Compile Include="RunningState.cs" />
|
||||||
|
|||||||
@@ -24,18 +24,6 @@ namespace PomoTime
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int _minutes_left;
|
|
||||||
public int MinutesLeft
|
|
||||||
{
|
|
||||||
get { return _minutes_left; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_minutes_left = value;
|
|
||||||
NotifyPropertyChanged("MinutesLeft");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int _seconds_left;
|
public int _seconds_left;
|
||||||
public int SecondsLeft
|
public int SecondsLeft
|
||||||
{
|
{
|
||||||
@@ -84,12 +72,5 @@ namespace PomoTime
|
|||||||
NotifyPropertyChanged("PreviousShortBreaks");
|
NotifyPropertyChanged("PreviousShortBreaks");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CurrentPeriodName()
|
|
||||||
{
|
|
||||||
return CurrentPeriod.Name();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
31
PomoTime/SecondsLeftToMinutesConverter.cs
Normal file
31
PomoTime/SecondsLeftToMinutesConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using Windows.UI.Xaml.Data;
|
||||||
|
|
||||||
|
namespace PomoTime
|
||||||
|
{
|
||||||
|
public class SecondsLeftToMinutesConverter : IValueConverter
|
||||||
|
{
|
||||||
|
|
||||||
|
#region IValueConverter Members
|
||||||
|
|
||||||
|
// Define the Convert method to change a DateTime object to
|
||||||
|
// a month string.
|
||||||
|
public object Convert(object value, Type targetType,
|
||||||
|
object parameter, string language)
|
||||||
|
{
|
||||||
|
// The value parameter is the data from the source object.
|
||||||
|
int secondsLeft = (int)value;
|
||||||
|
return String.Format("{0:00}", secondsLeft / 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConvertBack is not implemented for a OneWay binding.
|
||||||
|
public object ConvertBack(object value, Type targetType,
|
||||||
|
object parameter, string language)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
PomoTime/SecondsLeftToSecondsConverter.cs
Normal file
31
PomoTime/SecondsLeftToSecondsConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using Windows.UI.Xaml.Data;
|
||||||
|
|
||||||
|
namespace PomoTime
|
||||||
|
{
|
||||||
|
public class SecondsLeftToSecondsConverter : IValueConverter
|
||||||
|
{
|
||||||
|
|
||||||
|
#region IValueConverter Members
|
||||||
|
|
||||||
|
// Define the Convert method to change a DateTime object to
|
||||||
|
// a month string.
|
||||||
|
public object Convert(object value, Type targetType,
|
||||||
|
object parameter, string language)
|
||||||
|
{
|
||||||
|
// The value parameter is the data from the source object.
|
||||||
|
int secondsLeft = (int)value;
|
||||||
|
return String.Format("{0:00}", secondsLeft % 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConvertBack is not implemented for a OneWay binding.
|
||||||
|
public object ConvertBack(object value, Type targetType,
|
||||||
|
object parameter, string language)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user