Skip to content

Commit

Permalink
Fixed Notification Manager stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdesol committed Sep 12, 2021
1 parent 22e60b1 commit af31e60
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
9 changes: 8 additions & 1 deletion CutCode/Interfaces/INotificationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;

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

public class NotifyObject : PropertyChangedBase
public class NotifyObject
{
public string Message { get; set; }
public int Delay { get; set; }
public System.Object View { get; set; }
}

public class LiveNotification
{
public DispatcherTimer timer { get; set; }
public NotifyObject notification { get; set; }
}
}
34 changes: 27 additions & 7 deletions CutCode/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ public void ChangePageCommand(string selected_item)

sideBarBtns[ind].background = _themeService.IsLightTheme ? ColorCon.Convert("#FCFCFC") : ColorCon.Convert("#36393F");
if (currentPage != Pages[ind]) pageService.Page = Pages[ind];

if(selected_item == "Settings")
{
notifyManager.CreateNotification("Simple test", 10);
}
}
#region Color
private SolidColorBrush _backgroundColor;
Expand Down Expand Up @@ -209,6 +204,7 @@ public ObservableCollection<NotifyObject> notificationList
}

private List<NotifyObject> WaitingNotifications = new List<NotifyObject>();
private List<LiveNotification> liveNotifications = new List<LiveNotification>();
private void showNotification(object sender, EventArgs e)
{
var notification = sender as NotifyObject;
Expand All @@ -229,22 +225,46 @@ private void showNotification(object sender, EventArgs e)
Interval = TimeSpan.FromSeconds(notification.Delay),
IsEnabled = true
};
liveNotifications.Add(new LiveNotification() { timer = closeTimer, notification = notification});
closeTimer.Tick += CloseNotification;
}
}

private void exitNotification(object sender, EventArgs e)
{
var notification = sender as NotifyObject;
var liveNotification = new LiveNotification();
foreach (var _liveNotification in liveNotifications)
{
if (_liveNotification.notification == notification)
{
liveNotification = _liveNotification;
break;
}
}
notificationList.Remove(notification);
UpdateNotification();
liveNotification.timer.Stop();
liveNotifications.Remove(liveNotification);
}

private void CloseNotification(object sender, EventArgs e)
{
if(notificationList.Count > 0) notificationList.RemoveAt(0);
var timer = sender as DispatcherTimer;
var liveNotification = new LiveNotification();
foreach(var _liveNotification in liveNotifications)
{
if(_liveNotification.timer == timer)
{
liveNotification = _liveNotification;
break;
}
}

notificationList.Remove(liveNotification.notification);
liveNotifications.Remove(liveNotification);
UpdateNotification();
(sender as DispatcherTimer).Stop();
timer.Stop();
}

private void UpdateNotification()
Expand Down
2 changes: 1 addition & 1 deletion CutCode/Views/NotificationDialogView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</Grid>

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

0 comments on commit af31e60

Please sign in to comment.