1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-25 20:53:25 +00:00
Files
mobile/src/Android/Services/AndroidPushNotificationService.cs
2017-12-21 22:28:09 -05:00

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?
}
}
}