More sync operations with broadcast refreshes of listing pages

This commit is contained in:
Kyle Spearrin 2016-06-30 20:08:34 -04:00
parent acfe0032ef
commit 8fd4e09b78
9 changed files with 117 additions and 6120 deletions

View File

@ -26,6 +26,7 @@ namespace Bit.Android
LoadApplication(new App.App(
Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IDatabaseService>(),
Resolver.Resolve<ISyncService>(),
Resolver.Resolve<IFingerprint>(),
Resolver.Resolve<ISettings>()));
}

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@ namespace Bit.App
public class App : Application
{
private readonly IDatabaseService _databaseService;
private readonly ISyncService _syncService;
private readonly IAuthService _authService;
private readonly IFingerprint _fingerprint;
private readonly ISettings _settings;
@ -23,10 +24,12 @@ namespace Bit.App
public App(
IAuthService authService,
IDatabaseService databaseService,
ISyncService syncService,
IFingerprint fingerprint,
ISettings settings)
{
_databaseService = databaseService;
_syncService = syncService;
_authService = authService;
_fingerprint = fingerprint;
_settings = settings;
@ -42,6 +45,13 @@ namespace Bit.App
MainPage = new HomePage();
}
MessagingCenter.Subscribe<Application, bool>(Current, "Resumed", async (sender, args) =>
{
var syncTask = _syncService.IncrementalSyncAsync();
await CheckLockAsync(args);
await syncTask;
});
MessagingCenter.Subscribe<Application, bool>(Current, "Lock", async (sender, args) =>
{
await CheckLockAsync(args);
@ -51,8 +61,9 @@ namespace Bit.App
protected override void OnStart()
{
// Handle when your app starts
CheckLockAsync(false);
var lockTask = CheckLockAsync(false);
_databaseService.CreateTables();
var syncTask = _syncService.FullSyncAsync();
Debug.WriteLine("OnStart");
}
@ -75,7 +86,7 @@ namespace Bit.App
if(Device.OS == TargetPlatform.Android)
{
CheckLockAsync(false);
var task = CheckLockAsync(false);
}
var lockPinPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage;

View File

@ -67,7 +67,7 @@ namespace Bit.App.Pages
if(_checkFingerprintImmediately)
{
CheckFingerprintAsync();
var task = CheckFingerprintAsync();
}
}

View File

@ -19,6 +19,7 @@ namespace Bit.App.Pages
private IDeviceInfo _deviceInfo;
private IAppIdService _appIdService;
private IUserDialogs _userDialogs;
private ISyncService _syncService;
public LoginPage()
{
@ -27,6 +28,7 @@ namespace Bit.App.Pages
_deviceInfo = Resolver.Resolve<IDeviceInfo>();
_appIdService = Resolver.Resolve<IAppIdService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_syncService = Resolver.Resolve<ISyncService>();
Init();
}
@ -125,6 +127,7 @@ namespace Bit.App.Pages
_authService.Token = response.Result.Token;
_authService.UserId = response.Result.Profile.Id;
var syncTask = _syncService.FullSyncAsync();
Application.Current.MainPage = new MainPage();
}
}

View File

@ -42,6 +42,11 @@ namespace Bit.App.Pages
private void Init()
{
MessagingCenter.Subscribe<Application>(Application.Current, "SyncCompleted", async (sender) =>
{
await LoadFoldersAsync();
});
if(!_favorites)
{
ToolbarItems.Add(new AddSiteToolBarItem(this));

View File

@ -55,7 +55,7 @@ namespace Bit.App.Repositories
var requestMessage = new TokenHttpRequestMessage()
{
Method = HttpMethod.Get,
RequestUri = new Uri(Client.BaseAddress, string.Concat(ApiRoute, "?since=", since)),
RequestUri = new Uri(Client.BaseAddress, string.Concat(ApiRoute, "/history", "?since=", since)),
};
var response = await Client.SendAsync(requestMessage);

View File

@ -6,6 +6,7 @@ using Bit.App.Models.Data;
using Plugin.Settings.Abstractions;
using Bit.App.Models.Api;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Bit.App.Services
{
@ -82,6 +83,7 @@ namespace Bit.App.Services
return false;
}
BroadcastSyncCompleted();
return true;
}
@ -93,6 +95,7 @@ namespace Bit.App.Services
}
await _folderRepository.DeleteAsync(id);
BroadcastSyncCompleted();
return true;
}
@ -104,6 +107,7 @@ namespace Bit.App.Services
}
await _siteRepository.DeleteAsync(id);
BroadcastSyncCompleted();
return true;
}
@ -131,6 +135,7 @@ namespace Bit.App.Services
}
_settings.AddOrUpdateValue(LastSyncKey, now);
BroadcastSyncCompleted();
return true;
}
@ -165,6 +170,7 @@ namespace Bit.App.Services
}
_settings.AddOrUpdateValue(LastSyncKey, now);
BroadcastSyncCompleted();
return true;
}
@ -238,5 +244,10 @@ namespace Bit.App.Services
}
await Task.WhenAll(tasks);
}
private void BroadcastSyncCompleted()
{
MessagingCenter.Send(Application.Current, "SyncCompleted");
}
}
}

View File

@ -44,6 +44,7 @@ namespace Bit.iOS
LoadApplication(new App.App(
Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IDatabaseService>(),
Resolver.Resolve<ISyncService>(),
Resolver.Resolve<IFingerprint>(),
Resolver.Resolve<ISettings>()));
@ -112,7 +113,7 @@ namespace Bit.iOS
public override void WillEnterForeground(UIApplication uiApplication)
{
SendLockMessage();
SendResumedMessage();
base.WillEnterForeground(uiApplication);
Debug.WriteLine("WillEnterForeground");
}
@ -159,9 +160,9 @@ namespace Bit.iOS
}
}
private void SendLockMessage()
private void SendResumedMessage()
{
MessagingCenter.Send(Xamarin.Forms.Application.Current, "Lock", false);
MessagingCenter.Send(Xamarin.Forms.Application.Current, "Resumed", false);
}
private void SetIoc()