1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-15 07:43:37 +00:00

register android push on my vault page too

This commit is contained in:
Kyle Spearrin
2017-12-21 22:27:25 -05:00
parent 582e6ee322
commit c34376820a
2 changed files with 37 additions and 23 deletions

View File

@@ -28,6 +28,10 @@ namespace Bit.Android.Services
{ {
_pushNotificationListener.OnRegistered(registeredToken, Device.Android); _pushNotificationListener.OnRegistered(registeredToken, Device.Android);
} }
else
{
_settings.AddOrUpdateValue(Constants.PushLastRegistrationDate, DateTime.UtcNow);
}
} }
public void Unregister() public void Unregister()

View File

@@ -136,34 +136,44 @@ namespace Bit.App.Pages
_filterResultsCancellationTokenSource = FetchAndLoadVault(); _filterResultsCancellationTokenSource = FetchAndLoadVault();
if(_connectivity.IsConnected && Device.RuntimePlatform == Device.iOS) // Push registration
if(_connectivity.IsConnected)
{ {
var pushPromptShow = _settings.GetValueOrDefault(Constants.PushInitialPromptShown, false); var lastPushRegistration = _settings.GetValueOrDefault(Constants.PushLastRegistrationDate,
Action registerAction = () => DateTime.MinValue);
{
var lastPushRegistration =
_settings.GetValueOrDefault(Constants.PushLastRegistrationDate, DateTime.MinValue);
if(!pushPromptShow || DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1))
{
_pushNotification.Register();
}
};
if(!pushPromptShow) if(Device.RuntimePlatform == Device.iOS)
{ {
_settings.AddOrUpdateValue(Constants.PushInitialPromptShown, true); var pushPromptShow = _settings.GetValueOrDefault(Constants.PushInitialPromptShown, false);
_userDialogs.Alert(new AlertConfig Action registerAction = () =>
{ {
Message = AppResources.PushNotificationAlert, if(!pushPromptShow || DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1))
Title = AppResources.EnableAutomaticSyncing, {
OnAction = registerAction, _pushNotification.Register();
OkText = AppResources.OkGotIt }
}); };
if(!pushPromptShow)
{
_settings.AddOrUpdateValue(Constants.PushInitialPromptShown, true);
_userDialogs.Alert(new AlertConfig
{
Message = AppResources.PushNotificationAlert,
Title = AppResources.EnableAutomaticSyncing,
OnAction = registerAction,
OkText = AppResources.OkGotIt
});
}
else
{
// Check push registration once per day
registerAction();
}
} }
else else if(Device.RuntimePlatform == Device.Android &&
DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1))
{ {
// Check push registration once per day _pushNotification.Register();
registerAction();
} }
} }
} }
@@ -230,7 +240,7 @@ namespace Bit.App.Pages
if(collections.Any()) if(collections.Any())
{ {
folderGroupings.Add(new GroupingOrCipher(new Grouping(AppResources.FolderNone, folderGroupings.Add(new GroupingOrCipher(new Grouping(AppResources.FolderNone,
noFolderCipherGroupings.Count))); noFolderCipherGroupings.Count)));
} }