mirror of
https://github.com/bitwarden/android.git
synced 2024-12-21 08:42:39 +03:00
Android styling. Invoke lock and isbusy updates on main UI thread. ConfigureAwaits in sync service.
This commit is contained in:
parent
189c56342a
commit
ca4a00196a
9 changed files with 51 additions and 38 deletions
|
@ -21,11 +21,14 @@ namespace Bit.Android.Controls
|
||||||
base.OnElementChanged(e);
|
base.OnElementChanged(e);
|
||||||
|
|
||||||
var view = (ExtendedEntry)Element;
|
var view = (ExtendedEntry)Element;
|
||||||
|
if(Control != null)
|
||||||
if(Control != null && e.NewElement != null && e.NewElement.IsPassword)
|
|
||||||
{
|
{
|
||||||
Control.SetTypeface(Typeface.Default, TypefaceStyle.Normal);
|
Control.SetIncludeFontPadding(false);
|
||||||
Control.TransformationMethod = new PasswordTransformationMethod();
|
if(e.NewElement != null && e.NewElement.IsPassword)
|
||||||
|
{
|
||||||
|
Control.SetTypeface(Typeface.Default, TypefaceStyle.Normal);
|
||||||
|
Control.TransformationMethod = new PasswordTransformationMethod();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBorder(view);
|
SetBorder(view);
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
<color name="lightgray">#efeff4</color>
|
<color name="lightgray">#efeff4</color>
|
||||||
<color name="primary">#3c8dbc</color>
|
<color name="primary">#3c8dbc</color>
|
||||||
<color name="darkaccent">#222d32</color>
|
<color name="darkaccent">#222d32</color>
|
||||||
<color name="accent">#286090</color>
|
<color name="accent">#3883af</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -71,9 +71,9 @@ namespace Bit.App
|
||||||
await Task.Run(() => IncrementalSyncAsync()).ConfigureAwait(false);
|
await Task.Run(() => IncrementalSyncAsync()).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
MessagingCenter.Subscribe<Application, bool>(Current, "Lock", async (sender, args) =>
|
MessagingCenter.Subscribe<Application, bool>(Current, "Lock", (sender, args) =>
|
||||||
{
|
{
|
||||||
await CheckLockAsync(args);
|
Device.BeginInvokeOnMainThread(async () => await CheckLockAsync(args));
|
||||||
});
|
});
|
||||||
|
|
||||||
MessagingCenter.Subscribe<Application, string>(Current, "Logout", (sender, args) =>
|
MessagingCenter.Subscribe<Application, string>(Current, "Logout", (sender, args) =>
|
||||||
|
@ -129,7 +129,7 @@ namespace Bit.App
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _syncService.IncrementalSyncAsync(TimeSpan.FromMinutes(30));
|
await _syncService.IncrementalSyncAsync(TimeSpan.FromMinutes(30)).ConfigureAwait(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch(WebException)
|
catch(WebException)
|
||||||
|
@ -162,7 +162,7 @@ namespace Bit.App
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _syncService.FullSyncAsync();
|
await _syncService.FullSyncAsync().ConfigureAwait(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch(WebException)
|
catch(WebException)
|
||||||
|
|
|
@ -28,12 +28,12 @@ namespace Bit.App.Controls
|
||||||
{
|
{
|
||||||
MessagingCenter.Subscribe<Application, bool>(Application.Current, "SyncCompleted", (sender, success) =>
|
MessagingCenter.Subscribe<Application, bool>(Application.Current, "SyncCompleted", (sender, success) =>
|
||||||
{
|
{
|
||||||
IsBusy = _syncService.SyncInProgress;
|
Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress);
|
||||||
});
|
});
|
||||||
|
|
||||||
MessagingCenter.Subscribe<Application>(Application.Current, "SyncStarted", (sender) =>
|
MessagingCenter.Subscribe<Application>(Application.Current, "SyncStarted", (sender) =>
|
||||||
{
|
{
|
||||||
IsBusy = _syncService.SyncInProgress;
|
Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,11 @@ namespace Bit.App.Controls
|
||||||
if(Device.OS == TargetPlatform.Android)
|
if(Device.OS == TargetPlatform.Android)
|
||||||
{
|
{
|
||||||
Entry.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
|
Entry.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
|
||||||
Entry.TextColor = Color.Black;
|
|
||||||
formStackLayout.Spacing = 0;
|
formStackLayout.Spacing = 0;
|
||||||
|
if(!useLabelAsPlaceholder)
|
||||||
|
{
|
||||||
|
Entry.Margin = new Thickness(-4, -2, -4, -10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!useLabelAsPlaceholder)
|
if(!useLabelAsPlaceholder)
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
|
|
|
@ -33,8 +33,13 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
|
var padding = Device.OnPlatform(
|
||||||
|
iOS: new Thickness(15, 20),
|
||||||
|
Android: new Thickness(15, 8),
|
||||||
|
WinPhone: new Thickness(15, 20));
|
||||||
|
|
||||||
PasswordCell = new FormEntryCell(AppResources.MasterPassword, IsPassword: true,
|
PasswordCell = new FormEntryCell(AppResources.MasterPassword, IsPassword: true,
|
||||||
useLabelAsPlaceholder: true, imageSource: "lock");
|
useLabelAsPlaceholder: true, imageSource: "lock", containerPadding: padding);
|
||||||
|
|
||||||
PasswordCell.Entry.ReturnType = Enums.ReturnType.Go;
|
PasswordCell.Entry.ReturnType = Enums.ReturnType.Go;
|
||||||
PasswordCell.Entry.Completed += Entry_Completed;
|
PasswordCell.Entry.Completed += Entry_Completed;
|
||||||
|
@ -87,7 +92,7 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
SyncStarted();
|
SyncStarted();
|
||||||
|
|
||||||
var cipher = await _cipherApiRepository.GetByIdAsync(id);
|
var cipher = await _cipherApiRepository.GetByIdAsync(id).ConfigureAwait(false);
|
||||||
if(!cipher.Succeeded)
|
if(!cipher.Succeeded)
|
||||||
{
|
{
|
||||||
SyncCompleted(false);
|
SyncCompleted(false);
|
||||||
|
@ -70,11 +70,11 @@ namespace Bit.App.Services
|
||||||
var existingLocalFolder = _folderRepository.GetByIdAsync(id);
|
var existingLocalFolder = _folderRepository.GetByIdAsync(id);
|
||||||
if(existingLocalFolder == null)
|
if(existingLocalFolder == null)
|
||||||
{
|
{
|
||||||
await _folderRepository.InsertAsync(folderData);
|
await _folderRepository.InsertAsync(folderData).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _folderRepository.UpdateAsync(folderData);
|
await _folderRepository.UpdateAsync(folderData).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Enums.CipherType.Site:
|
case Enums.CipherType.Site:
|
||||||
|
@ -82,11 +82,11 @@ namespace Bit.App.Services
|
||||||
var existingLocalSite = _siteRepository.GetByIdAsync(id);
|
var existingLocalSite = _siteRepository.GetByIdAsync(id);
|
||||||
if(existingLocalSite == null)
|
if(existingLocalSite == null)
|
||||||
{
|
{
|
||||||
await _siteRepository.InsertAsync(siteData);
|
await _siteRepository.InsertAsync(siteData).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _siteRepository.UpdateAsync(siteData);
|
await _siteRepository.UpdateAsync(siteData).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -107,7 +107,7 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
SyncStarted();
|
SyncStarted();
|
||||||
|
|
||||||
await _folderRepository.DeleteWithSiteUpdateAsync(id, revisionDate);
|
await _folderRepository.DeleteWithSiteUpdateAsync(id, revisionDate).ConfigureAwait(false);
|
||||||
SyncCompleted(true);
|
SyncCompleted(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
SyncStarted();
|
SyncStarted();
|
||||||
|
|
||||||
await _siteRepository.DeleteAsync(id);
|
await _siteRepository.DeleteAsync(id).ConfigureAwait(false);
|
||||||
SyncCompleted(true);
|
SyncCompleted(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ namespace Bit.App.Services
|
||||||
SyncStarted();
|
SyncStarted();
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
var ciphers = await _cipherApiRepository.GetAsync();
|
var ciphers = await _cipherApiRepository.GetAsync().ConfigureAwait(false);
|
||||||
if(!ciphers.Succeeded)
|
if(!ciphers.Succeeded)
|
||||||
{
|
{
|
||||||
SyncCompleted(false);
|
SyncCompleted(false);
|
||||||
|
@ -155,7 +155,7 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
var siteTask = SyncSitesAsync(sites, true);
|
var siteTask = SyncSitesAsync(sites, true);
|
||||||
var folderTask = SyncFoldersAsync(folders, true);
|
var folderTask = SyncFoldersAsync(folders, true);
|
||||||
await Task.WhenAll(siteTask, folderTask);
|
await Task.WhenAll(siteTask, folderTask).ConfigureAwait(false);
|
||||||
|
|
||||||
if(folderTask.Exception != null || siteTask.Exception != null)
|
if(folderTask.Exception != null || siteTask.Exception != null)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ namespace Bit.App.Services
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await IncrementalSyncAsync();
|
return await IncrementalSyncAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IncrementalSyncAsync()
|
public async Task<bool> IncrementalSyncAsync()
|
||||||
|
@ -190,12 +190,12 @@ namespace Bit.App.Services
|
||||||
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.LastSync);
|
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.LastSync);
|
||||||
if(lastSync == null)
|
if(lastSync == null)
|
||||||
{
|
{
|
||||||
return await FullSyncAsync();
|
return await FullSyncAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncStarted();
|
SyncStarted();
|
||||||
|
|
||||||
var ciphers = await _cipherApiRepository.GetByRevisionDateWithHistoryAsync(lastSync.Value);
|
var ciphers = await _cipherApiRepository.GetByRevisionDateWithHistoryAsync(lastSync.Value).ConfigureAwait(false);
|
||||||
if(!ciphers.Succeeded)
|
if(!ciphers.Succeeded)
|
||||||
{
|
{
|
||||||
SyncCompleted(false);
|
SyncCompleted(false);
|
||||||
|
@ -216,7 +216,7 @@ namespace Bit.App.Services
|
||||||
var folderTask = SyncFoldersAsync(folders, false);
|
var folderTask = SyncFoldersAsync(folders, false);
|
||||||
var deleteTask = DeleteCiphersAsync(ciphers.Result.Deleted);
|
var deleteTask = DeleteCiphersAsync(ciphers.Result.Deleted);
|
||||||
|
|
||||||
await Task.WhenAll(siteTask, folderTask, deleteTask);
|
await Task.WhenAll(siteTask, folderTask, deleteTask).ConfigureAwait(false);
|
||||||
if(folderTask.Exception != null || siteTask.Exception != null || deleteTask.Exception != null)
|
if(folderTask.Exception != null || siteTask.Exception != null || deleteTask.Exception != null)
|
||||||
{
|
{
|
||||||
SyncCompleted(false);
|
SyncCompleted(false);
|
||||||
|
@ -235,7 +235,8 @@ namespace Bit.App.Services
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var localFolders = (await _folderRepository.GetAllByUserIdAsync(_authService.UserId)).ToDictionary(f => f.Id);
|
var localFolders = (await _folderRepository.GetAllByUserIdAsync(_authService.UserId).ConfigureAwait(false))
|
||||||
|
.ToDictionary(f => f.Id);
|
||||||
|
|
||||||
foreach(var serverFolder in serverFolders)
|
foreach(var serverFolder in serverFolders)
|
||||||
{
|
{
|
||||||
|
@ -248,12 +249,12 @@ namespace Bit.App.Services
|
||||||
if(existingLocalFolder == null)
|
if(existingLocalFolder == null)
|
||||||
{
|
{
|
||||||
var data = new FolderData(serverFolder.Value, _authService.UserId);
|
var data = new FolderData(serverFolder.Value, _authService.UserId);
|
||||||
await _folderRepository.InsertAsync(data);
|
await _folderRepository.InsertAsync(data).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if(existingLocalFolder.RevisionDateTime != serverFolder.Value.RevisionDate)
|
else if(existingLocalFolder.RevisionDateTime != serverFolder.Value.RevisionDate)
|
||||||
{
|
{
|
||||||
var data = new FolderData(serverFolder.Value, _authService.UserId);
|
var data = new FolderData(serverFolder.Value, _authService.UserId);
|
||||||
await _folderRepository.UpdateAsync(data);
|
await _folderRepository.UpdateAsync(data).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +265,7 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
foreach(var folder in localFolders.Where(localFolder => !serverFolders.ContainsKey(localFolder.Key)))
|
foreach(var folder in localFolders.Where(localFolder => !serverFolders.ContainsKey(localFolder.Key)))
|
||||||
{
|
{
|
||||||
await _folderRepository.DeleteAsync(folder.Value.Id);
|
await _folderRepository.DeleteAsync(folder.Value.Id).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +276,8 @@ namespace Bit.App.Services
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var localSites = (await _siteRepository.GetAllByUserIdAsync(_authService.UserId)).ToDictionary(s => s.Id);
|
var localSites = (await _siteRepository.GetAllByUserIdAsync(_authService.UserId).ConfigureAwait(false))
|
||||||
|
.ToDictionary(s => s.Id);
|
||||||
|
|
||||||
foreach(var serverSite in serverSites)
|
foreach(var serverSite in serverSites)
|
||||||
{
|
{
|
||||||
|
@ -288,12 +290,12 @@ namespace Bit.App.Services
|
||||||
if(existingLocalSite == null)
|
if(existingLocalSite == null)
|
||||||
{
|
{
|
||||||
var data = new SiteData(serverSite.Value, _authService.UserId);
|
var data = new SiteData(serverSite.Value, _authService.UserId);
|
||||||
await _siteRepository.InsertAsync(data);
|
await _siteRepository.InsertAsync(data).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if(existingLocalSite.RevisionDateTime != serverSite.Value.RevisionDate)
|
else if(existingLocalSite.RevisionDateTime != serverSite.Value.RevisionDate)
|
||||||
{
|
{
|
||||||
var data = new SiteData(serverSite.Value, _authService.UserId);
|
var data = new SiteData(serverSite.Value, _authService.UserId);
|
||||||
await _siteRepository.UpdateAsync(data);
|
await _siteRepository.UpdateAsync(data).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +306,7 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
foreach(var site in localSites.Where(localSite => !serverSites.ContainsKey(localSite.Key)))
|
foreach(var site in localSites.Where(localSite => !serverSites.ContainsKey(localSite.Key)))
|
||||||
{
|
{
|
||||||
await _siteRepository.DeleteAsync(site.Value.Id);
|
await _siteRepository.DeleteAsync(site.Value.Id).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +323,7 @@ namespace Bit.App.Services
|
||||||
tasks.Add(_siteRepository.DeleteAsync(cipherId));
|
tasks.Add(_siteRepository.DeleteAsync(cipherId));
|
||||||
tasks.Add(_folderRepository.DeleteAsync(cipherId));
|
tasks.Add(_folderRepository.DeleteAsync(cipherId));
|
||||||
}
|
}
|
||||||
await Task.WhenAll(tasks);
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SyncStarted()
|
private void SyncStarted()
|
||||||
|
|
Loading…
Reference in a new issue