From 3f8f29dfe76bfe47fe0067a7b2a3c69150d372a6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 30 May 2019 00:29:00 -0400 Subject: [PATCH] secondary menu on groupings page --- src/Android/MainActivity.cs | 10 ++++++ .../Vault/GroupingsPage/GroupingsPage.xaml | 7 ++++ .../Vault/GroupingsPage/GroupingsPage.xaml.cs | 20 +++++++++++ .../GroupingsPage/GroupingsPageViewModel.cs | 34 ++++++++++++++++++- src/App/Resources/AppResources.Designer.cs | 18 ++++++++++ src/App/Resources/AppResources.resx | 6 ++++ 6 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index 669e91870..0f2d5bc61 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -101,6 +101,10 @@ namespace Bit.Droid { RestartApp(); } + else if(message.Command == "exit") + { + ExitApp(); + } }); } @@ -283,5 +287,11 @@ namespace Bit.Droid alarmManager.Set(AlarmType.Rtc, triggerMs, pendingIntent); Java.Lang.JavaSystem.Exit(0); } + + private void ExitApp() + { + FinishAffinity(); + Java.Lang.JavaSystem.Exit(0); + } } } diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml index 1afa5d2c7..451e11b43 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml @@ -20,6 +20,13 @@ + + + + ("syncService"); _pushNotificationService = ServiceContainer.Resolve("pushNotificationService"); _storageService = ServiceContainer.Resolve("storageService"); + _lockService = ServiceContainer.Resolve("lockService"); _vm = BindingContext as GroupingsPageViewModel; _vm.Page = this; _vm.MainPage = mainPage; @@ -47,6 +49,9 @@ namespace Bit.App.Pages else { _fab.Clicked = AddButton_Clicked; + ToolbarItems.Add(_syncItem); + ToolbarItems.Add(_lockItem); + ToolbarItems.Add(_exitItem); } } @@ -149,6 +154,21 @@ namespace Bit.App.Pages } } + private async void Sync_Clicked(object sender, System.EventArgs e) + { + await _vm.SyncAsync(); + } + + private async void Lock_Clicked(object sender, System.EventArgs e) + { + await _lockService.LockAsync(true); + } + + private async void Exit_Clicked(object sender, System.EventArgs e) + { + await _vm.ExitAsync(); + } + private async void AddButton_Clicked(object sender, System.EventArgs e) { var page = new AddEditPage(null, _vm.Type, _vm.FolderId, _vm.CollectionId); diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs b/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs index ef0770e2d..946bfe89e 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs @@ -1,4 +1,5 @@ -using Bit.App.Resources; +using Bit.App.Abstractions; +using Bit.App.Resources; using Bit.App.Utilities; using Bit.Core.Abstractions; using Bit.Core.Enums; @@ -32,6 +33,9 @@ namespace Bit.App.Pages private readonly IFolderService _folderService; private readonly ICollectionService _collectionService; private readonly ISyncService _syncService; + private readonly IDeviceActionService _deviceActionService; + private readonly IPlatformUtilsService _platformUtilsService; + private readonly IMessagingService _messagingService; public GroupingsPageViewModel() { @@ -39,6 +43,9 @@ namespace Bit.App.Pages _folderService = ServiceContainer.Resolve("folderService"); _collectionService = ServiceContainer.Resolve("collectionService"); _syncService = ServiceContainer.Resolve("syncService"); + _deviceActionService = ServiceContainer.Resolve("deviceActionService"); + _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); + _messagingService = ServiceContainer.Resolve("messagingService"); Loading = true; PageTitle = AppResources.MyVault; @@ -248,6 +255,31 @@ namespace Bit.App.Pages await Page.Navigation.PushAsync(page); } + public async Task ExitAsync() + { + var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.ExitConfirmation, + AppResources.Exit, AppResources.Yes, AppResources.Cancel); + if(confirmed) + { + _messagingService.Send("exit"); + } + } + + public async Task SyncAsync() + { + await _deviceActionService.ShowLoadingAsync(AppResources.Syncing); + var success = await _syncService.FullSyncAsync(false); + await _deviceActionService.HideLoadingAsync(); + if(success) + { + _platformUtilsService.ShowToast("success", null, AppResources.SyncingComplete); + } + else + { + await Page.DisplayAlert(null, AppResources.SyncingFailed, AppResources.Ok); + } + } + private async Task LoadDataAsync() { NoDataText = AppResources.NoItems; diff --git a/src/App/Resources/AppResources.Designer.cs b/src/App/Resources/AppResources.Designer.cs index fa82442b5..3a6872353 100644 --- a/src/App/Resources/AppResources.Designer.cs +++ b/src/App/Resources/AppResources.Designer.cs @@ -1401,6 +1401,24 @@ namespace Bit.App.Resources { } } + /// + /// Looks up a localized string similar to Exit. + /// + public static string Exit { + get { + return ResourceManager.GetString("Exit", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Are you sure you want to exit Bitwarden?. + /// + public static string ExitConfirmation { + get { + return ResourceManager.GetString("ExitConfirmation", resourceCulture); + } + } + /// /// Looks up a localized string similar to Re-enable App Extension. /// diff --git a/src/App/Resources/AppResources.resx b/src/App/Resources/AppResources.resx index dbd110e16..ddae8f37a 100644 --- a/src/App/Resources/AppResources.resx +++ b/src/App/Resources/AppResources.resx @@ -1567,4 +1567,10 @@ Copy Notes + + Exit + + + Are you sure you want to exit Bitwarden? + \ No newline at end of file