forked from VladislavAntonyuk/MauiSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
62 lines (51 loc) · 1.41 KB
/
MainPage.xaml.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
namespace MauiDynamicConfiguration;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ConfigCat.Client;
public partial class MainPage : ContentPage
{
private readonly MainViewModel mainViewModel;
public MainPage(MainViewModel mainViewModel)
{
InitializeComponent();
this.mainViewModel = mainViewModel;
BindingContext = mainViewModel;
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);
mainViewModel.Initialize();
}
}
public partial class MainViewModel : ObservableObject
{
private readonly IConfigCatClient configCatClient;
private readonly UserContext userContext;
[ObservableProperty]
string title = "Main Page";
[ObservableProperty]
string image = "bot.png";
public MainViewModel(IConfigCatClient configCatClient, UserContext userContext)
{
this.configCatClient = configCatClient;
configCatClient.ConfigChanged += (_, _) =>
{
Initialize();
};
this.userContext = userContext;
}
public void Initialize()
{
Title = this.configCatClient.GetValue("beta_gmailusers_mainpagetitle", "Main Page", new User(userContext.Email)
{
Email = userContext.Email
});
Image = this.configCatClient.GetValue("beta", false) ? "botbeta.png" : "bot.png";
}
[RelayCommand]
private async Task Logout()
{
userContext.Email = null;
await ((AppShell)Application.Current!.MainPage!).GoToAsync("///LoginPage");
}
}