-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ActivationState.cs
114 lines (100 loc) · 2.65 KB
/
ActivationState.cs
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
#nullable enable
using System;
namespace Microsoft.Maui
{
public class ActivationState : IActivationState
{
#if __ANDROID__
public ActivationState(IMauiContext context, Android.OS.Bundle? savedInstance)
: this(context, GetPersistedState(savedInstance))
{
SavedInstance = savedInstance;
}
#elif __IOS__
public ActivationState(IMauiContext context, Foundation.NSDictionary[]? states)
: this(context, GetPersistedState(states))
{
}
#elif WINDOWS
public ActivationState(IMauiContext context, UI.Xaml.LaunchActivatedEventArgs? launchActivatedEventArgs)
: this(context)
{
LaunchActivatedEventArgs = launchActivatedEventArgs;
}
#elif TIZEN
public ActivationState(IMauiContext context, Tizen.Applications.Bundle? savedInstance)
: this(context, GetPersistedState(savedInstance))
{
SavedInstance = savedInstance;
}
#endif
public ActivationState(IMauiContext context)
{
Context = context ?? throw new ArgumentNullException(nameof(context));
State = new PersistedState();
}
public ActivationState(IMauiContext context, IPersistedState state)
{
Context = context ?? throw new ArgumentNullException(nameof(context));
State = state ?? throw new ArgumentNullException(nameof(state));
}
public IMauiContext Context { get; }
public IPersistedState State { get; }
#if __ANDROID__
public Android.OS.Bundle? SavedInstance { get; }
#elif WINDOWS
public UI.Xaml.LaunchActivatedEventArgs? LaunchActivatedEventArgs { get; }
#elif TIZEN
public Tizen.Applications.Bundle? SavedInstance { get; }
#endif
#if __ANDROID__
static PersistedState GetPersistedState(Android.OS.Bundle? state)
{
var dict = new PersistedState();
var keyset = state?.KeySet();
if (keyset != null)
{
foreach (var k in keyset)
{
#pragma warning disable 618 // TODO: one day use the API 33+ version: https://developer.android.com/reference/kotlin/android/os/BaseBundle?hl=en#get
dict[k] = state?.Get(k)?.ToString();
#pragma warning restore 618
}
}
return dict;
}
#elif __IOS__
static PersistedState GetPersistedState(Foundation.NSDictionary[]? states)
{
var state = new PersistedState();
if (states != null)
{
foreach (var s in states)
{
foreach (var k in s.Keys)
{
var key = k.ToString();
var val = s?[k]?.ToString();
state[key] = val;
}
}
}
return state;
}
#elif TIZEN
static PersistedState GetPersistedState(Tizen.Applications.Bundle? state)
{
var dict = new PersistedState();
var keyset = state?.Keys;
if (keyset != null)
{
foreach (var k in keyset)
{
dict[k] = state?.GetItem<string>(k);
}
}
return dict;
}
#endif
}
}