mirror of
https://github.com/bitwarden/mobile
synced 2025-12-25 20:53:25 +00:00
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System;
|
|
using Bit.App;
|
|
using Bit.App.Abstractions;
|
|
using Plugin.Settings.Abstractions;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Bit.Android.Services
|
|
{
|
|
public class AndroidPushNotificationService : IPushNotificationService
|
|
{
|
|
private readonly IPushNotificationListener _pushNotificationListener;
|
|
private readonly ISettings _settings;
|
|
|
|
public AndroidPushNotificationService(
|
|
IPushNotificationListener pushNotificationListener,
|
|
ISettings settings)
|
|
{
|
|
_pushNotificationListener = pushNotificationListener;
|
|
_settings = settings;
|
|
}
|
|
|
|
public string Token => _settings.GetValueOrDefault(Constants.PushCurrentToken, null);
|
|
|
|
public void Register()
|
|
{
|
|
var registeredToken = _settings.GetValueOrDefault(Constants.PushRegisteredToken, null);
|
|
if(!string.IsNullOrWhiteSpace(registeredToken) && registeredToken != Token)
|
|
{
|
|
_pushNotificationListener.OnRegistered(registeredToken, Device.Android);
|
|
}
|
|
else
|
|
{
|
|
_settings.AddOrUpdateValue(Constants.PushLastRegistrationDate, DateTime.UtcNow);
|
|
}
|
|
}
|
|
|
|
public void Unregister()
|
|
{
|
|
// Do we ever need to unregister?
|
|
}
|
|
}
|
|
}
|