Skip to content

Commit af31e60

Browse files
committed
Fixed Notification Manager stuff
1 parent 22e60b1 commit af31e60

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

CutCode/Interfaces/INotificationManager.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using System.Windows.Threading;
78

89
namespace CutCode
910
{
@@ -28,10 +29,16 @@ public void CreateNotification(string message, int delay)
2829
public void CloseNotification(NotifyObject notification) => OnCloseNotification?.Invoke(notification, EventArgs.Empty);
2930
}
3031

31-
public class NotifyObject : PropertyChangedBase
32+
public class NotifyObject
3233
{
3334
public string Message { get; set; }
3435
public int Delay { get; set; }
3536
public System.Object View { get; set; }
3637
}
38+
39+
public class LiveNotification
40+
{
41+
public DispatcherTimer timer { get; set; }
42+
public NotifyObject notification { get; set; }
43+
}
3744
}

CutCode/ViewModels/MainViewModel.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ public void ChangePageCommand(string selected_item)
103103

104104
sideBarBtns[ind].background = _themeService.IsLightTheme ? ColorCon.Convert("#FCFCFC") : ColorCon.Convert("#36393F");
105105
if (currentPage != Pages[ind]) pageService.Page = Pages[ind];
106-
107-
if(selected_item == "Settings")
108-
{
109-
notifyManager.CreateNotification("Simple test", 10);
110-
}
111106
}
112107
#region Color
113108
private SolidColorBrush _backgroundColor;
@@ -209,6 +204,7 @@ public ObservableCollection<NotifyObject> notificationList
209204
}
210205

211206
private List<NotifyObject> WaitingNotifications = new List<NotifyObject>();
207+
private List<LiveNotification> liveNotifications = new List<LiveNotification>();
212208
private void showNotification(object sender, EventArgs e)
213209
{
214210
var notification = sender as NotifyObject;
@@ -229,22 +225,46 @@ private void showNotification(object sender, EventArgs e)
229225
Interval = TimeSpan.FromSeconds(notification.Delay),
230226
IsEnabled = true
231227
};
228+
liveNotifications.Add(new LiveNotification() { timer = closeTimer, notification = notification});
232229
closeTimer.Tick += CloseNotification;
233230
}
234231
}
235232

236233
private void exitNotification(object sender, EventArgs e)
237234
{
238235
var notification = sender as NotifyObject;
236+
var liveNotification = new LiveNotification();
237+
foreach (var _liveNotification in liveNotifications)
238+
{
239+
if (_liveNotification.notification == notification)
240+
{
241+
liveNotification = _liveNotification;
242+
break;
243+
}
244+
}
239245
notificationList.Remove(notification);
240246
UpdateNotification();
247+
liveNotification.timer.Stop();
248+
liveNotifications.Remove(liveNotification);
241249
}
242250

243251
private void CloseNotification(object sender, EventArgs e)
244252
{
245-
if(notificationList.Count > 0) notificationList.RemoveAt(0);
253+
var timer = sender as DispatcherTimer;
254+
var liveNotification = new LiveNotification();
255+
foreach(var _liveNotification in liveNotifications)
256+
{
257+
if(_liveNotification.timer == timer)
258+
{
259+
liveNotification = _liveNotification;
260+
break;
261+
}
262+
}
263+
264+
notificationList.Remove(liveNotification.notification);
265+
liveNotifications.Remove(liveNotification);
246266
UpdateNotification();
247-
(sender as DispatcherTimer).Stop();
267+
timer.Stop();
248268
}
249269

250270
private void UpdateNotification()

CutCode/Views/NotificationDialogView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</Grid>
5656

5757
<Button Grid.Column="1" Background="Transparent"
58-
Style="{DynamicResource ButtonStyle}" Command="{s:Action ExitCommand}" Margin="0,0,5,0"
58+
Style="{DynamicResource ButtonStyle}" Command="{s:Action ExitCommand}" Margin="5,0,5,0"
5959
BorderBrush="{Binding exitBtnHoverColor}" VerticalAlignment="Center" Height="20" Width="20">
6060
<Image Width="15" Height="15" Source="{Binding exitImage}"
6161
RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased"/>

0 commit comments

Comments
 (0)