mirror of
https://github.com/usatiuk/PomoTime.git
synced 2025-10-28 08:27:48 +01:00
long/short breaks
This commit is contained in:
@@ -13,10 +13,7 @@
|
||||
<Page.Resources>
|
||||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<converters:FormatStringConverter x:Key="FormatStringConverter" />
|
||||
<converters:BoolToObjectConverter
|
||||
x:Key="BoolToWorkRestConverter"
|
||||
FalseValue="Work"
|
||||
TrueValue="Rest" />
|
||||
<local:PeriodToStringConverter x:Key="PeriodToStringConverter" />
|
||||
</Page.Resources>
|
||||
|
||||
<Grid>
|
||||
@@ -65,13 +62,14 @@
|
||||
VerticalAlignment="Top"
|
||||
FontSize="30"
|
||||
FontWeight="Light"
|
||||
Text="{x:Bind runningState.OnRest, Converter={StaticResource BoolToWorkRestConverter}, Mode=OneWay}" />
|
||||
Text="{x:Bind runningState.CurrentPeriod, Converter={StaticResource PeriodToStringConverter}, Mode=OneWay}" />
|
||||
</Grid>
|
||||
<Grid Grid.Row="0" Grid.Column="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -89,17 +87,29 @@
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Value="{x:Bind WorkMinutes, Mode=TwoWay}" />
|
||||
<controls:NumberBox
|
||||
x:Name="RestMinutesInput"
|
||||
x:Name="BreakMinutesInput"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Header="Rest time:"
|
||||
Header="Break time:"
|
||||
LargeChange="5"
|
||||
Minimum="0"
|
||||
SmallChange="1"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Value="{x:Bind RestMinutes, Mode=TwoWay}" />
|
||||
Value="{x:Bind BreakMinutes, Mode=TwoWay}" />
|
||||
<controls:NumberBox
|
||||
x:Name="LongBreakMinutesInput"
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Header="Long break time:"
|
||||
LargeChange="15"
|
||||
Minimum="0"
|
||||
SmallChange="5"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Value="{x:Bind LongBreakMinutes, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -15,6 +15,8 @@ using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using Windows.Storage;
|
||||
using Windows.System.Threading;
|
||||
using Windows.UI.Core;
|
||||
|
||||
|
||||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
|
||||
@@ -26,11 +28,16 @@ namespace PomoTime
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
private DispatcherTimer dispatcherTimer;
|
||||
public RunningState runningState = new RunningState();
|
||||
private const int DefaultBreakMinutes = 5;
|
||||
private const int DefaultWorkMinutes = 25;
|
||||
private const int DefaultLongBreakMinutes = 15;
|
||||
|
||||
private int RestMinutes { get; set; }
|
||||
|
||||
private int BreakMinutes { get; set; }
|
||||
private int WorkMinutes { get; set; }
|
||||
private int LongBreakMinutes { get; set; }
|
||||
|
||||
|
||||
public MainPage()
|
||||
{
|
||||
@@ -50,44 +57,84 @@ namespace PomoTime
|
||||
Windows.Storage.ApplicationDataCompositeValue minutes = (ApplicationDataCompositeValue)roamingSettings.Values["Minutes"];
|
||||
if (minutes != null)
|
||||
{
|
||||
WorkMinutes = (int)minutes["WorkMinutes"];
|
||||
RestMinutes = (int)minutes["RestMinutes"];
|
||||
if (minutes["WorkMinutes"] != null)
|
||||
{
|
||||
WorkMinutes = (int)minutes["WorkMinutes"];
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkMinutes = DefaultWorkMinutes;
|
||||
}
|
||||
if (minutes["BreakMinutes"] != null)
|
||||
{
|
||||
BreakMinutes = (int)minutes["BreakMinutes"];
|
||||
}
|
||||
else
|
||||
{
|
||||
BreakMinutes = DefaultBreakMinutes;
|
||||
}
|
||||
if (minutes["LongBreakMinutes"] != null)
|
||||
{
|
||||
LongBreakMinutes = (int)minutes["LongBreakMinutes"];
|
||||
}
|
||||
else
|
||||
{
|
||||
LongBreakMinutes = DefaultLongBreakMinutes;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Some maigc defualt numbers
|
||||
WorkMinutes = 40;
|
||||
RestMinutes = 5;
|
||||
WorkMinutes = DefaultWorkMinutes;
|
||||
BreakMinutes = DefaultBreakMinutes;
|
||||
LongBreakMinutes = DefaultLongBreakMinutes;
|
||||
}
|
||||
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)
|
||||
void timer_Tick()
|
||||
{
|
||||
if (!runningState.IsRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (runningState.SecondsLeft == 0)
|
||||
{
|
||||
runningState.SecondsLeft = 59;
|
||||
if (runningState.MinutesLeft == 0)
|
||||
{
|
||||
if (runningState.OnRest)
|
||||
switch (runningState.CurrentPeriod)
|
||||
{
|
||||
runningState.OnRest = false;
|
||||
runningState.MinutesLeft = WorkMinutes;
|
||||
runningState.SecondsLeft = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
runningState.OnRest = true;
|
||||
runningState.MinutesLeft = RestMinutes;
|
||||
runningState.SecondsLeft = 0;
|
||||
case Period.Work:
|
||||
if (runningState.PreviousShortBreaks != 4)
|
||||
{
|
||||
runningState.CurrentPeriod = Period.ShortBreak;
|
||||
runningState.MinutesLeft = BreakMinutes;
|
||||
}
|
||||
else
|
||||
{
|
||||
runningState.CurrentPeriod = Period.LongBreak;
|
||||
runningState.MinutesLeft = LongBreakMinutes;
|
||||
}
|
||||
runningState.SecondsLeft = 0;
|
||||
|
||||
break;
|
||||
case Period.ShortBreak:
|
||||
runningState.CurrentPeriod = Period.Work;
|
||||
runningState.PreviousShortBreaks += 1;
|
||||
runningState.MinutesLeft = WorkMinutes;
|
||||
runningState.SecondsLeft = 0;
|
||||
break;
|
||||
case Period.LongBreak:
|
||||
runningState.CurrentPeriod = Period.Work;
|
||||
runningState.PreviousShortBreaks = 0;
|
||||
runningState.MinutesLeft = WorkMinutes;
|
||||
runningState.SecondsLeft = 0;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -105,24 +152,21 @@ namespace PomoTime
|
||||
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.CurrentPeriod = Period.Work;
|
||||
runningState.MinutesLeft = WorkMinutes;
|
||||
runningState.SecondsLeft = 0;
|
||||
}
|
||||
@@ -150,14 +194,22 @@ namespace PomoTime
|
||||
ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
|
||||
Windows.Storage.ApplicationDataCompositeValue minutes = new Windows.Storage.ApplicationDataCompositeValue();
|
||||
minutes["WorkMinutes"] = WorkMinutes;
|
||||
minutes["RestMinutes"] = RestMinutes;
|
||||
minutes["BreakMinutes"] = BreakMinutes;
|
||||
minutes["LongBreakMinutes"] = LongBreakMinutes;
|
||||
roamingSettings.Values["Minutes"] = minutes;
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
private void MainPageLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DispatcherTimerSetup();
|
||||
ThreadPoolTimer timer = ThreadPoolTimer.CreatePeriodicTimer(async (t) =>
|
||||
{
|
||||
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
|
||||
() =>
|
||||
{
|
||||
timer_Tick();
|
||||
});
|
||||
}, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,11 @@
|
||||
DisplayName="PomoTime"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png"
|
||||
Description="PomoTime"
|
||||
Description="A qute little pomodoro technique timer, which does exactly what you think it does - counts (by default) 40 minutes of work time and then 5 minutes of rest time. And repeats until you stop it."
|
||||
BackgroundColor="transparent">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" Square71x71Logo="Assets\SmallTile.png" Square310x310Logo="Assets\LargeTile.png"/>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" />
|
||||
<uap:LockScreen BadgeLogo="Assets\BadgeLogo.png" Notification="badge"/>
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
53
PomoTime/PeriodToStringConverter.cs
Normal file
53
PomoTime/PeriodToStringConverter.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Xaml.Data;
|
||||
|
||||
namespace PomoTime
|
||||
{
|
||||
public class PeriodToStringConverter : 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.
|
||||
Period period = (Period)value;
|
||||
string output;
|
||||
switch (period)
|
||||
{
|
||||
case Period.LongBreak:
|
||||
output = "Long break";
|
||||
break;
|
||||
case Period.ShortBreak:
|
||||
output = "Short break";
|
||||
break;
|
||||
case Period.Work:
|
||||
output = "Work";
|
||||
break;
|
||||
default:
|
||||
output = "Something wrong";
|
||||
break;
|
||||
}
|
||||
|
||||
// Return the month value to pass to the target.
|
||||
return output;
|
||||
}
|
||||
|
||||
// ConvertBack is not implemented for a OneWay binding.
|
||||
public object ConvertBack(object value, Type targetType,
|
||||
object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -122,6 +122,7 @@
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="PeriodToStringConverter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RunningState.cs" />
|
||||
</ItemGroup>
|
||||
@@ -131,13 +132,62 @@
|
||||
</AppxManifest>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\BadgeLogo.scale-100.png" />
|
||||
<Content Include="Assets\BadgeLogo.scale-125.png" />
|
||||
<Content Include="Assets\BadgeLogo.scale-150.png" />
|
||||
<Content Include="Assets\BadgeLogo.scale-200.png" />
|
||||
<Content Include="Assets\BadgeLogo.scale-400.png" />
|
||||
<Content Include="Assets\LargeTile.scale-100.png" />
|
||||
<Content Include="Assets\LargeTile.scale-125.png" />
|
||||
<Content Include="Assets\LargeTile.scale-150.png" />
|
||||
<Content Include="Assets\LargeTile.scale-200.png" />
|
||||
<Content Include="Assets\LargeTile.scale-400.png" />
|
||||
<Content Include="Assets\SmallTile.scale-100.png" />
|
||||
<Content Include="Assets\SmallTile.scale-125.png" />
|
||||
<Content Include="Assets\SmallTile.scale-150.png" />
|
||||
<Content Include="Assets\SmallTile.scale-200.png" />
|
||||
<Content Include="Assets\SmallTile.scale-400.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-100.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-125.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-150.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-400.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-100.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-125.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-150.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-400.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-lightunplated_targetsize-16.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-lightunplated_targetsize-24.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-lightunplated_targetsize-256.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-lightunplated_targetsize-32.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-lightunplated_targetsize-48.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-unplated_targetsize-16.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-unplated_targetsize-256.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-unplated_targetsize-32.png" />
|
||||
<Content Include="Assets\Square44x44Logo.altform-unplated_targetsize-48.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-100.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-125.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-150.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-400.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-16.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-256.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-32.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-48.png" />
|
||||
<Content Include="Assets\StoreLogo.scale-100.png" />
|
||||
<Content Include="Assets\StoreLogo.scale-125.png" />
|
||||
<Content Include="Assets\StoreLogo.scale-150.png" />
|
||||
<Content Include="Assets\StoreLogo.scale-200.png" />
|
||||
<Content Include="Assets\StoreLogo.scale-400.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-100.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-125.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-150.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-400.png" />
|
||||
<Content Include="Properties\Default.rd.xml" />
|
||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\StoreLogo.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -152,7 +202,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
<Version>6.2.9</Version>
|
||||
<Version>6.2.10</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
|
||||
<Version>6.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
|
||||
<Version>6.0.0</Version>
|
||||
|
||||
@@ -8,6 +8,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace PomoTime
|
||||
{
|
||||
public enum Period
|
||||
{
|
||||
Work, ShortBreak, LongBreak
|
||||
}
|
||||
public class RunningState : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
@@ -52,17 +56,31 @@ namespace PomoTime
|
||||
|
||||
}
|
||||
|
||||
public bool _on_rest;
|
||||
public Period _period;
|
||||
|
||||
public bool OnRest
|
||||
public Period CurrentPeriod
|
||||
{
|
||||
get { return _on_rest; }
|
||||
get { return _period; }
|
||||
set
|
||||
{
|
||||
_on_rest = value;
|
||||
NotifyPropertyChanged("OnRest");
|
||||
_period = value;
|
||||
NotifyPropertyChanged("CurrentPeriod");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int _previous_short_breaks;
|
||||
|
||||
public int PreviousShortBreaks
|
||||
{
|
||||
get { return _previous_short_breaks; }
|
||||
set
|
||||
{
|
||||
_previous_short_breaks = value;
|
||||
NotifyPropertyChanged("PreviousShortBreaks");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user