Skip to content

Commit aaf8059

Browse files
committed
Implemented docking notifications and notification manager interface
1 parent 208ff06 commit aaf8059

File tree

4 files changed

+52
-30
lines changed

4 files changed

+52
-30
lines changed

CutCode/Interfaces/INotificationManager.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Stylet;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -22,9 +23,10 @@ public void CreateNotification(string message, int delay)
2223
}
2324
}
2425

25-
public class NotifyModel
26+
public class NotifyModel : PropertyChangedBase
2627
{
2728
public string Message { get; set; }
2829
public int Delay { get; set; }
30+
public Object View { get; set; }
2931
}
3032
}

CutCode/ViewModels/MainViewModel.cs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public MainViewModel(IWindowManager _windowManager,IThemeService themeService, I
3333

3434
notifyManager = _notifyManager;
3535
notifyManager.ShowNotification += showNotification;
36+
notificationList = new ObservableCollection<NotifyModel>();
3637

3738
_themeService = themeService;
3839
_themeService.ThemeChanged += ThemeChanged;
@@ -102,12 +103,14 @@ public void ChangePageCommand(string selected_item)
102103
sideBarBtns[ind].background = _themeService.IsLightTheme ? ColorCon.Convert("#FCFCFC") : ColorCon.Convert("#36393F");
103104
if (currentPage != Pages[ind]) pageService.Page = Pages[ind];
104105

106+
105107
if(selected_item == "Share")
106108
{
107-
notifyManager.CreateNotification("This is just for test", 6);
109+
notifyManager.CreateNotification($"{k} : This is just for test", 5);
110+
k++;
108111
}
109112
}
110-
113+
private int k = 1;
111114
#region Color
112115
private SolidColorBrush _backgroundColor;
113116
public SolidColorBrush backgroundColor
@@ -200,38 +203,48 @@ public string minImage
200203
}
201204

202205
#region NotificationDialogView
203-
private Object _notificationDialogView;
204-
public Object notificationDialogView
205-
{
206-
get => _notificationDialogView;
207-
set => SetAndNotify(ref _notificationDialogView, value);
208-
}
209-
210-
private Visibility _notifcationDialogVisibility;
211-
public Visibility notifcationDialogVisibility
206+
private ObservableCollection<NotifyModel> _notificationList;
207+
public ObservableCollection<NotifyModel> notificationList
212208
{
213-
get => _notifcationDialogVisibility;
214-
set => SetAndNotify(ref _notifcationDialogVisibility, value);
209+
get => _notificationList;
210+
set => SetAndNotify(ref _notificationList, value);
215211
}
216212

213+
private List<NotifyModel> WaitingNotifications = new List<NotifyModel>();
217214
private void showNotification(object sender, EventArgs e)
218215
{
219-
var noitification = sender as NotifyModel;
216+
var notification = sender as NotifyModel;
220217

221-
var notifcationViewModel = new NotificationDialogViewModel(_themeService, noitification.Message);
222-
notificationDialogView = (Object)notifcationViewModel;
218+
var notifcationViewModel = new NotificationDialogViewModel(_themeService, notification.Message);
219+
notification.View = (Object)notifcationViewModel;
223220

224-
notifcationDialogVisibility = Visibility.Visible;
225-
var closeTimer = new DispatcherTimer
221+
if(notificationList.Count > 2)
226222
{
227-
Interval = TimeSpan.FromSeconds(noitification.Delay),
228-
IsEnabled = true
229-
};
230-
closeTimer.Tick += (object sender, EventArgs e) =>
223+
WaitingNotifications.Add(notification);
224+
}
225+
else
231226
{
232-
notifcationDialogVisibility = Visibility.Hidden;
233-
closeTimer.Stop();
234-
};
227+
notificationList.Add(notification);
228+
229+
var closeTimer = new DispatcherTimer
230+
{
231+
Interval = TimeSpan.FromSeconds(notification.Delay),
232+
IsEnabled = true
233+
};
234+
closeTimer.Tick += CloseNotification;
235+
}
236+
}
237+
238+
private void CloseNotification(object sender, EventArgs e)
239+
{
240+
notificationList.RemoveAt(0);
241+
if (WaitingNotifications.Count != 0)
242+
{
243+
var notification = WaitingNotifications[0];
244+
WaitingNotifications.RemoveAt(0);
245+
notifyManager.CreateNotification(notification.Message, notification.Delay);
246+
}
247+
(sender as DispatcherTimer).Stop();
235248
}
236249
#endregion
237250
}

CutCode/Views/MainView.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,15 @@
153153
</Grid>
154154

155155
<Grid Grid.Row="1">
156-
<ContentControl Visibility="{Binding notifcationDialogVisibility}" HorizontalAlignment="Right" VerticalAlignment="Bottom"
157-
s:View.Model="{Binding notificationDialogView, UpdateSourceTrigger=PropertyChanged}"/>
156+
<ItemsControl Background="Transparent"
157+
ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
158+
HorizontalAlignment="Right" VerticalAlignment="Bottom" ItemsSource="{Binding notificationList}">
159+
<ItemsControl.ItemTemplate>
160+
<DataTemplate>
161+
<ContentControl s:View.Model="{Binding View, UpdateSourceTrigger=PropertyChanged}"/>
162+
</DataTemplate>
163+
</ItemsControl.ItemTemplate>
164+
</ItemsControl>
158165
</Grid>
159166

160167
</Grid>

CutCode/Views/NotificationDialogView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
mc:Ignorable="d"
99
d:DataContext="{d:DesignInstance local:NotificationDialogViewModel}"
1010
UseLayoutRounding="True"
11-
Padding="10">
11+
Padding="5">
1212

1313
<UserControl.Resources>
1414
<Style x:Key="ButtonStyle" TargetType="Button">

0 commit comments

Comments
 (0)