Skip to content

Commit

Permalink
Showing the time left in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ironjan committed Apr 17, 2017
1 parent ef22785 commit 4f8777c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
-

## [0.0.3]
- Display the time left

## [0.0.2]
- Added basic UI elements for workflow (start working, start break)
- Added MVP workflow: toggle working and pause
Expand Down
21 changes: 11 additions & 10 deletions MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ namespace InteractiveOfficeClient
{
public class MainWindow : Gtk.Window
{
private readonly Grid Grid = new Grid();
private readonly Button BtnStartWorking = new Button("Start Working");
private readonly Button BtnStartBreak = new Button("Start Break");
private readonly Grid Grid = new Grid();
private readonly Label LabelTimeLeft = new Label("");


private bool IsWorking = false;

private enum TimerState {Created, Running, Paused};
Expand All @@ -19,17 +22,15 @@ private enum TimerState {Created, Running, Paused};
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")
{
Add(Grid);
Grid.Attach(BtnStartWorking, 0, 0, 1, 1);
Grid.Attach(BtnStartBreak, 0, 1, 1, 1);
Grid.Attach(LabelTimeLeft, 0, 0, 1, 1);
Grid.AttachNextTo(BtnStartWorking, LabelTimeLeft, PositionType.Bottom, 1, 1);
Grid.AttachNextTo(BtnStartBreak, BtnStartWorking, PositionType.Bottom, 1, 1);

DeleteEvent += delegate { Visible = false; };
DeleteEvent += delegate { Iconify(); };

BtnStartWorking.Clicked += delegate {
SetWorkingState(true);
Expand All @@ -38,7 +39,7 @@ public MainWindow() : base("Interactive Office Project")

ShowAll();

Callback = new TimerCallback(OnTimerCallback);
new System.Threading.Timer(new TimerCallback(OnTimerCallback), "", TimeSpan.Zero, TimeSpan.FromSeconds(1));
}

private void OnTimerCallback(object state)
Expand All @@ -47,7 +48,9 @@ private void OnTimerCallback(object state)
if (TimeLeft <= 0)
{
Visible = true;
TimeLeft = 0;
}
LabelTimeLeft.Text = $"Time Left: {TimeLeft}s";
}

private void SetWorkingState(bool newState)
Expand All @@ -59,8 +62,6 @@ private void SetWorkingState(bool newState)
else
TimeLeft = INTERVAL_5_MIN_AS_SECONDS;

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

UpdateUi();
Visible = false;
}
Expand All @@ -69,7 +70,7 @@ private void UpdateUi()
{
BtnStartWorking.Sensitive = !IsWorking;
BtnStartBreak.Sensitive = IsWorking;
}
}

protected override bool OnVisibilityNotifyEvent(EventVisibility evnt)
{
Expand Down

0 comments on commit 4f8777c

Please sign in to comment.