-
Notifications
You must be signed in to change notification settings - Fork 2
/
NotificationHandler.cs
305 lines (297 loc) · 12.9 KB
/
NotificationHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
using MahApps.Metro.IconPacks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Windows;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Automation;
using System.Windows.Shapes;
namespace sShell
{
public enum NotificationType : byte
{
/// <summary>
/// Display a default notification.
/// </summary>
Default = 0,
/// <summary>
/// Display a warning notification.
/// </summary>
Warning = 1,
/// <summary>
/// Display an error notification.
/// </summary>
Error = 2,
/// <summary>
/// Display an information notification.
/// </summary>
Information = 3
}
public enum NotificationButtons : byte
{
NoButtons = 0,
OneButton = 1,
TwoButtons = 2
}
public struct Notification
{
public NotificationType Type;
public string Title;
public string Description;
// public NotificationButtons Buttons;
}
public class NotificationHandler
{
MainWindow mw;
public void setMW(MainWindow mw)
{
this.mw = mw;
}
public bool ShowNotification(Notification notif)
{
// Check notification count and display it in the corner
int count = mw.notifBox.Children.Count + 1; // +1 because this is the notification we are adding
if (count > 8)
{
mw.NotifAmountText.Text = "9+";
mw.NotifAmount.Visibility = Visibility.Visible;
}
else if (count == 0)
{
mw.NotifAmount.Visibility = Visibility.Hidden;
}
else
{
mw.NotifAmountText.Text = count.ToString();
mw.NotifAmount.Visibility = Visibility.Visible;
}
// Display the notification in the Quick Actions menu
Border qaNotif = new()
{
Style = mw.FindResource("TBitemPanelBdr") as Style,
Margin = new Thickness(0, 3, 0, 0),
Padding = new Thickness(20),
CornerRadius = new CornerRadius(3)
};
DockPanel qaPanel = new();
PackIconMaterialDesign qaIcon = new();
switch (notif.Type)
{
case NotificationType.Default:
qaIcon = new()
{
VerticalAlignment = VerticalAlignment.Center,
Kind = PackIconMaterialDesignKind.Notifications,
Foreground = mw.FindResource("bgPrimary") as System.Windows.Media.Brush,
Width = 30,
Height = 30,
HorizontalAlignment = HorizontalAlignment.Left
};
break;
case NotificationType.Error:
qaIcon = new()
{
VerticalAlignment = VerticalAlignment.Center,
Kind = PackIconMaterialDesignKind.Error,
Foreground = mw.FindResource("bgDanger") as System.Windows.Media.Brush,
Width = 30,
Height = 30,
HorizontalAlignment = HorizontalAlignment.Left
};
break;
case NotificationType.Warning:
qaIcon = new()
{
VerticalAlignment = VerticalAlignment.Center,
Kind = PackIconMaterialDesignKind.Warning,
Foreground = mw.FindResource("bgWarning") as System.Windows.Media.Brush,
Width = 30,
Height = 30,
HorizontalAlignment = HorizontalAlignment.Left
};
break;
case NotificationType.Information:
qaIcon = new()
{
VerticalAlignment = VerticalAlignment.Center,
Kind = PackIconMaterialDesignKind.Warning,
Foreground = mw.FindResource("bgInfo") as System.Windows.Media.Brush,
Width = 30,
Height = 30,
HorizontalAlignment = HorizontalAlignment.Left
};
break;
}
/*
<Border Style="{DynamicResource TBitemPanelBdr}" Margin="0,3,0,0" Width="275" Padding="20" CornerRadius="3">
<DockPanel>
<iconPacks:PackIconMaterialDesign
VerticalAlignment="Center" Kind="Notifications" Foreground="{DynamicResource bgPrimary}" Width="30" Height="30" HorizontalAlignment="Left" />
<StackPanel Margin="10,0,0,0">
<TextBlock Foreground="{DynamicResource FG}" HorizontalAlignment="Left" Text="Notification" FontSize="18" />
<TextBlock Foreground="{DynamicResource FG}" HorizontalAlignment="Left" Text="Hello" FontSize="13" />
</StackPanel>
</DockPanel>
</Border>
*/
StackPanel qaStack = new()
{
Margin = new Thickness(10, 0, 0, 0)
};
TextBlock qaTitle = new()
{
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
Text = notif.Title,
HorizontalAlignment = HorizontalAlignment.Left,
FontSize = 18
};
TextBlock qaDesc = new()
{
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
Text = notif.Description,
HorizontalAlignment = HorizontalAlignment.Left,
FontSize = 13
};
qaNotif.Child = qaPanel;
qaPanel.Children.Add(qaIcon);
qaStack.Children.Add(qaTitle);
qaStack.Children.Add(qaDesc);
qaPanel.Children.Add(qaStack);
mw.qaStackParent.Children.Add(qaNotif);
// Display the notification in the bottom right corner
switch (notif.Type)
{
case NotificationType.Default:
/*
<Border Style="{DynamicResource Notification}" Margin="0,3,0,0" Width="275" Background="{DynamicResource bgPrimary}" Padding="20" CornerRadius="3">
<DockPanel>
<iconPacks:PackIconMaterialDesign VerticalAlignment="Center" Kind="Notifications" Foreground="White" Width="30" Height="30" HorizontalAlignment="Left" />
<StackPanel Margin="10,0,0,0">
<TextBlock Foreground="{DynamicResource FG}" HorizontalAlignment="Left" Text="Notification" FontSize="18" />
<TextBlock Foreground="{DynamicResource FG}" HorizontalAlignment="Left" Text="Hello" FontSize="13" />
</StackPanel>
</DockPanel>
</Border>
*/
Border Defbdr = new()
{
Margin = new Thickness(0, 3, 0, 0),
Background = mw.FindResource("bgPrimary") as System.Windows.Media.Brush,
Padding = new Thickness(20),
CornerRadius = new CornerRadius(3),
Style = mw.FindResource("Notification") as Style,
HorizontalAlignment = HorizontalAlignment.Right,
MinWidth = 400,
MinHeight = 100
};
DockPanel Defpanel = new();
PackIconMaterialDesign Deficon = new()
{
VerticalAlignment = VerticalAlignment.Center,
Kind = PackIconMaterialDesignKind.Notifications,
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
Width = 30,
Height = 30,
HorizontalAlignment = HorizontalAlignment.Left
};
StackPanel Defsp = new()
{
Margin = new Thickness(10, 0, 0, 0)
};
TextBlock Deftitle = new()
{
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
HorizontalAlignment = HorizontalAlignment.Left,
Text = notif.Title,
FontSize = 18
};
TextBlock Defdesc = new()
{
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
HorizontalAlignment = HorizontalAlignment.Left,
Text = notif.Description,
FontSize = 13
};
Defbdr.Child = Defpanel;
Defpanel.Children.Add(Deficon);
Defsp.Children.Add(Deftitle);
Defsp.Children.Add(Defdesc);
Defpanel.Children.Add(Defsp);
mw.notifBox.Children.Add(Defbdr);
break;
case NotificationType.Error:
Border Errbdr = new()
{
Margin = new Thickness(0, 3, 0, 0),
Background = mw.FindResource("bgDanger") as System.Windows.Media.Brush,
Padding = new Thickness(20),
CornerRadius = new CornerRadius(3),
Style = mw.FindResource("Notification") as Style,
HorizontalAlignment = HorizontalAlignment.Right,
MinWidth = 400,
MinHeight = 100
};
DockPanel Errpanel = new();
PackIconMaterialDesign Erricon = new()
{
VerticalAlignment = VerticalAlignment.Center,
Kind = PackIconMaterialDesignKind.Error,
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
Width = 30,
Height = 30,
HorizontalAlignment = HorizontalAlignment.Left
};
StackPanel Errsp = new()
{
Margin = new Thickness(10, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center
};
TextBlock Errtitle = new()
{
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
HorizontalAlignment = HorizontalAlignment.Left,
Text = notif.Title,
FontSize = 18
};
TextBlock Errdesc = new()
{
Foreground = mw.FindResource("FG") as System.Windows.Media.Brush,
HorizontalAlignment = HorizontalAlignment.Left,
Text = notif.Description,
FontSize = 13
};
/*
<Border Margin="0,3,0,0" Width="275" Background="{DynamicResource bgDanger}" Padding="20" CornerRadius="3">
<DockPanel>
<iconPacks:PackIconMaterialDesign VerticalAlignment="Center" Kind="Error" Foreground="White" Width="30" Height="30" HorizontalAlignment="Left" />
<StackPanel Margin="10,0,0,0">
<TextBlock Foreground="{DynamicResource FG}" HorizontalAlignment="Left" Text="Test Notification" FontSize="18" />
<TextBlock Foreground="{DynamicResource FG}" HorizontalAlignment="Left" Text="Hello" FontSize="13" />
</StackPanel>
</DockPanel>
</Border>
*/
Errbdr.Child = Errpanel;
Errpanel.Children.Add(Erricon);
Errsp.Children.Add(Errtitle);
Errsp.Children.Add(Errdesc);
Errpanel.Children.Add(Errsp);
mw.notifBox.Children.Add(Errbdr);
break;
}
return true;
}
}
}