blob: 17d5146136ce217ad5b5ce19b62f83847c2d3022 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Commands;
using Tango.Core.DI;
namespace Tango.FSE.Common.Notifications
{
public class SnackbarItem : ExtendedObject
{
private Action _closeAction;
private Action _pressAction;
private bool _isClosed;
public bool HoldTimeout { get; set; }
private MessageType _type;
public MessageType Type
{
get { return _type; }
set { _type = value; RaisePropertyChangedAuto(); }
}
public String Title { get; set; }
private String _message;
public String Message
{
get { return _message; }
set { _message = value; RaisePropertyChangedAuto(); }
}
private bool _isProgress;
public bool IsProgress
{
get { return _isProgress; }
set { _isProgress = value; RaisePropertyChangedAuto(); }
}
public TimeSpan? Timeout { get; set; }
private bool _canClose;
public bool CanClose
{
get { return _canClose; }
set { _canClose = value; RaisePropertyChangedAuto(); }
}
public RelayCommand CloseCommand { get; private set; }
public RelayCommand PressCommand { get; private set; }
private bool _isClosing;
public bool IsClosing
{
get { return _isClosing; }
private set { _isClosing = value; RaisePropertyChangedAuto(); }
}
public SnackbarItem(MessageType type, String title, bool canClose, String message = null, TimeSpan? timeout = null, Action closeAction = null, Action pressAction = null)
{
Type = type;
Title = title;
CanClose = canClose;
Message = message;
Timeout = timeout;
_pressAction = () =>
{
if (IsProgress) return;
if (pressAction != null)
{
Close();
pressAction.Invoke();
}
else if (CanClose)
{
Close();
}
};
_closeAction = () =>
{
Close();
closeAction?.Invoke();
};
PressCommand = new RelayCommand(() => { _pressAction?.Invoke(); });
CloseCommand = new RelayCommand(() => { _closeAction?.Invoke(); });
StartCloseTimeout(Timeout);
}
public void Close()
{
if (!_isClosed)
{
_isClosed = true;
TangoIOC.Default.GetInstance<INotificationProvider>().PopSnackbarItem(this);
}
}
public void ProgressCompleted(String message, TimeSpan? timeout = null, Action pressAction = null)
{
if (pressAction != null)
{
_pressAction = () =>
{
Close();
pressAction.Invoke();
};
}
IsProgress = false;
CanClose = true;
Message = message;
Type = MessageType.Success;
StartCloseTimeout(timeout);
}
public void ProgressFailed(String message, TimeSpan? timeout = null)
{
IsProgress = false;
CanClose = true;
Message = message;
Type = MessageType.Error;
StartCloseTimeout(timeout);
}
private void StartCloseTimeout(TimeSpan? timeout)
{
if (timeout != null)
{
Task.Delay(timeout.Value).ContinueWith((x) =>
{
if (HoldTimeout)
{
StartCloseTimeout(timeout);
return;
}
if (!_isClosed)
{
IsClosing = true;
Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith((y) =>
{
if (HoldTimeout)
{
IsClosing = false;
StartCloseTimeout(timeout);
return;
}
Close();
});
}
});
}
}
}
}
|