mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 02:18:27 +03:00
changes for new messaging
This commit is contained in:
parent
7c1549bb95
commit
480f954433
4 changed files with 44 additions and 60 deletions
21
src/App/Services/MobileBroadcasterMessagingService.cs
Normal file
21
src/App/Services/MobileBroadcasterMessagingService.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using Bit.Core.Abstractions;
|
||||||
|
using Bit.Core.Models.Domain;
|
||||||
|
|
||||||
|
namespace Bit.App.Services
|
||||||
|
{
|
||||||
|
public class MobileBroadcasterMessagingService : IMessagingService
|
||||||
|
{
|
||||||
|
private readonly IBroadcasterService _broadcasterService;
|
||||||
|
|
||||||
|
public MobileBroadcasterMessagingService(IBroadcasterService broadcasterService)
|
||||||
|
{
|
||||||
|
_broadcasterService = broadcasterService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Send(string subscriber, object arg = null)
|
||||||
|
{
|
||||||
|
var message = new Message { Command = subscriber, Data = arg };
|
||||||
|
_broadcasterService.Send(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
using Bit.Core.Abstractions;
|
|
||||||
|
|
||||||
namespace Bit.App.Services
|
|
||||||
{
|
|
||||||
public class MobileMessagingService : IMessagingService
|
|
||||||
{
|
|
||||||
public void Send<T>(string subscriber, T arg = default(T))
|
|
||||||
{
|
|
||||||
Xamarin.Forms.MessagingCenter.Send(Xamarin.Forms.Application.Current, subscriber, arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -35,8 +35,11 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
_broadcasterService.Subscribe<Tuple<int, bool>>("showDialogResolve", (details) =>
|
_broadcasterService.Subscribe("showDialogResolve", (message) =>
|
||||||
{
|
{
|
||||||
|
if(message.Command == "")
|
||||||
|
{
|
||||||
|
var details = message.Data as Tuple<int, bool>;
|
||||||
var dialogId = details.Item1;
|
var dialogId = details.Item1;
|
||||||
var confirmed = details.Item2;
|
var confirmed = details.Item2;
|
||||||
if(_showDialogResolves.ContainsKey(dialogId))
|
if(_showDialogResolves.ContainsKey(dialogId))
|
||||||
|
@ -59,6 +62,7 @@ namespace Bit.App.Services
|
||||||
{
|
{
|
||||||
_showDialogResolves.Remove(id);
|
_showDialogResolves.Remove(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue