-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathMainPage.xaml.cs
69 lines (58 loc) · 1.63 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
63
64
65
66
67
68
69
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 async void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);
await mainViewModel.Initialize();
}
}
public partial class MainViewModel : ObservableObject
{
private readonly IConfigCatClient configCatClient;
private readonly UserContext userContext;
[ObservableProperty]
public partial string Title { get; set; }
[ObservableProperty]
public partial string Image { get; set; }
public MainViewModel(IConfigCatClient configCatClient, UserContext userContext)
{
this.configCatClient = configCatClient;
configCatClient.ConfigChanged += async (_, _) =>
{
await Initialize();
};
this.userContext = userContext;
Image = "bot.png";
Title = "Main Page";
}
public async Task Initialize()
{
Title = await configCatClient.GetValueAsync("beta_gmailusers_mainpagetitle", "Main Page", new User(userContext.Email)
{
Email = userContext.Email
});
Image = await configCatClient.GetValueAsync("beta", false) ? "botbeta.png" : "bot.png";
}
[RelayCommand]
private async Task Logout()
{
userContext.Email = string.Empty;
var page = Application.Current?.Windows.LastOrDefault()?.Page as AppShell;
if (page is null)
{
ArgumentNullException.ThrowIfNull(page);
}
await page.GoToAsync("///LoginPage");
}
}