rename to pushnotificationservice

This commit is contained in:
Kyle Spearrin 2017-10-10 08:25:23 -04:00
parent 6da0d3e88d
commit 6040c7768f
14 changed files with 87 additions and 93 deletions

View file

@ -317,7 +317,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\LogService.cs" /> <Compile Include="Services\LogService.cs" />
<Compile Include="Services\MemoryService.cs" /> <Compile Include="Services\MemoryService.cs" />
<Compile Include="Services\PushNotificationImplementation.cs" /> <Compile Include="Services\AndroidPushNotificationService.cs" />
<Compile Include="Services\ReflectionService.cs" /> <Compile Include="Services\ReflectionService.cs" />
<Compile Include="Services\SqlService.cs" /> <Compile Include="Services\SqlService.cs" />
<Compile Include="SplashActivity.cs" /> <Compile Include="SplashActivity.cs" />

View file

@ -67,7 +67,7 @@ namespace Bit.Android
private void HandlePushReregistration() private void HandlePushReregistration()
{ {
var pushNotification = Resolver.Resolve<IPushNotification>(); var pushNotification = Resolver.Resolve<IPushNotificationService>();
var settings = Resolver.Resolve<ISettings>(); var settings = Resolver.Resolve<ISettings>();
// Reregister for push token based on certain conditions // Reregister for push token based on certain conditions
@ -151,11 +151,11 @@ namespace Bit.Android
public static void StartPushService() public static void StartPushService()
{ {
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService))); AppContext.StartService(new Intent(AppContext, typeof(AndroidPushNotificationService)));
if(Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) if(Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{ {
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext,
typeof(PushNotificationService)), 0); typeof(AndroidPushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService); AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
alarm.Cancel(pintent); alarm.Cancel(pintent);
} }
@ -163,11 +163,11 @@ namespace Bit.Android
public static void StopPushService() public static void StopPushService()
{ {
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService))); AppContext.StopService(new Intent(AppContext, typeof(AndroidPushNotificationService)));
if(Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) if(Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{ {
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext,
typeof(PushNotificationService)), 0); typeof(AndroidPushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService); AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
alarm.Cancel(pintent); alarm.Cancel(pintent);
} }

View file

@ -17,7 +17,7 @@ using Newtonsoft.Json;
namespace Bit.Android.Services namespace Bit.Android.Services
{ {
public class PushNotificationImplementation : IPushNotification public class AndroidPushNotificationService : IPushNotificationService
{ {
private const string GcmPreferencesKey = "GCMPreferences"; private const string GcmPreferencesKey = "GCMPreferences";
private const string Tag = "PushNotification"; private const string Tag = "PushNotification";
@ -29,20 +29,20 @@ namespace Bit.Android.Services
{ {
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - Register - Registering push notifications"); $"{PushNotificationContants.DomainName} - Register - Registering push notifications");
if(string.IsNullOrEmpty(CrossPushNotification.SenderId)) if(string.IsNullOrEmpty(CrossPushNotification.SenderId))
{ {
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - Register - SenderId is missing."); $"{PushNotificationContants.DomainName} - Register - SenderId is missing.");
CrossPushNotification.PushNotificationListener.OnError( CrossPushNotification.PushNotificationListener.OnError(
$"{PushNotificationKey.DomainName} - Register - Sender Id is missing.", Device.Android); $"{PushNotificationContants.DomainName} - Register - Sender Id is missing.", Device.Android);
} }
else else
{ {
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - Register - Registering for Push Notifications"); $"{PushNotificationContants.DomainName} - Register - Registering for Push Notifications");
ThreadPool.QueueUserWorkItem(state => ThreadPool.QueueUserWorkItem(state =>
{ {
@ -68,10 +68,10 @@ namespace Bit.Android.Services
ThreadPool.QueueUserWorkItem(state => ThreadPool.QueueUserWorkItem(state =>
{ {
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - Unregister - Unregistering push notifications"); $"{PushNotificationContants.DomainName} - Unregister - Unregistering push notifications");
try try
{ {
InstanceID instanceID = InstanceID.GetInstance(global::Android.App.Application.Context); var instanceID = InstanceID.GetInstance(global::Android.App.Application.Context);
instanceID.DeleteToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope); instanceID.DeleteToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope);
CrossPushNotification.PushNotificationListener.OnUnregistered(Device.Android); CrossPushNotification.PushNotificationListener.OnUnregistered(Device.Android);
@ -89,35 +89,31 @@ namespace Bit.Android.Services
private string GetRegistrationId() private string GetRegistrationId()
{ {
var retVal = string.Empty;
var context = global::Android.App.Application.Context; var context = global::Android.App.Application.Context;
var prefs = GetGCMPreferences(context); var prefs = GetGCMPreferences(context);
var registrationId = prefs.GetString(PushNotificationKey.Token, string.Empty); var registrationId = prefs.GetString(PushNotificationContants.Token, string.Empty);
if(string.IsNullOrEmpty(registrationId)) if(string.IsNullOrEmpty(registrationId))
{ {
System.Diagnostics.Debug.WriteLine($"{PushNotificationKey.DomainName} - Registration not found."); System.Diagnostics.Debug.WriteLine($"{PushNotificationContants.DomainName} - Registration not found.");
return retVal; return string.Empty;
} }
// Check if app was updated; if so, it must clear the registration ID // Check if app was updated; if so, it must clear the registration ID
// since the existing registration ID is not guaranteed to work with // since the existing registration ID is not guaranteed to work with
// the new app version. // the new app version.
var registeredVersion = prefs.GetInt(PushNotificationKey.AppVersion, Java.Lang.Integer.MinValue); var registeredVersion = prefs.GetInt(PushNotificationContants.AppVersion, Java.Lang.Integer.MinValue);
var currentVersion = GetAppVersion(context); var currentVersion = GetAppVersion(context);
if(registeredVersion != currentVersion) if(registeredVersion != currentVersion)
{ {
System.Diagnostics.Debug.WriteLine($"{PushNotificationKey.DomainName} - App version changed."); System.Diagnostics.Debug.WriteLine($"{PushNotificationContants.DomainName} - App version changed.");
return retVal; return string.Empty;
} }
retVal = registrationId; return registrationId;
return retVal;
} }
internal static ISharedPreferences GetGCMPreferences(Context context) internal static ISharedPreferences GetGCMPreferences(Context context)
{ {
// This sample app persists the registration ID in shared preferences, but
// how you store the registration ID in your app is up to you.
return context.GetSharedPreferences(GcmPreferencesKey, FileCreationMode.Private); return context.GetSharedPreferences(GcmPreferencesKey, FileCreationMode.Private);
} }
@ -141,11 +137,11 @@ namespace Bit.Android.Services
var appVersion = GetAppVersion(context); var appVersion = GetAppVersion(context);
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - Saving token on app version {appVersion}"); $"{PushNotificationContants.DomainName} - Saving token on app version {appVersion}");
var editor = prefs.Edit(); var editor = prefs.Edit();
editor.PutString(PushNotificationKey.Token, regId); editor.PutString(PushNotificationContants.Token, regId);
editor.PutInt(PushNotificationKey.AppVersion, appVersion); editor.PutInt(PushNotificationContants.AppVersion, appVersion);
editor.Commit(); editor.Commit();
} }
} }
@ -168,7 +164,7 @@ namespace Bit.Android.Services
var token = instanceID.GetToken(CrossPushNotification.SenderId, var token = instanceID.GetToken(CrossPushNotification.SenderId,
GoogleCloudMessaging.InstanceIdScope, null); GoogleCloudMessaging.InstanceIdScope, null);
CrossPushNotification.PushNotificationListener.OnRegistered(token, Device.Android); CrossPushNotification.PushNotificationListener.OnRegistered(token, Device.Android);
PushNotificationImplementation.StoreRegistrationId(global::Android.App.Application.Context, token); AndroidPushNotificationService.StoreRegistrationId(global::Android.App.Application.Context, token);
SubscribeTopics(token); SubscribeTopics(token);
System.Diagnostics.Debug.WriteLine($"{token} - Device registered, registration ID={Tag}"); System.Diagnostics.Debug.WriteLine($"{token} - Device registered, registration ID={Tag}");
} }
@ -230,7 +226,7 @@ namespace Bit.Android.Services
if(extras != null && !extras.IsEmpty) if(extras != null && !extras.IsEmpty)
{ {
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - GCM Listener - Push Received"); $"{PushNotificationContants.DomainName} - GCM Listener - Push Received");
var parameters = new Dictionary<string, object>(); var parameters = new Dictionary<string, object>();
var values = new JObject(); var values = new JObject();
@ -249,7 +245,7 @@ namespace Bit.Android.Services
parameters.Add(key, extras.Get(key)); parameters.Add(key, extras.Get(key));
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - GCM Listener - Push Params {key} : {extras.Get(key)}"); $"{PushNotificationContants.DomainName} - GCM Listener - Push Params {key} : {extras.Get(key)}");
} }
var context = global::Android.App.Application.Context; var context = global::Android.App.Application.Context;
@ -267,21 +263,21 @@ namespace Bit.Android.Services
{ {
message = parameters[CrossPushNotification.NotificationContentTextKey].ToString(); message = parameters[CrossPushNotification.NotificationContentTextKey].ToString();
} }
else if(parameters.ContainsKey(PushNotificationKey.Alert)) else if(parameters.ContainsKey(PushNotificationContants.Alert))
{ {
message = parameters[PushNotificationKey.Alert].ToString(); message = parameters[PushNotificationContants.Alert].ToString();
} }
else if(parameters.ContainsKey(PushNotificationKey.Message)) else if(parameters.ContainsKey(PushNotificationContants.Message))
{ {
message = parameters[PushNotificationKey.Message].ToString(); message = parameters[PushNotificationContants.Message].ToString();
} }
else if(parameters.ContainsKey(PushNotificationKey.Subtitle)) else if(parameters.ContainsKey(PushNotificationContants.Subtitle))
{ {
message = parameters[PushNotificationKey.Subtitle].ToString(); message = parameters[PushNotificationContants.Subtitle].ToString();
} }
else if(parameters.ContainsKey(PushNotificationKey.Text)) else if(parameters.ContainsKey(PushNotificationContants.Text))
{ {
message = parameters[PushNotificationKey.Text].ToString(); message = parameters[PushNotificationContants.Text].ToString();
} }
if(!string.IsNullOrEmpty(CrossPushNotification.NotificationContentTitleKey) && if(!string.IsNullOrEmpty(CrossPushNotification.NotificationContentTitleKey) &&
@ -289,15 +285,15 @@ namespace Bit.Android.Services
{ {
title = parameters[CrossPushNotification.NotificationContentTitleKey].ToString(); title = parameters[CrossPushNotification.NotificationContentTitleKey].ToString();
} }
else if(parameters.ContainsKey(PushNotificationKey.Title)) else if(parameters.ContainsKey(PushNotificationContants.Title))
{ {
if(!string.IsNullOrEmpty(message)) if(!string.IsNullOrEmpty(message))
{ {
title = parameters[PushNotificationKey.Title].ToString(); title = parameters[PushNotificationContants.Title].ToString();
} }
else else
{ {
message = parameters[PushNotificationKey.Title].ToString(); message = parameters[PushNotificationContants.Title].ToString();
} }
} }
@ -307,7 +303,7 @@ namespace Bit.Android.Services
!string.IsNullOrEmpty(CrossPushNotification.NotificationContentDataKey) && !string.IsNullOrEmpty(CrossPushNotification.NotificationContentDataKey) &&
values[CrossPushNotification.NotificationContentDataKey] != null) ? values[CrossPushNotification.NotificationContentDataKey] != null) ?
values[CrossPushNotification.NotificationContentDataKey] : values[CrossPushNotification.NotificationContentDataKey] :
values[PushNotificationKey.Data]; values[PushNotificationContants.Data];
if(data != null) if(data != null)
{ {
@ -316,21 +312,21 @@ namespace Bit.Android.Services
{ {
message = data[CrossPushNotification.NotificationContentTextKey].ToString(); message = data[CrossPushNotification.NotificationContentTextKey].ToString();
} }
else if(data[PushNotificationKey.Alert] != null) else if(data[PushNotificationContants.Alert] != null)
{ {
message = data[PushNotificationKey.Alert].ToString(); message = data[PushNotificationContants.Alert].ToString();
} }
else if(data[PushNotificationKey.Message] != null) else if(data[PushNotificationContants.Message] != null)
{ {
message = data[PushNotificationKey.Message].ToString(); message = data[PushNotificationContants.Message].ToString();
} }
else if(data[PushNotificationKey.Subtitle] != null) else if(data[PushNotificationContants.Subtitle] != null)
{ {
message = data[PushNotificationKey.Subtitle].ToString(); message = data[PushNotificationContants.Subtitle].ToString();
} }
else if(data[PushNotificationKey.Text] != null) else if(data[PushNotificationContants.Text] != null)
{ {
message = data[PushNotificationKey.Text].ToString(); message = data[PushNotificationContants.Text].ToString();
} }
if(!string.IsNullOrEmpty(CrossPushNotification.NotificationContentTitleKey) && if(!string.IsNullOrEmpty(CrossPushNotification.NotificationContentTitleKey) &&
@ -338,23 +334,23 @@ namespace Bit.Android.Services
{ {
title = data[CrossPushNotification.NotificationContentTitleKey].ToString(); title = data[CrossPushNotification.NotificationContentTitleKey].ToString();
} }
else if(data[PushNotificationKey.Title] != null) else if(data[PushNotificationContants.Title] != null)
{ {
if(!string.IsNullOrEmpty(message)) if(!string.IsNullOrEmpty(message))
{ {
title = data[PushNotificationKey.Title].ToString(); title = data[PushNotificationContants.Title].ToString();
} }
else else
{ {
message = data[PushNotificationKey.Title].ToString(); message = data[PushNotificationContants.Title].ToString();
} }
} }
} }
} }
if(parameters.ContainsKey(PushNotificationKey.Id)) if(parameters.ContainsKey(PushNotificationContants.Id))
{ {
var str = parameters[PushNotificationKey.Id].ToString(); var str = parameters[PushNotificationContants.Id].ToString();
try try
{ {
notifyId = Convert.ToInt32(str); notifyId = Convert.ToInt32(str);
@ -366,13 +362,13 @@ namespace Bit.Android.Services
} }
} }
if(parameters.ContainsKey(PushNotificationKey.Tag)) if(parameters.ContainsKey(PushNotificationContants.Tag))
{ {
tag = parameters[PushNotificationKey.Tag].ToString(); tag = parameters[PushNotificationContants.Tag].ToString();
} }
if(!parameters.ContainsKey(PushNotificationKey.Silent) || if(!parameters.ContainsKey(PushNotificationContants.Silent) ||
!System.Boolean.Parse(parameters[PushNotificationKey.Silent].ToString())) !System.Boolean.Parse(parameters[PushNotificationContants.Silent].ToString()))
{ {
if(CrossPushNotification.PushNotificationListener.ShouldShowNotification()) if(CrossPushNotification.PushNotificationListener.ShouldShowNotification())
{ {
@ -395,7 +391,7 @@ namespace Bit.Android.Services
private void CreateNotification(string title, string message, int notifyId, string tag, Bundle extras) private void CreateNotification(string title, string message, int notifyId, string tag, Bundle extras)
{ {
System.Diagnostics.Debug.WriteLine( System.Diagnostics.Debug.WriteLine(
$"{PushNotificationKey.DomainName} - PushNotification - Message {title} : {message}"); $"{PushNotificationContants.DomainName} - PushNotification - Message {title} : {message}");
NotificationCompat.Builder builder = null; NotificationCompat.Builder builder = null;
var context = global::Android.App.Application.Context; var context = global::Android.App.Application.Context;
@ -480,7 +476,7 @@ namespace Bit.Android.Services
{ } { }
[Service] [Service]
public class PushNotificationService : Service public class AndroidPushService : Service
{ {
public override void OnCreate() public override void OnCreate()
{ {
@ -509,8 +505,8 @@ namespace Bit.Android.Services
internal class CrossPushNotification internal class CrossPushNotification
{ {
private static Lazy<IPushNotification> Implementation = new Lazy<IPushNotification>( private static Lazy<IPushNotificationService> Implementation = new Lazy<IPushNotificationService>(
() => new PushNotificationImplementation(), () => new AndroidPushNotificationService(),
LazyThreadSafetyMode.PublicationOnly); LazyThreadSafetyMode.PublicationOnly);
public static bool IsInitialized => PushNotificationListener != null; public static bool IsInitialized => PushNotificationListener != null;
public static IPushNotificationListener PushNotificationListener { get; private set; } public static IPushNotificationListener PushNotificationListener { get; private set; }
@ -542,7 +538,7 @@ namespace Bit.Android.Services
Initialize(new T(), senderId); Initialize(new T(), senderId);
} }
public static IPushNotification Current public static IPushNotificationService Current
{ {
get get
{ {

View file

@ -1,6 +1,6 @@
namespace Bit.App.Abstractions namespace Bit.App.Abstractions
{ {
public interface IPushNotification public interface IPushNotificationService
{ {
string Token { get; } string Token { get; }
void Register(); void Register();

View file

@ -358,7 +358,7 @@
<Compile Include="Utilities\Extentions.cs" /> <Compile Include="Utilities\Extentions.cs" />
<Compile Include="Utilities\ExtendedObservableCollection.cs" /> <Compile Include="Utilities\ExtendedObservableCollection.cs" />
<Compile Include="Utilities\ApiHttpClient.cs" /> <Compile Include="Utilities\ApiHttpClient.cs" />
<Compile Include="Utilities\PushNotificationKey.cs" /> <Compile Include="Utilities\PushNotificationContants.cs" />
<Compile Include="Utilities\TokenHttpRequestMessage.cs" /> <Compile Include="Utilities\TokenHttpRequestMessage.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -18,7 +18,7 @@ namespace Bit.App.Pages
private ISyncService _syncService; private ISyncService _syncService;
private ISettings _settings; private ISettings _settings;
private IGoogleAnalyticsService _googleAnalyticsService; private IGoogleAnalyticsService _googleAnalyticsService;
private IPushNotification _pushNotification; private IPushNotificationService _pushNotification;
private readonly string _email; private readonly string _email;
public LoginPage(string email = null) public LoginPage(string email = null)
@ -30,7 +30,7 @@ namespace Bit.App.Pages
_syncService = Resolver.Resolve<ISyncService>(); _syncService = Resolver.Resolve<ISyncService>();
_settings = Resolver.Resolve<ISettings>(); _settings = Resolver.Resolve<ISettings>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>(); _googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_pushNotification = Resolver.Resolve<IPushNotification>(); _pushNotification = Resolver.Resolve<IPushNotificationService>();
Init(); Init();
} }

View file

@ -24,7 +24,7 @@ namespace Bit.App.Pages
private IDeviceInfoService _deviceInfoService; private IDeviceInfoService _deviceInfoService;
private IGoogleAnalyticsService _googleAnalyticsService; private IGoogleAnalyticsService _googleAnalyticsService;
private ITwoFactorApiRepository _twoFactorApiRepository; private ITwoFactorApiRepository _twoFactorApiRepository;
private IPushNotification _pushNotification; private IPushNotificationService _pushNotification;
private IAppSettingsService _appSettingsService; private IAppSettingsService _appSettingsService;
private readonly string _email; private readonly string _email;
private readonly string _masterPasswordHash; private readonly string _masterPasswordHash;
@ -51,7 +51,7 @@ namespace Bit.App.Pages
_appSettingsService = Resolver.Resolve<IAppSettingsService>(); _appSettingsService = Resolver.Resolve<IAppSettingsService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>(); _googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_twoFactorApiRepository = Resolver.Resolve<ITwoFactorApiRepository>(); _twoFactorApiRepository = Resolver.Resolve<ITwoFactorApiRepository>();
_pushNotification = Resolver.Resolve<IPushNotification>(); _pushNotification = Resolver.Resolve<IPushNotificationService>();
Init(); Init();
} }

View file

@ -17,7 +17,7 @@ namespace Bit.App.Pages
private readonly IUserDialogs _userDialogs; private readonly IUserDialogs _userDialogs;
private readonly ISettings _settings; private readonly ISettings _settings;
private readonly IFingerprint _fingerprint; private readonly IFingerprint _fingerprint;
private readonly IPushNotification _pushNotification; private readonly IPushNotificationService _pushNotification;
private readonly IGoogleAnalyticsService _googleAnalyticsService; private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly IDeviceInfoService _deviceInfoService; private readonly IDeviceInfoService _deviceInfoService;
@ -29,7 +29,7 @@ namespace Bit.App.Pages
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();
_settings = Resolver.Resolve<ISettings>(); _settings = Resolver.Resolve<ISettings>();
_fingerprint = Resolver.Resolve<IFingerprint>(); _fingerprint = Resolver.Resolve<IFingerprint>();
_pushNotification = Resolver.Resolve<IPushNotification>(); _pushNotification = Resolver.Resolve<IPushNotificationService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>(); _googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>(); _deviceInfoService = Resolver.Resolve<IDeviceInfoService>();

View file

@ -25,7 +25,7 @@ namespace Bit.App.Pages
private readonly IConnectivity _connectivity; private readonly IConnectivity _connectivity;
private readonly IDeviceActionService _clipboardService; private readonly IDeviceActionService _clipboardService;
private readonly ISyncService _syncService; private readonly ISyncService _syncService;
private readonly IPushNotification _pushNotification; private readonly IPushNotificationService _pushNotification;
private readonly IDeviceInfoService _deviceInfoService; private readonly IDeviceInfoService _deviceInfoService;
private readonly ISettings _settings; private readonly ISettings _settings;
private readonly IGoogleAnalyticsService _googleAnalyticsService; private readonly IGoogleAnalyticsService _googleAnalyticsService;
@ -42,7 +42,7 @@ namespace Bit.App.Pages
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();
_clipboardService = Resolver.Resolve<IDeviceActionService>(); _clipboardService = Resolver.Resolve<IDeviceActionService>();
_syncService = Resolver.Resolve<ISyncService>(); _syncService = Resolver.Resolve<ISyncService>();
_pushNotification = Resolver.Resolve<IPushNotification>(); _pushNotification = Resolver.Resolve<IPushNotificationService>();
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>(); _deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
_settings = Resolver.Resolve<ISettings>(); _settings = Resolver.Resolve<ISettings>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>(); _googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();

View file

@ -1,6 +1,6 @@
namespace Bit.App.Utilities namespace Bit.App.Utilities
{ {
public static class PushNotificationKey public static class PushNotificationContants
{ {
/// <summary> /// <summary>
/// Type /// Type

View file

@ -9,7 +9,7 @@ using Xamarin.Forms;
namespace Bit.UWP.Services namespace Bit.UWP.Services
{ {
public class PushNotificationImplementation : IPushNotification public class UwpPushNotificationService : IPushNotificationService
{ {
private PushNotificationChannel _channel; private PushNotificationChannel _channel;
private JsonSerializer serializer = new JsonSerializer() private JsonSerializer serializer = new JsonSerializer()
@ -44,11 +44,9 @@ namespace Bit.UWP.Services
case PushNotificationType.Badge: case PushNotificationType.Badge:
jobject = JObject.FromObject(args.BadgeNotification, serializer); jobject = JObject.FromObject(args.BadgeNotification, serializer);
break; break;
case PushNotificationType.Raw: case PushNotificationType.Raw:
jobject = JObject.FromObject(args.RawNotification, serializer); jobject = JObject.FromObject(args.RawNotification, serializer);
break; break;
case PushNotificationType.Tile: case PushNotificationType.Tile:
jobject = JObject.FromObject(args.TileNotification, serializer); jobject = JObject.FromObject(args.TileNotification, serializer);
break; break;
@ -78,8 +76,8 @@ namespace Bit.UWP.Services
internal class CrossPushNotification internal class CrossPushNotification
{ {
private static Lazy<IPushNotification> Implementation = new Lazy<IPushNotification>( private static Lazy<IPushNotificationService> Implementation = new Lazy<IPushNotificationService>(
() => new PushNotificationImplementation(), () => new UwpPushNotificationService(),
LazyThreadSafetyMode.PublicationOnly); LazyThreadSafetyMode.PublicationOnly);
public static bool IsInitialized => PushNotificationListener != null; public static bool IsInitialized => PushNotificationListener != null;
public static IPushNotificationListener PushNotificationListener { get; private set; } public static IPushNotificationListener PushNotificationListener { get; private set; }
@ -102,7 +100,7 @@ namespace Bit.UWP.Services
Initialize(new T()); Initialize(new T());
} }
public static IPushNotification Current public static IPushNotificationService Current
{ {
get get
{ {

View file

@ -105,7 +105,7 @@
<Compile Include="Services\DeviceInfoService.cs" /> <Compile Include="Services\DeviceInfoService.cs" />
<Compile Include="Services\GoogleAnalyticsService.cs" /> <Compile Include="Services\GoogleAnalyticsService.cs" />
<Compile Include="Services\HttpService.cs" /> <Compile Include="Services\HttpService.cs" />
<Compile Include="Services\PushNotificationImplementation.cs" /> <Compile Include="Services\UwpPushNotificationService.cs" />
<Compile Include="Services\ReflectionService.cs" /> <Compile Include="Services\ReflectionService.cs" />
<Compile Include="Services\SecureStorageService.cs" /> <Compile Include="Services\SecureStorageService.cs" />
<Compile Include="Services\KeyDerivationService.cs" /> <Compile Include="Services\KeyDerivationService.cs" />

View file

@ -11,9 +11,9 @@ using Xamarin.Forms;
namespace Bit.iOS.Services namespace Bit.iOS.Services
{ {
public class PushNotificationImplementation : IPushNotification, IPushNotificationHandler public class iOSPushNotificationService : IPushNotificationService, IPushNotificationHandler
{ {
public string Token => NSUserDefaults.StandardUserDefaults.StringForKey(PushNotificationKey.Token); public string Token => NSUserDefaults.StandardUserDefaults.StringForKey(PushNotificationContants.Token);
public void Register() public void Register()
{ {
@ -65,13 +65,13 @@ namespace Bit.iOS.Services
public void OnErrorReceived(NSError error) public void OnErrorReceived(NSError error)
{ {
Debug.WriteLine("{0} - Registration Failed.", PushNotificationKey.DomainName); Debug.WriteLine("{0} - Registration Failed.", PushNotificationContants.DomainName);
CrossPushNotification.PushNotificationListener.OnError(error.LocalizedDescription, Device.iOS); CrossPushNotification.PushNotificationListener.OnError(error.LocalizedDescription, Device.iOS);
} }
public void OnRegisteredSuccess(NSData token) public void OnRegisteredSuccess(NSData token)
{ {
Debug.WriteLine("{0} - Succesfully Registered.", PushNotificationKey.DomainName); Debug.WriteLine("{0} - Succesfully Registered.", PushNotificationContants.DomainName);
var trimmedDeviceToken = token.Description; var trimmedDeviceToken = token.Description;
if(!string.IsNullOrWhiteSpace(trimmedDeviceToken)) if(!string.IsNullOrWhiteSpace(trimmedDeviceToken))
@ -82,16 +82,16 @@ namespace Bit.iOS.Services
trimmedDeviceToken = trimmedDeviceToken.Replace(" ", ""); trimmedDeviceToken = trimmedDeviceToken.Replace(" ", "");
} }
Console.WriteLine("{0} - Token: {1}", PushNotificationKey.DomainName, trimmedDeviceToken); Console.WriteLine("{0} - Token: {1}", PushNotificationContants.DomainName, trimmedDeviceToken);
CrossPushNotification.PushNotificationListener.OnRegistered(trimmedDeviceToken, Device.iOS); CrossPushNotification.PushNotificationListener.OnRegistered(trimmedDeviceToken, Device.iOS);
NSUserDefaults.StandardUserDefaults.SetString(trimmedDeviceToken, PushNotificationKey.Token); NSUserDefaults.StandardUserDefaults.SetString(trimmedDeviceToken, PushNotificationContants.Token);
NSUserDefaults.StandardUserDefaults.Synchronize(); NSUserDefaults.StandardUserDefaults.Synchronize();
} }
public void OnUnregisteredSuccess() public void OnUnregisteredSuccess()
{ {
CrossPushNotification.PushNotificationListener.OnUnregistered(Device.iOS); CrossPushNotification.PushNotificationListener.OnUnregistered(Device.iOS);
NSUserDefaults.StandardUserDefaults.SetString(string.Empty, PushNotificationKey.Token); NSUserDefaults.StandardUserDefaults.SetString(string.Empty, PushNotificationContants.Token);
NSUserDefaults.StandardUserDefaults.Synchronize(); NSUserDefaults.StandardUserDefaults.Synchronize();
} }
} }
@ -106,8 +106,8 @@ namespace Bit.iOS.Services
internal class CrossPushNotification internal class CrossPushNotification
{ {
private static Lazy<IPushNotification> Implementation = new Lazy<IPushNotification>( private static Lazy<IPushNotificationService> Implementation = new Lazy<IPushNotificationService>(
() => new PushNotificationImplementation(), () => new iOSPushNotificationService(),
LazyThreadSafetyMode.PublicationOnly); LazyThreadSafetyMode.PublicationOnly);
public static bool IsInitialized => PushNotificationListener != null; public static bool IsInitialized => PushNotificationListener != null;
public static IPushNotificationListener PushNotificationListener { get; private set; } public static IPushNotificationListener PushNotificationListener { get; private set; }
@ -130,7 +130,7 @@ namespace Bit.iOS.Services
Initialize(new T()); Initialize(new T());
} }
public static IPushNotification Current public static IPushNotificationService Current
{ {
get get
{ {

View file

@ -238,7 +238,7 @@
<Compile Include="Services\DeviceActionService.cs" /> <Compile Include="Services\DeviceActionService.cs" />
<Compile Include="Main.cs" /> <Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" /> <Compile Include="AppDelegate.cs" />
<Compile Include="Services\PushNotificationImplementation.cs" /> <Compile Include="Services\iOSPushNotificationService.cs" />
<Compile Include="Services\ReflectionService.cs" /> <Compile Include="Services\ReflectionService.cs" />
<None Include="app.config"> <None Include="app.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>