mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 10:28:28 +03:00
mobile broadcaster service
This commit is contained in:
parent
1dd5f9fc27
commit
da73a2f5d2
2 changed files with 40 additions and 0 deletions
29
src/App/Services/MobileBroadcasterService.cs
Normal file
29
src/App/Services/MobileBroadcasterService.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using Bit.Core.Abstractions;
|
||||||
|
using System;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Bit.App.Services
|
||||||
|
{
|
||||||
|
public class MobileBroadcasterService : IBroadcasterService
|
||||||
|
{
|
||||||
|
public void Send<T>(T message, string id = null)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(id))
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Cannot send a message to all subscribers.");
|
||||||
|
}
|
||||||
|
MessagingCenter.Send(Application.Current, id, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Subscribe<T>(string id, Action<T> messageCallback)
|
||||||
|
{
|
||||||
|
MessagingCenter.Subscribe<Application, T>(Application.Current, id,
|
||||||
|
(sender, message) => messageCallback(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unsubscribe(string id)
|
||||||
|
{
|
||||||
|
MessagingCenter.Unsubscribe<Application, object>(Application.Current, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
src/Core/Abstractions/IBroadcasterService.cs
Normal file
11
src/Core/Abstractions/IBroadcasterService.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Bit.Core.Abstractions
|
||||||
|
{
|
||||||
|
public interface IBroadcasterService
|
||||||
|
{
|
||||||
|
void Send<T>(T message, string id = null);
|
||||||
|
void Subscribe<T>(string id, Action<T> messageCallback);
|
||||||
|
void Unsubscribe(string id);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue