mirror of
https://github.com/usatiuk/PomoTime.git
synced 2025-10-28 08:27: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:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:Pomotimer">
|
||||
|
||||
<Application.Resources>
|
||||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||
</Application.Resources>
|
||||
|
||||
@@ -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">
|
||||
|
||||
<Page.Resources>
|
||||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<converters:BoolToObjectConverter
|
||||
x:Key="BoolToWorkRestConverter"
|
||||
FalseValue="Work"
|
||||
TrueValue="Rest" />
|
||||
</Page.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -18,16 +27,44 @@
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<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>
|
||||
<Run FontSize="60" FontWeight="Bold">
|
||||
40
|
||||
</Run>
|
||||
<Run FontSize="30" FontWeight="SemiBold">
|
||||
:00
|
||||
</Run>
|
||||
<Run
|
||||
x:Name="MinutesText"
|
||||
FontSize="60"
|
||||
FontWeight="Bold"
|
||||
Text="{x:Bind runningState.MinutesLeft, Mode=OneWay}" />
|
||||
<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>
|
||||
</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.Row="0" Grid.Column="1">
|
||||
<Grid>
|
||||
@@ -49,7 +86,7 @@
|
||||
Minimum="0"
|
||||
SmallChange="5"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Value="40" />
|
||||
Value="{x:Bind WorkMinutes, Mode=TwoWay}" />
|
||||
<controls:NumberBox
|
||||
x:Name="RestMinutesInput"
|
||||
Grid.Row="1"
|
||||
@@ -61,7 +98,7 @@
|
||||
Minimum="0"
|
||||
SmallChange="1"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Value="5" />
|
||||
Value="{x:Bind RestMinutes, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
@@ -71,20 +108,38 @@
|
||||
DefaultLabelPosition="Right"
|
||||
IsOpen="True">
|
||||
<AppBarButton
|
||||
x:Name="PlayButton"
|
||||
Click="PlayButton_Click"
|
||||
Icon="Play"
|
||||
Label="Start"
|
||||
Visibility="Visible" />
|
||||
Visibility="{x:Bind runningState.IsRunning, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay, ConverterParameter=True}" />
|
||||
<AppBarButton
|
||||
x:Name="PauseButton"
|
||||
Click="PauseButton_Click"
|
||||
Icon="Pause"
|
||||
Label="Pause"
|
||||
Visibility="Collapsed" />
|
||||
Visibility="{x:Bind runningState.IsRunning, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" />
|
||||
<AppBarButton
|
||||
x:Name="ResetButton"
|
||||
Click="ResetButton_Click"
|
||||
Icon="Redo"
|
||||
Label="Reset"
|
||||
Visibility="Collapsed" />
|
||||
<AppBarButton Icon="Add" Label="+1min" />
|
||||
<AppBarButton Icon="Add" Label="+5min" />
|
||||
<AppBarButton Icon="Add" Label="+10min" />
|
||||
Visibility="Visible" />
|
||||
<AppBarButton
|
||||
x:Name="Plus1Button"
|
||||
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>
|
||||
</Page.BottomAppBar>
|
||||
</Page>
|
||||
@@ -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
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,7 @@
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RunningState.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
@@ -153,6 +154,9 @@
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
<Version>6.2.9</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
|
||||
<Version>6.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.UI.Xaml">
|
||||
<Version>2.3.200213001</Version>
|
||||
</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