-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathBoundServiceConnection.android.cs
More file actions
49 lines (38 loc) · 1.32 KB
/
BoundServiceConnection.android.cs
File metadata and controls
49 lines (38 loc) · 1.32 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 Android.Content;
using Android.OS;
using CommunityToolkit.Maui.Core.Views;
namespace CommunityToolkit.Maui.Services;
sealed partial class BoundServiceConnection(MediaManager mediaManager) : Java.Lang.Object, IServiceConnection
{
readonly WeakEventManager taskRemovedEventManager = new();
public event EventHandler MediaControlsServiceTaskRemoved
{
add => taskRemovedEventManager.AddEventHandler(value);
remove => taskRemovedEventManager.RemoveEventHandler(value);
}
public MediaManager? Activity { get; } = mediaManager;
public bool IsConnected => Binder is not null;
public BoundServiceBinder? Binder { get; private set; }
void HandleTaskRemoved(object? sender, EventArgs e)
{
taskRemovedEventManager.HandleEvent(this, EventArgs.Empty, nameof(MediaControlsServiceTaskRemoved));
}
void IServiceConnection.OnServiceConnected(ComponentName? name, IBinder? service)
{
Binder = service as BoundServiceBinder;
if (Binder is not null)
{
Binder.Service.TaskRemoved += HandleTaskRemoved;
}
// UpdateNotifications needs to be called as it may have been called before the service was connected
Activity?.UpdateNotifications();
}
void IServiceConnection.OnServiceDisconnected(ComponentName? name)
{
if (Binder is not null)
{
Binder.Service.TaskRemoved -= HandleTaskRemoved;
Binder = null;
}
}
}