Skip to content

Commit

Permalink
Showing default activities for break
Browse files Browse the repository at this point in the history
  • Loading branch information
ironjan committed Apr 26, 2017
1 parent 7365ce2 commit 99edc53
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 19 deletions.
60 changes: 60 additions & 0 deletions ActivityWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Threading.Tasks;
using Gtk;
using InteractiveOfficeClient.Models;

namespace InteractiveOfficeClient
{
public class ActivityWindow : Gtk.Window
{
private InteractiveOfficeClient _app;
private readonly Grid _grid = new Grid();

public ActivityWindow(InteractiveOfficeClient interactiveOfficeClient) : base("Break Time")
{
this._app = interactiveOfficeClient;
Add(_grid);
ShowLoading(true);
var activities = Activity.DefaultActivities;

for (int i = 0; i < activities.Length; i++)
{
var activity = activities[i];

Button b = new ActivityButton(activity);
b.Clicked += delegate { ActivitySelected(activity); };

_grid.Attach(b, 0, i, 1, 1);
}
ShowLoading(false);
}

private void ActivitySelected(Activity activity)
{
Console.WriteLine($"Selected {activity}");
_app.State = AppState.Break;
Close();
}

private void ShowLoading(bool isLoading)
{
Console.WriteLine($"IsLoading: {isLoading}");
}

}

class ActivityButton: Gtk.Button
{
public ActivityButton(Activity a)
{
if (a.MaximumUsers > 0)
{
Label = $"{a.Name} ({a.MaximumUsers})";
}
else
{
Label = $"{a.Name}";
}
}
}
}
6 changes: 3 additions & 3 deletions ApplicationTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ private void ResetTimer()
private static readonly TimeSpan TimeSpanTickInterval = TimeSpan.FromSeconds(1);

#if DEBUG
private static readonly int IntervalMinute = 1;
private static readonly double IntervalMinute = 0.3;
#else
private static readonly int IntervalMinute = 60;
private static readonly double IntervalMinute = 60.0;
#endif

private static readonly int Interval5MinAsSeconds = 5 * IntervalMinute;
private static readonly int Interval5MinAsSeconds = (int) (5 * IntervalMinute);
private static readonly int Interval25MinAsSeconds = 5 * Interval5MinAsSeconds;

private int _timeLeft = 0;
Expand Down
31 changes: 20 additions & 11 deletions InteractiveOfficeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ public AppState State
get { return _appState; }
set
{
Console.WriteLine($"new state: {value}");
_appState = value;
_applicationTimer.ChangeState(value);
mainWindow.UpdateUi();
Gtk.Application.Invoke(delegate {
Console.WriteLine($"new state: {value}");
_appState = value;
_applicationTimer.ChangeState(value);
mainWindow.UpdateUi();
});

}
}
private InteractiveOfficeClient()
Expand Down Expand Up @@ -79,14 +82,20 @@ public void Show()

public void TriggerNotification()
{
if (IsWorking)
Gtk.Application.Invoke(delegate
{
State = AppState.NotifyingBreak;
}
else
{
State = AppState.NotifyingWork;
}
if (IsWorking)
{
State = AppState.NotifyingBreak;
Console.WriteLine("Show Activities");
ActivityWindow aw = new ActivityWindow(this);
aw.ShowAll();
}
else
{
State = AppState.NotifyingWork;
}
});
}
}
}
1 change: 1 addition & 0 deletions InteractiveOfficeClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="ActivityWindow.cs" />
<Compile Include="InteractiveOfficeClient.cs" />
<Compile Include="IopTrayIcon.cs" />
<Compile Include="MainWindow.cs" />
Expand Down
2 changes: 2 additions & 0 deletions MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public MainWindow(InteractiveOfficeClient interactiveOfficeClient) : base("Inter
_btnStartWorking.Clicked += delegate
{
_app.State = AppState.Working;
Close();
};
_btnStartBreak.Clicked += delegate
{
_app.State = AppState.Break;
Close();
};

ShowAll();
Expand Down
13 changes: 9 additions & 4 deletions Models/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
public class Activity
{
readonly int ActivityID;
readonly string Name;
private readonly int MaximumUsers;
public readonly int ActivityID;
public readonly string Name;
public readonly int MaximumUsers;

Activity[] DefaultActivities = new Activity[]
public static readonly Activity[] DefaultActivities = new Activity[]
{
new Activity(-1, "Coffee Break", 0),
new Activity(-2, "Walking", 0),
Expand All @@ -20,5 +20,10 @@ public Activity(int activityId, string name, int maximumUsers)
Name = name;
MaximumUsers = maximumUsers;
}

public override string ToString()
{
return $"[{ActivityID} - {Name} ({MaximumUsers})]";
}
}
}
2 changes: 1 addition & 1 deletion build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fi
TAG=$1
git checkout $TAG
xbuild /p:Configuration=Release InteractiveOfficeClient.sln
7za InteractiveOfficeClient-$TAG.exe bin/Release/
7za a InteractiveOfficeClient-$TAG.7z bin/Release/

0 comments on commit 99edc53

Please sign in to comment.