From 25b4f7b9b1c56cd199a29358fe35dc0184f6d943 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Fri, 18 Sep 2020 21:32:22 +0300 Subject: [PATCH] use only seconds internally --- PomoTime/MainPage.xaml | 7 +- PomoTime/MainPage.xaml.cs | 107 ++++++++-------------- PomoTime/PomoTime.csproj | 2 + PomoTime/RunningState.cs | 19 ---- PomoTime/SecondsLeftToMinutesConverter.cs | 31 +++++++ PomoTime/SecondsLeftToSecondsConverter.cs | 31 +++++++ 6 files changed, 106 insertions(+), 91 deletions(-) create mode 100644 PomoTime/SecondsLeftToMinutesConverter.cs create mode 100644 PomoTime/SecondsLeftToSecondsConverter.cs diff --git a/PomoTime/MainPage.xaml b/PomoTime/MainPage.xaml index 4946b1e..f85b7c0 100644 --- a/PomoTime/MainPage.xaml +++ b/PomoTime/MainPage.xaml @@ -12,8 +12,9 @@ - + + @@ -42,7 +43,7 @@ x:Name="MinutesText" FontSize="60" FontWeight="Bold" - Text="{x:Bind MainViewRunningState.MinutesLeft, Converter={StaticResource FormatStringConverter}, Mode=OneWay, ConverterParameter='00'}" /> + Text="{x:Bind MainViewRunningState.SecondsLeft, Converter={StaticResource SecondsLeftToMinutesConverter}, Mode=OneWay}" /> + Text="{x:Bind MainViewRunningState.SecondsLeft, Converter={StaticResource SecondsLeftToSecondsConverter}, Mode=OneWay}" /> = MainViewRunningState.MinutesLeft * 60 + MainViewRunningState.SecondsLeft) + if (TimeFromSuspend.TotalSeconds >= MainViewRunningState.SecondsLeft) { MainViewRunningState.IsRunning = false; - MainViewRunningState.MinutesLeft = 0; MainViewRunningState.SecondsLeft = 0; 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; - } private void OnResuming(object sender, Object e) @@ -399,9 +372,8 @@ namespace PomoTime private void LoadRunningState() { 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.IsRunning = (bool)localSettings.Values["IsRunning"]; MainViewRunningState.PreviousShortBreaks = (int)localSettings.Values["PreviousShortBreaks"]; @@ -426,19 +398,16 @@ namespace PomoTime switch (action) { case "5minutes": - MainViewRunningState.MinutesLeft = 5; - MainViewRunningState.SecondsLeft = 0; + MainViewRunningState.SecondsLeft = 5 * 60; MainViewRunningState.IsRunning = true; break; case "continue": - MainViewRunningState.MinutesLeft = 0; MainViewRunningState.SecondsLeft = 0; // Onto the next period PlusSecond(); MainViewRunningState.IsRunning = true; break; case "nothing": - MainViewRunningState.MinutesLeft = 0; MainViewRunningState.SecondsLeft = 0; MainViewRunningState.IsRunning = false; break; diff --git a/PomoTime/PomoTime.csproj b/PomoTime/PomoTime.csproj index d5ca971..0209f0c 100644 --- a/PomoTime/PomoTime.csproj +++ b/PomoTime/PomoTime.csproj @@ -133,6 +133,8 @@ MainPage.xaml + + diff --git a/PomoTime/RunningState.cs b/PomoTime/RunningState.cs index 08d19a6..0b813a5 100644 --- a/PomoTime/RunningState.cs +++ b/PomoTime/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 SecondsLeft { @@ -84,12 +72,5 @@ namespace PomoTime NotifyPropertyChanged("PreviousShortBreaks"); } } - - public string CurrentPeriodName() - { - return CurrentPeriod.Name(); - } } - - } diff --git a/PomoTime/SecondsLeftToMinutesConverter.cs b/PomoTime/SecondsLeftToMinutesConverter.cs new file mode 100644 index 0000000..47ccf43 --- /dev/null +++ b/PomoTime/SecondsLeftToMinutesConverter.cs @@ -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 + } + +} diff --git a/PomoTime/SecondsLeftToSecondsConverter.cs b/PomoTime/SecondsLeftToSecondsConverter.cs new file mode 100644 index 0000000..4a99ecb --- /dev/null +++ b/PomoTime/SecondsLeftToSecondsConverter.cs @@ -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 + } + +}