Skip to content

Commit 208ff06

Browse files
committed
created INotifyInterface
1 parent 38c9677 commit 208ff06

7 files changed

Lines changed: 127 additions & 38 deletions

File tree

CutCode/Helpers/Bootstrapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ protected override void ConfigureIoC(IStyletIoCBuilder builder)
1010
builder.Bind<IThemeService>().To<ThemeService>();
1111
builder.Bind<IPageService>().To<PageService>();
1212
builder.Bind<IDataBase>().To<DataBaseManager>();
13+
builder.Bind<INotificationManager>().To<NotificationManager>();
1314
}
1415
}
1516
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CutCode
8+
{
9+
public interface INotificationManager
10+
{
11+
event EventHandler ShowNotification;
12+
void CreateNotification(string message, int delay);
13+
}
14+
15+
public class NotificationManager : INotificationManager
16+
{
17+
public event EventHandler ShowNotification;
18+
public void CreateNotification(string message, int delay)
19+
{
20+
var notify = new NotifyModel(){ Message = message, Delay= delay};
21+
ShowNotification?.Invoke(notify, EventArgs.Empty);
22+
}
23+
}
24+
25+
public class NotifyModel
26+
{
27+
public string Message { get; set; }
28+
public int Delay { get; set; }
29+
}
30+
}

CutCode/ViewModels/MainViewModel.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Windows.Controls;
1515
using System.Windows.Input;
1616
using System.Windows.Media;
17+
using System.Windows.Threading;
1718

1819
namespace CutCode
1920
{
@@ -24,11 +25,15 @@ public class MainViewModel : Screen
2425
private readonly IThemeService _themeService;
2526
private IWindowManager windowManager;
2627
private readonly IPageService pageService;
28+
private readonly INotificationManager notifyManager;
2729
public ObservableCollection<SideBarBtnModel> sideBarBtns { get; set; }
28-
public MainViewModel(IWindowManager _windowManager,IThemeService themeService, IPageService _pageService, IDataBase _dataBase)
30+
public MainViewModel(IWindowManager _windowManager,IThemeService themeService, IPageService _pageService, IDataBase _dataBase, INotificationManager _notifyManager)
2931
{
3032
windowManager = _windowManager;
3133

34+
notifyManager = _notifyManager;
35+
notifyManager.ShowNotification += showNotification;
36+
3237
_themeService = themeService;
3338
_themeService.ThemeChanged += ThemeChanged;
3439
_themeService.IsLightTheme = _dataBase.isLightTheme;
@@ -99,7 +104,7 @@ public void ChangePageCommand(string selected_item)
99104

100105
if(selected_item == "Share")
101106
{
102-
windowManager.ShowDialog(new NotificationDialogViewModel(_themeService, "Just for test"));
107+
notifyManager.CreateNotification("This is just for test", 6);
103108
}
104109
}
105110

@@ -193,5 +198,41 @@ public string minImage
193198
set
194199
{ SetAndNotify(ref _minImage, value); }
195200
}
201+
202+
#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
212+
{
213+
get => _notifcationDialogVisibility;
214+
set => SetAndNotify(ref _notifcationDialogVisibility, value);
215+
}
216+
217+
private void showNotification(object sender, EventArgs e)
218+
{
219+
var noitification = sender as NotifyModel;
220+
221+
var notifcationViewModel = new NotificationDialogViewModel(_themeService, noitification.Message);
222+
notificationDialogView = (Object)notifcationViewModel;
223+
224+
notifcationDialogVisibility = Visibility.Visible;
225+
var closeTimer = new DispatcherTimer
226+
{
227+
Interval = TimeSpan.FromSeconds(noitification.Delay),
228+
IsEnabled = true
229+
};
230+
closeTimer.Tick += (object sender, EventArgs e) =>
231+
{
232+
notifcationDialogVisibility = Visibility.Hidden;
233+
closeTimer.Stop();
234+
};
235+
}
236+
#endregion
196237
}
197238
}

CutCode/ViewModels/NotificationDialogViewModel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ namespace CutCode
1010
{
1111
public class NotificationDialogViewModel : Screen
1212
{
13-
public NotificationDialogViewModel(IThemeService themeService, string _message)
13+
private readonly IThemeService themeService;
14+
public NotificationDialogViewModel(IThemeService _themeService, string _message)
1415
{
1516
message = _message;
17+
themeService = _themeService;
18+
SetAppearance(null, null);
19+
themeService.ThemeChanged += SetAppearance;
20+
}
21+
22+
private void SetAppearance(object sender, EventArgs e)
23+
{
1624
background = themeService.IsLightTheme ? ColorCon.Convert("#DCDCDC") : ColorCon.Convert("#26292F");
1725
exitBtnHoverColor = themeService.IsLightTheme ? ColorCon.Convert("#D0D1D2") : ColorCon.Convert("#1F232B");
1826
textColor = themeService.IsLightTheme ? ColorCon.Convert("#060607") : ColorCon.Convert("#94969A");
@@ -69,5 +77,10 @@ public SolidColorBrush exitBtnHoverColor
6977
}
7078

7179
}
80+
81+
public void ExitCommand()
82+
{
83+
84+
}
7285
}
7386
}

CutCode/Views/MainView.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
<ContentControl s:View.Model="{Binding currentPage, UpdateSourceTrigger=PropertyChanged}"/>
153153
</Grid>
154154

155+
<Grid Grid.Row="1">
156+
<ContentControl Visibility="{Binding notifcationDialogVisibility}" HorizontalAlignment="Right" VerticalAlignment="Bottom"
157+
s:View.Model="{Binding notificationDialogView, UpdateSourceTrigger=PropertyChanged}"/>
158+
</Grid>
159+
155160
</Grid>
156161
</Grid>
157162
</Window>
Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
<Window x:Class="CutCode.NotificationDialogView"
1+
<UserControl x:Class="CutCode.NotificationDialogView"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:s="https://github.com/canton7/Stylet"
67
xmlns:local="clr-namespace:CutCode"
7-
mc:Ignorable="d"
8+
mc:Ignorable="d"
89
d:DataContext="{d:DesignInstance local:NotificationDialogViewModel}"
9-
ResizeMode="NoResize"
10-
WindowStyle="SingleBorderWindow"
1110
UseLayoutRounding="True"
12-
Title="Notification" Height="50" Width="270">
11+
Padding="10">
1312

14-
<WindowChrome.WindowChrome>
15-
<WindowChrome GlassFrameThickness="0" CornerRadius="15" CaptionHeight="0" ResizeBorderThickness="5"/>
16-
</WindowChrome.WindowChrome>
17-
18-
<Window.Resources>
13+
<UserControl.Resources>
1914
<Style x:Key="ButtonStyle" TargetType="Button">
2015
<Setter Property="Template">
2116
<Setter.Value>
@@ -39,29 +34,33 @@
3934
</Setter.Value>
4035
</Setter>
4136
</Style>
42-
</Window.Resources>
43-
44-
<Grid Background="{Binding background}">
45-
<Grid.ColumnDefinitions>
46-
<ColumnDefinition Width="*"/>
47-
<ColumnDefinition Width="40"/>
48-
</Grid.ColumnDefinitions>
37+
</UserControl.Resources>
38+
39+
<Border Background="{Binding background}" CornerRadius="8"
40+
Height="50" MinWidth="250">
41+
<Grid>
42+
<Grid.ColumnDefinitions>
43+
<ColumnDefinition Width="*"/>
44+
<ColumnDefinition Width="40"/>
45+
</Grid.ColumnDefinitions>
4946

50-
<Grid Grid.Column="0">
51-
<Grid.RowDefinitions>
52-
<RowDefinition Height="30"/>
53-
<RowDefinition Height="Auto"/>
54-
</Grid.RowDefinitions>
55-
<Label Grid.Row="0" FontSize="10.5" FontFamily="{StaticResource poppins_semibold}" Content="Notification" Foreground="{Binding textColor}"/>
56-
<Label Grid.Row="1" Foreground="{Binding textColor}" Content="{Binding message}" Margin="0,-12,0,0"
47+
<Grid Grid.Column="0">
48+
<Grid.RowDefinitions>
49+
<RowDefinition Height="30"/>
50+
<RowDefinition Height="Auto"/>
51+
</Grid.RowDefinitions>
52+
<Label Grid.Row="0" FontSize="10.5" FontFamily="{StaticResource poppins_semibold}" Content="Notification" Foreground="{Binding textColor}"/>
53+
<Label Grid.Row="1" Foreground="{Binding textColor}" Content="{Binding message}" Margin="0,-12,0,0"
5754
FontSize="14" FontFamily="{StaticResource poppins_semibold}"/>
58-
</Grid>
55+
</Grid>
5956

60-
<Button Grid.Column="1" Background="Transparent" Style="{DynamicResource ButtonStyle}"
61-
Click="exitBtnClick" BorderBrush="{Binding exitBtnHoverColor}" VerticalAlignment="Center">
62-
<Image Width="20" Height="20" Margin="4,15,4,15" Source="{Binding exitImage}"
57+
<Button Margin="10,2,2,2" Grid.Column="1" Background="Transparent"
58+
Style="{DynamicResource ButtonStyle}" Command="{s:Action ExitCommand}"
59+
BorderBrush="{Binding exitBtnHoverColor}" VerticalAlignment="Center" Height="50">
60+
<Image Width="18" Height="18" Source="{Binding exitImage}"
6361
RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased"/>
64-
</Button>
62+
</Button>
6563

66-
</Grid>
67-
</Window>
64+
</Grid>
65+
</Border>
66+
</UserControl>

CutCode/Views/NotificationDialogView.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ namespace CutCode
2020
/// <summary>
2121
/// Interaction logic for NotificationDialogView.xaml
2222
/// </summary>
23-
public partial class NotificationDialogView : Window
23+
public partial class NotificationDialogView : System.Windows.Controls.UserControl
2424
{
2525
public NotificationDialogView()
2626
{
2727
InitializeComponent();
2828

29+
/*
2930
var mainView = System.Windows.Application.Current.Windows[0] as MainView;
30-
3131
if(mainView.WindowState == WindowState.Maximized)
3232
{
3333
var currentScreen = Screen.FromHandle(new WindowInteropHelper(mainView).Handle).Bounds;
@@ -39,15 +39,15 @@ public NotificationDialogView()
3939
Top = mainView.Top + mainView.Height - (Height + 10);
4040
Left = mainView.Left + mainView.Width - (Width + 10);
4141
}
42-
4342
var closeTimer = new DispatcherTimer
4443
{
4544
Interval = TimeSpan.FromSeconds(3),
4645
IsEnabled = true
4746
};
4847
closeTimer.Tick += exitBtnClick;
48+
*/
4949
}
5050

51-
private void exitBtnClick(object sender, EventArgs e) => Close();
51+
//private void exitBtnClick(object sender, EventArgs e) => Close();
5252
}
5353
}

0 commit comments

Comments
 (0)