Skip to content

Commit

Permalink
MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
ironjan committed Apr 17, 2017
1 parent 63e7332 commit 7dfbf38
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- Added basic UI elements for workflow (start working, start break)

- Added MVP workflow: toggle working and pause

## [0.0.1]

Expand Down
35 changes: 34 additions & 1 deletion MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using Gdk;
using Gtk;

Expand All @@ -11,6 +12,15 @@ public class MainWindow : Gtk.Window
private readonly Grid Grid = new Grid();
private bool IsWorking = false;

private enum TimerState {Created, Running, Paused};

private static readonly int INTERVAL_1_SECOND_AS_MILLIS = 1000;
private static readonly int INTERVAL_5_MIN_AS_SECONDS = 5*60;
private static readonly int INTERVAL_25_MIN_AS_SECONDS = 5*INTERVAL_5_MIN_AS_SECONDS;

private int TimeLeft = 0;
private TimerCallback Callback;
private Timer Timer;

public MainWindow() : base("Interactive Office Project")
{
Expand All @@ -21,16 +31,38 @@ public MainWindow() : base("Interactive Office Project")

DeleteEvent += delegate { Visible = false; };

BtnStartWorking.Clicked += delegate { SetWorkingState(true); };
BtnStartWorking.Clicked += delegate {
SetWorkingState(true);
};
BtnStartBreak.Clicked += delegate { SetWorkingState(false); };

ShowAll();

Callback = new TimerCallback(OnTimerCallback);
}

private void OnTimerCallback(object state)
{
TimeLeft = TimeLeft - 1;
if (TimeLeft <= 0)
{
Visible = true;
}
}

private void SetWorkingState(bool newState)
{
IsWorking = newState;

if (IsWorking)
TimeLeft = INTERVAL_25_MIN_AS_SECONDS;
else
TimeLeft = INTERVAL_5_MIN_AS_SECONDS;

Timer = new System.Threading.Timer(Callback, "", int.MaxValue, INTERVAL_1_SECOND_AS_MILLIS);

UpdateUi();
Visible = false;
}

private void UpdateUi()
Expand All @@ -45,5 +77,6 @@ protected override bool OnVisibilityNotifyEvent(EventVisibility evnt)
UpdateUi();
return baseResult;
}

}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Add them to the project, place them in the Resources folder, and set them to

* [x] Add "minimize to tray" to keep the app running when window is closed. Useful links:
* http://www.mono-project.com/docs/gui/gtksharp/widgets/notification-icon/
* [ ] Add the simplified tracking work-flow: ["start working"] -(30min)-> ["start break"] -(10min)-> ["start working"] ...
* [x] Add the simplified tracking work-flow: ["start working"] -(30min)-> ["start break"] -(5min)-> ["start working"] ...
* Most minimal application
* App gets invisible on starting something, visible when it's done
* [ ] Add "start on boot"
* No research done yet
* [ ] Then extend according to https://drive.google.com/drive/folders/0B6Tl_UdBt6QYWUtTSExzQ2toOHc ?
Expand Down

0 comments on commit 7dfbf38

Please sign in to comment.