This repository was archived by the owner on Jan 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPreferencesStateListener.cs
More file actions
49 lines (47 loc) · 1.34 KB
/
PreferencesStateListener.cs
File metadata and controls
49 lines (47 loc) · 1.34 KB
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
using System;
namespace Dawn.Utilities
{
public class PreferencesStateListener
{
/// <summary>
/// Typically used OnAppStart
/// </summary>
public PreferencesStateListener(bool Preference, Action OnTrue, Action OnFalse, bool InitialInvoke = false)
{
PreviousResult = Preference;
this.OnTrue = OnTrue;
this.OnFalse = OnFalse;
if (Preference && InitialInvoke) OnTrue?.Invoke();
}
/// <summary>
/// Typically used OnPreferencesSaved
/// </summary>
public void Update(bool UpdateState)
{
if (UpdateState)
{
if (!PreviousResult)
{
OnTrue?.Invoke();
}
}
else
{
if (PreviousResult)
{
OnFalse?.Invoke();
}
}
PreviousResult = UpdateState;
}
public void ForceUpdate(bool UpdateState)
{
if (UpdateState) OnTrue?.Invoke();
else OnFalse?.Invoke();
PreviousResult = UpdateState;
}
private readonly Action OnTrue;
private readonly Action OnFalse;
private bool PreviousResult;
}
}