From 99edc53902ef34f08c8557f8bc4817f6f6f55894 Mon Sep 17 00:00:00 2001 From: Jan Lippert Date: Wed, 26 Apr 2017 15:44:58 +0300 Subject: [PATCH] Showing default activities for break --- ActivityWindow.cs | 60 ++++++++++++++++++++++++++++++++++ ApplicationTimer.cs | 6 ++-- InteractiveOfficeClient.cs | 31 +++++++++++------- InteractiveOfficeClient.csproj | 1 + MainWindow.cs | 2 ++ Models/Activity.cs | 13 +++++--- build-release.sh | 2 +- 7 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 ActivityWindow.cs diff --git a/ActivityWindow.cs b/ActivityWindow.cs new file mode 100644 index 0000000..8738454 --- /dev/null +++ b/ActivityWindow.cs @@ -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}"; + } + } + } +} \ No newline at end of file diff --git a/ApplicationTimer.cs b/ApplicationTimer.cs index f4411c9..8f415ba 100644 --- a/ApplicationTimer.cs +++ b/ApplicationTimer.cs @@ -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; diff --git a/InteractiveOfficeClient.cs b/InteractiveOfficeClient.cs index e800cdc..9204f86 100644 --- a/InteractiveOfficeClient.cs +++ b/InteractiveOfficeClient.cs @@ -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() @@ -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; + } + }); } } } \ No newline at end of file diff --git a/InteractiveOfficeClient.csproj b/InteractiveOfficeClient.csproj index c3c246f..ea8b160 100644 --- a/InteractiveOfficeClient.csproj +++ b/InteractiveOfficeClient.csproj @@ -33,6 +33,7 @@ 4 + diff --git a/MainWindow.cs b/MainWindow.cs index 5c79d4b..c1c9c3c 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -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(); diff --git a/Models/Activity.cs b/Models/Activity.cs index ce0148e..09436a2 100644 --- a/Models/Activity.cs +++ b/Models/Activity.cs @@ -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), @@ -20,5 +20,10 @@ public Activity(int activityId, string name, int maximumUsers) Name = name; MaximumUsers = maximumUsers; } + + public override string ToString() + { + return $"[{ActivityID} - {Name} ({MaximumUsers})]"; + } } } \ No newline at end of file diff --git a/build-release.sh b/build-release.sh index bea726e..64f9efd 100755 --- a/build-release.sh +++ b/build-release.sh @@ -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/