mirror of
https://github.com/usatiuk/PomoTime.git
synced 2025-10-29 00:47:48 +01:00
everything mostly works
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="using:Pomotimer">
|
xmlns:local="using:Pomotimer">
|
||||||
|
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|||||||
@@ -3,12 +3,21 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
|
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:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="using:Pomotimer"
|
xmlns:local="using:Pomotimer"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
|
<Page.Resources>
|
||||||
|
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||||
|
<converters:BoolToObjectConverter
|
||||||
|
x:Key="BoolToWorkRestConverter"
|
||||||
|
FalseValue="Work"
|
||||||
|
TrueValue="Rest" />
|
||||||
|
</Page.Resources>
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
@@ -18,16 +27,44 @@
|
|||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid Grid.Row="0" Grid.Column="0">
|
<Grid Grid.Row="0" Grid.Column="0">
|
||||||
<RichTextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="2*" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<RichTextBlock
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="0"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Bottom">
|
||||||
<Paragraph>
|
<Paragraph>
|
||||||
<Run FontSize="60" FontWeight="Bold">
|
<Run
|
||||||
40
|
x:Name="MinutesText"
|
||||||
</Run>
|
FontSize="60"
|
||||||
<Run FontSize="30" FontWeight="SemiBold">
|
FontWeight="Bold"
|
||||||
:00
|
Text="{x:Bind runningState.MinutesLeft, Mode=OneWay}" />
|
||||||
</Run>
|
<Run
|
||||||
|
x:Name="Separator"
|
||||||
|
FontSize="30"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
Text=":" />
|
||||||
|
<Run
|
||||||
|
x:Name="SecondsText"
|
||||||
|
FontSize="30"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
Text="{x:Bind runningState.SecondsLeft, Mode=OneWay}" />
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
</RichTextBlock>
|
</RichTextBlock>
|
||||||
|
<TextBlock
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.Column="0"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
FontSize="30"
|
||||||
|
FontWeight="Light"
|
||||||
|
Text="{x:Bind runningState.OnRest, Converter={StaticResource BoolToWorkRestConverter}, Mode=OneWay}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid Grid.Row="0" Grid.Column="1">
|
<Grid Grid.Row="0" Grid.Column="1">
|
||||||
<Grid>
|
<Grid>
|
||||||
@@ -49,7 +86,7 @@
|
|||||||
Minimum="0"
|
Minimum="0"
|
||||||
SmallChange="5"
|
SmallChange="5"
|
||||||
SpinButtonPlacementMode="Inline"
|
SpinButtonPlacementMode="Inline"
|
||||||
Value="40" />
|
Value="{x:Bind WorkMinutes, Mode=TwoWay}" />
|
||||||
<controls:NumberBox
|
<controls:NumberBox
|
||||||
x:Name="RestMinutesInput"
|
x:Name="RestMinutesInput"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
@@ -61,7 +98,7 @@
|
|||||||
Minimum="0"
|
Minimum="0"
|
||||||
SmallChange="1"
|
SmallChange="1"
|
||||||
SpinButtonPlacementMode="Inline"
|
SpinButtonPlacementMode="Inline"
|
||||||
Value="5" />
|
Value="{x:Bind RestMinutes, Mode=TwoWay}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -71,20 +108,38 @@
|
|||||||
DefaultLabelPosition="Right"
|
DefaultLabelPosition="Right"
|
||||||
IsOpen="True">
|
IsOpen="True">
|
||||||
<AppBarButton
|
<AppBarButton
|
||||||
|
x:Name="PlayButton"
|
||||||
|
Click="PlayButton_Click"
|
||||||
Icon="Play"
|
Icon="Play"
|
||||||
Label="Start"
|
Label="Start"
|
||||||
Visibility="Visible" />
|
Visibility="{x:Bind runningState.IsRunning, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay, ConverterParameter=True}" />
|
||||||
<AppBarButton
|
<AppBarButton
|
||||||
|
x:Name="PauseButton"
|
||||||
|
Click="PauseButton_Click"
|
||||||
Icon="Pause"
|
Icon="Pause"
|
||||||
Label="Pause"
|
Label="Pause"
|
||||||
Visibility="Collapsed" />
|
Visibility="{x:Bind runningState.IsRunning, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" />
|
||||||
<AppBarButton
|
<AppBarButton
|
||||||
|
x:Name="ResetButton"
|
||||||
|
Click="ResetButton_Click"
|
||||||
Icon="Redo"
|
Icon="Redo"
|
||||||
Label="Reset"
|
Label="Reset"
|
||||||
Visibility="Collapsed" />
|
Visibility="Visible" />
|
||||||
<AppBarButton Icon="Add" Label="+1min" />
|
<AppBarButton
|
||||||
<AppBarButton Icon="Add" Label="+5min" />
|
x:Name="Plus1Button"
|
||||||
<AppBarButton Icon="Add" Label="+10min" />
|
Click="Plus1Button_Click"
|
||||||
|
Icon="Add"
|
||||||
|
Label="+1min" />
|
||||||
|
<AppBarButton
|
||||||
|
x:Name="Plus5Button"
|
||||||
|
Click="Plus5Button_Click"
|
||||||
|
Icon="Add"
|
||||||
|
Label="+5min" />
|
||||||
|
<AppBarButton
|
||||||
|
x:Name="Plus10Button"
|
||||||
|
Click="Plus10Button_Click"
|
||||||
|
Icon="Add"
|
||||||
|
Label="+10min" />
|
||||||
</CommandBar>
|
</CommandBar>
|
||||||
</Page.BottomAppBar>
|
</Page.BottomAppBar>
|
||||||
</Page>
|
</Page>
|
||||||
@@ -8,11 +8,13 @@ using Windows.Foundation.Collections;
|
|||||||
using Windows.UI.ViewManagement;
|
using Windows.UI.ViewManagement;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
using controls = Microsoft.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Controls.Primitives;
|
using Windows.UI.Xaml.Controls.Primitives;
|
||||||
using Windows.UI.Xaml.Data;
|
using Windows.UI.Xaml.Data;
|
||||||
using Windows.UI.Xaml.Input;
|
using Windows.UI.Xaml.Input;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using Windows.UI.Xaml.Navigation;
|
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
|
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
|
||||||
@@ -24,15 +26,138 @@ namespace Pomotimer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class MainPage : Page
|
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()
|
public MainPage()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
|
|
||||||
|
// Some maigc numbers
|
||||||
Size defaultSize = new Size(500, 250);
|
Size defaultSize = new Size(500, 250);
|
||||||
|
|
||||||
ApplicationView.PreferredLaunchViewSize = defaultSize;
|
ApplicationView.PreferredLaunchViewSize = defaultSize;
|
||||||
ApplicationView.GetForCurrentView().SetPreferredMinSize(defaultSize);
|
ApplicationView.GetForCurrentView().SetPreferredMinSize(defaultSize);
|
||||||
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@
|
|||||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="RunningState.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AppxManifest Include="Package.appxmanifest">
|
<AppxManifest Include="Package.appxmanifest">
|
||||||
@@ -153,6 +154,9 @@
|
|||||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||||
<Version>6.2.9</Version>
|
<Version>6.2.9</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
|
||||||
|
<Version>6.0.0</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.UI.Xaml">
|
<PackageReference Include="Microsoft.UI.Xaml">
|
||||||
<Version>2.3.200213001</Version>
|
<Version>2.3.200213001</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
68
Pomotimer/RunningState.cs
Normal file
68
Pomotimer/RunningState.cs
Normal file
@@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user