-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAppShell.xaml.cs
More file actions
66 lines (56 loc) · 1.87 KB
/
Copy pathAppShell.xaml.cs
File metadata and controls
66 lines (56 loc) · 1.87 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using TFMAudioApp.Services.Interfaces;
using TFMAudioApp.Views;
namespace TFMAudioApp;
public partial class AppShell : Shell
{
private IConnectivityService? _connectivityService;
public AppShell()
{
InitializeComponent();
// Register routes for pages that are navigated to with parameters
Routing.RegisterRoute("playlistdetail", typeof(PlaylistDetailPage));
Routing.RegisterRoute("channeldetail", typeof(ChannelDetailPage));
Routing.RegisterRoute("folderdetail", typeof(FolderDetailPage));
Routing.RegisterRoute("player", typeof(PlayerPage));
}
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
if (Handler != null)
{
InitializeConnectivityService();
}
}
private void InitializeConnectivityService()
{
_connectivityService = Application.Current?.Handler?.MauiContext?.Services.GetService<IConnectivityService>();
if (_connectivityService != null)
{
_connectivityService.ConnectivityChanged += OnConnectivityChanged;
UpdateConnectionUI(_connectivityService.IsConnected);
}
}
private void OnConnectivityChanged(object? sender, bool isConnected)
{
MainThread.BeginInvokeOnMainThread(() =>
{
UpdateConnectionUI(isConnected);
});
}
private void UpdateConnectionUI(bool isConnected)
{
if (ConnectionIndicator != null && ConnectionText != null)
{
if (isConnected)
{
ConnectionIndicator.TextColor = Color.FromArgb("#22C55E"); // Green
ConnectionText.Text = "Online";
}
else
{
ConnectionIndicator.TextColor = Color.FromArgb("#EF4444"); // Red
ConnectionText.Text = "Offline";
}
}
}
}