diff --git a/Pomotimer/App.xaml b/Pomotimer/App.xaml index 004f42e..d31dd3c 100644 --- a/Pomotimer/App.xaml +++ b/Pomotimer/App.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Pomotimer"> + diff --git a/Pomotimer/MainPage.xaml b/Pomotimer/MainPage.xaml index 6ba72c2..d1cc6f2 100644 --- a/Pomotimer/MainPage.xaml +++ b/Pomotimer/MainPage.xaml @@ -3,12 +3,21 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Microsoft.UI.Xaml.Controls" + xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:Pomotimer" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" mc:Ignorable="d"> + + + + + @@ -18,16 +27,44 @@ - + + + + + + + + - - 40 - - - :00 - + + + + @@ -49,7 +86,7 @@ Minimum="0" SmallChange="5" SpinButtonPlacementMode="Inline" - Value="40" /> + Value="{x:Bind WorkMinutes, Mode=TwoWay}" /> + Value="{x:Bind RestMinutes, Mode=TwoWay}" /> @@ -71,20 +108,38 @@ DefaultLabelPosition="Right" IsOpen="True"> + Visibility="{x:Bind runningState.IsRunning, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay, ConverterParameter=True}" /> + Visibility="{x:Bind runningState.IsRunning, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" /> - - - + Visibility="Visible" /> + + + \ No newline at end of file diff --git a/Pomotimer/MainPage.xaml.cs b/Pomotimer/MainPage.xaml.cs index 709a5c4..bed0062 100644 --- a/Pomotimer/MainPage.xaml.cs +++ b/Pomotimer/MainPage.xaml.cs @@ -8,11 +8,13 @@ using Windows.Foundation.Collections; using Windows.UI.ViewManagement; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using controls = Microsoft.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; +using Windows.Storage; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 @@ -24,15 +26,138 @@ namespace Pomotimer /// public sealed partial class MainPage : Page { + private DispatcherTimer dispatcherTimer; + public RunningState runningState = new RunningState(); + + private int RestMinutes { get; set; } + private int WorkMinutes { get; set; } + public MainPage() { this.InitializeComponent(); + // Some maigc numbers Size defaultSize = new Size(500, 250); ApplicationView.PreferredLaunchViewSize = defaultSize; ApplicationView.GetForCurrentView().SetPreferredMinSize(defaultSize); ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; + + Application.Current.Suspending += OnSuspending; + this.Loaded += MainPageLoaded; + + ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; + Windows.Storage.ApplicationDataCompositeValue minutes = (ApplicationDataCompositeValue)roamingSettings.Values["Minutes"]; + if (minutes != null) + { + WorkMinutes = (int)minutes["WorkMinutes"]; + RestMinutes = (int)minutes["RestMinutes"]; + } + else + { + // Some maigc defualt numbers + WorkMinutes = 40; + RestMinutes = 5; + } + runningState.MinutesLeft = WorkMinutes; + runningState.SecondsLeft = 0; + + } + public void DispatcherTimerSetup() + { + dispatcherTimer = new DispatcherTimer(); + dispatcherTimer.Tick += dispatcherTimer_Tick; + dispatcherTimer.Interval = new TimeSpan(0, 0, 1); + } + + void dispatcherTimer_Tick(object sender, object e) + { + if (runningState.SecondsLeft == 0) + { + runningState.SecondsLeft = 59; + if (runningState.MinutesLeft == 0) + { + if (runningState.OnRest) + { + runningState.OnRest = false; + runningState.MinutesLeft = WorkMinutes; + runningState.SecondsLeft = 0; + } + else + { + runningState.OnRest = true; + runningState.MinutesLeft = RestMinutes; + runningState.SecondsLeft = 0; + } + } + else + { + runningState.MinutesLeft--; + } + } + else + { + runningState.SecondsLeft--; + } + } + + + private void PlayButton_Click(object sender, RoutedEventArgs e) + { + AppBarButton b = sender as AppBarButton; + dispatcherTimer.Start(); + runningState.IsRunning = true; + } + + private void PauseButton_Click(object sender, RoutedEventArgs e) + { + AppBarButton b = sender as AppBarButton; + dispatcherTimer.Stop(); + runningState.IsRunning = false; + } + + private void ResetButton_Click(object sender, RoutedEventArgs e) + { + AppBarButton b = sender as AppBarButton; + dispatcherTimer.Stop(); + runningState.IsRunning = false; + + runningState.OnRest = false; + runningState.MinutesLeft = WorkMinutes; + runningState.SecondsLeft = 0; + } + + private void Plus1Button_Click(object sender, RoutedEventArgs e) + { + AppBarButton b = sender as AppBarButton; + runningState.MinutesLeft += 1; + } + + private void Plus5Button_Click(object sender, RoutedEventArgs e) + { + AppBarButton b = sender as AppBarButton; + runningState.MinutesLeft += 5; + } + + private void Plus10Button_Click(object sender, RoutedEventArgs e) + { + AppBarButton b = sender as AppBarButton; + runningState.MinutesLeft += 10; + } + private void OnSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) + { + var deferral = e.SuspendingOperation.GetDeferral(); + ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; + Windows.Storage.ApplicationDataCompositeValue minutes = new Windows.Storage.ApplicationDataCompositeValue(); + minutes["WorkMinutes"] = WorkMinutes; + minutes["RestMinutes"] = RestMinutes; + roamingSettings.Values["Minutes"] = minutes; + deferral.Complete(); + } + + private void MainPageLoaded(object sender, RoutedEventArgs e) + { + DispatcherTimerSetup(); } } } diff --git a/Pomotimer/Pomotimer.csproj b/Pomotimer/Pomotimer.csproj index 21590d0..0003288 100644 --- a/Pomotimer/Pomotimer.csproj +++ b/Pomotimer/Pomotimer.csproj @@ -123,6 +123,7 @@ MainPage.xaml + @@ -153,6 +154,9 @@ 6.2.9 + + 6.0.0 + 2.3.200213001 diff --git a/Pomotimer/RunningState.cs b/Pomotimer/RunningState.cs new file mode 100644 index 0000000..c80537c --- /dev/null +++ b/Pomotimer/RunningState.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace Pomotimer +{ + public class RunningState : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private bool _is_running; + public bool IsRunning + { + get { return _is_running; } + set + { + _is_running = value; + NotifyPropertyChanged("IsRunning"); + } + + } + + public int _minutes_left; + public int MinutesLeft + { + get { return _minutes_left; } + set + { + _minutes_left = value; + NotifyPropertyChanged("MinutesLeft"); + } + + } + + public int _seconds_left; + public int SecondsLeft + { + get { return _seconds_left; } + set + { + _seconds_left = value; + NotifyPropertyChanged("SecondsLeft"); + } + + } + + public bool _on_rest; + + public bool OnRest + { + get { return _on_rest; } + set + { + _on_rest = value; + NotifyPropertyChanged("OnRest"); + } + + } + } +}