1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-17 15:27:43 +01:00

load previous view/edit page after lock

This commit is contained in:
Kyle Spearrin 2019-07-31 16:50:16 -04:00
parent d91d71333b
commit 67c6cf6b8c
9 changed files with 108 additions and 34 deletions

View File

@ -36,7 +36,6 @@ namespace Bit.Droid
private IUserService _userService; private IUserService _userService;
private IAppIdService _appIdService; private IAppIdService _appIdService;
private IStorageService _storageService; private IStorageService _storageService;
private IStateService _stateService;
private IEventService _eventService; private IEventService _eventService;
private PendingIntent _lockAlarmPendingIntent; private PendingIntent _lockAlarmPendingIntent;
private PendingIntent _clearClipboardPendingIntent; private PendingIntent _clearClipboardPendingIntent;
@ -67,7 +66,6 @@ namespace Bit.Droid
_userService = ServiceContainer.Resolve<IUserService>("userService"); _userService = ServiceContainer.Resolve<IUserService>("userService");
_appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService"); _appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService");
_storageService = ServiceContainer.Resolve<IStorageService>("storageService"); _storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
_eventService = ServiceContainer.Resolve<IEventService>("eventService"); _eventService = ServiceContainer.Resolve<IEventService>("eventService");
TabLayoutResource = Resource.Layout.Tabbar; TabLayoutResource = Resource.Layout.Tabbar;

View File

@ -89,18 +89,7 @@ namespace Bit.App
} }
else if(message.Command == "locked") else if(message.Command == "locked")
{ {
await _stateService.PurgeAsync(); await LockedAsync(!(message.Data as bool?).GetValueOrDefault());
var autoPromptFingerprint = !(message.Data as bool?).GetValueOrDefault();
if(autoPromptFingerprint && Device.RuntimePlatform == Device.iOS)
{
var lockOptions = await _storageService.GetAsync<int?>(Constants.LockOptionKey);
if(lockOptions == 0)
{
autoPromptFingerprint = false;
}
}
var lockPage = new LockPage(_appOptions, autoPromptFingerprint);
Device.BeginInvokeOnMainThread(() => Current.MainPage = new NavigationPage(lockPage));
} }
else if(message.Command == "lockVault") else if(message.Command == "lockVault")
{ {
@ -398,5 +387,45 @@ namespace Bit.App
await _storageService.RemoveAsync(Constants.ClearCiphersCacheKey); await _storageService.RemoveAsync(Constants.ClearCiphersCacheKey);
} }
} }
private async Task LockedAsync(bool autoPromptFingerprint)
{
await _stateService.PurgeAsync();
if(autoPromptFingerprint && Device.RuntimePlatform == Device.iOS)
{
var lockOptions = await _storageService.GetAsync<int?>(Constants.LockOptionKey);
if(lockOptions == 0)
{
autoPromptFingerprint = false;
}
}
PreviousPageInfo lastPageBeforeLock = null;
if(Current.MainPage is TabbedPage tabbedPage && tabbedPage.Navigation.ModalStack.Count > 0)
{
var topPage = tabbedPage.Navigation.ModalStack[tabbedPage.Navigation.ModalStack.Count - 1];
if(topPage is NavigationPage navPage)
{
if(navPage.CurrentPage is ViewPage viewPage)
{
lastPageBeforeLock = new PreviousPageInfo
{
Page = "view",
CipherId = viewPage.ViewModel.CipherId
};
}
else if(navPage.CurrentPage is AddEditPage addEditPage && addEditPage.ViewModel.EditMode)
{
lastPageBeforeLock = new PreviousPageInfo
{
Page = "edit",
CipherId = addEditPage.ViewModel.CipherId
};
}
}
}
await _storageService.SaveAsync(Constants.PreviousPageKey, lastPageBeforeLock);
var lockPage = new LockPage(_appOptions, autoPromptFingerprint);
Device.BeginInvokeOnMainThread(() => Current.MainPage = new NavigationPage(lockPage));
}
} }
} }

View File

@ -0,0 +1,9 @@
namespace Bit.App.Models
{
public class PreviousPageInfo
{
public string Page { get; set; }
public string CipherId { get; set; }
public string SearchText { get; set; }
}
}

View File

@ -1,4 +1,7 @@
using Bit.App.Models; using Bit.App.Models;
using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xamarin.Forms; using Xamarin.Forms;
@ -7,6 +10,7 @@ namespace Bit.App.Pages
{ {
public partial class LockPage : BaseContentPage public partial class LockPage : BaseContentPage
{ {
private readonly IStorageService _storageService;
private readonly AppOptions _appOptions; private readonly AppOptions _appOptions;
private readonly bool _autoPromptFingerprint; private readonly bool _autoPromptFingerprint;
private readonly LockPageViewModel _vm; private readonly LockPageViewModel _vm;
@ -16,28 +20,13 @@ namespace Bit.App.Pages
public LockPage(AppOptions appOptions = null, bool autoPromptFingerprint = true) public LockPage(AppOptions appOptions = null, bool autoPromptFingerprint = true)
{ {
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_appOptions = appOptions; _appOptions = appOptions;
_autoPromptFingerprint = autoPromptFingerprint; _autoPromptFingerprint = autoPromptFingerprint;
InitializeComponent(); InitializeComponent();
_vm = BindingContext as LockPageViewModel; _vm = BindingContext as LockPageViewModel;
_vm.Page = this; _vm.Page = this;
_vm.UnlockedAction = () => Device.BeginInvokeOnMainThread(() => _vm.UnlockedAction = () => Device.BeginInvokeOnMainThread(async () => await UnlockedAsync());
{
if(_appOptions != null)
{
if(_appOptions.FromAutofillFramework && _appOptions.SaveType.HasValue)
{
Application.Current.MainPage = new NavigationPage(new AddEditPage(appOptions: _appOptions));
return;
}
else if(_appOptions.Uri != null)
{
Application.Current.MainPage = new NavigationPage(new AutofillCiphersPage(_appOptions));
return;
}
}
Application.Current.MainPage = new TabsPage(_appOptions);
});
MasterPasswordEntry = _masterPassword; MasterPasswordEntry = _masterPassword;
PinEntry = _pin; PinEntry = _pin;
} }
@ -107,5 +96,28 @@ namespace Bit.App.Pages
await _vm.PromptFingerprintAsync(); await _vm.PromptFingerprintAsync();
} }
} }
private async Task UnlockedAsync()
{
if(_appOptions != null)
{
if(_appOptions.FromAutofillFramework && _appOptions.SaveType.HasValue)
{
Application.Current.MainPage = new NavigationPage(new AddEditPage(appOptions: _appOptions));
return;
}
else if(_appOptions.Uri != null)
{
Application.Current.MainPage = new NavigationPage(new AutofillCiphersPage(_appOptions));
return;
}
}
var previousPage = await _storageService.GetAsync<PreviousPageInfo>(Constants.PreviousPageKey);
if(previousPage != null)
{
await _storageService.RemoveAsync(Constants.PreviousPageKey);
}
Application.Current.MainPage = new TabsPage(_appOptions, previousPage);
}
} }
} }

View File

@ -10,9 +10,9 @@ namespace Bit.App.Pages
private NavigationPage _groupingsPage; private NavigationPage _groupingsPage;
private NavigationPage _generatorPage; private NavigationPage _generatorPage;
public TabsPage(AppOptions appOptions = null) public TabsPage(AppOptions appOptions = null, PreviousPageInfo previousPage = null)
{ {
_groupingsPage = new NavigationPage(new GroupingsPage(true)) _groupingsPage = new NavigationPage(new GroupingsPage(true, previousPage: previousPage))
{ {
Title = AppResources.MyVault, Title = AppResources.MyVault,
Icon = "lock.png" Icon = "lock.png"

View File

@ -131,6 +131,7 @@ namespace Bit.App.Pages
} }
public bool FromAutofillFramework { get; set; } public bool FromAutofillFramework { get; set; }
public AddEditPageViewModel ViewModel => _vm;
protected override async void OnAppearing() protected override async void OnAppearing()
{ {

View File

@ -1,5 +1,6 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Controls; using Bit.App.Controls;
using Bit.App.Models;
using Bit.App.Resources; using Bit.App.Resources;
using Bit.Core; using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
@ -22,8 +23,10 @@ namespace Bit.App.Pages
private readonly GroupingsPageViewModel _vm; private readonly GroupingsPageViewModel _vm;
private readonly string _pageName; private readonly string _pageName;
private PreviousPageInfo _previousPage;
public GroupingsPage(bool mainPage, CipherType? type = null, string folderId = null, public GroupingsPage(bool mainPage, CipherType? type = null, string folderId = null,
string collectionId = null, string pageTitle = null) string collectionId = null, string pageTitle = null, PreviousPageInfo previousPage = null)
{ {
_pageName = string.Concat(nameof(GroupingsPage), "_", DateTime.UtcNow.Ticks); _pageName = string.Concat(nameof(GroupingsPage), "_", DateTime.UtcNow.Ticks);
InitializeComponent(); InitializeComponent();
@ -41,6 +44,7 @@ namespace Bit.App.Pages
_vm.Type = type; _vm.Type = type;
_vm.FolderId = folderId; _vm.FolderId = folderId;
_vm.CollectionId = collectionId; _vm.CollectionId = collectionId;
_previousPage = previousPage;
if(pageTitle != null) if(pageTitle != null)
{ {
_vm.PageTitle = pageTitle; _vm.PageTitle = pageTitle;
@ -125,6 +129,7 @@ namespace Bit.App.Pages
await _syncService.FullSyncAsync(true); await _syncService.FullSyncAsync(true);
} }
} }
await ShowPreviousPageAsync();
}, _mainContent); }, _mainContent);
if(!_vm.MainPage) if(!_vm.MainPage)
@ -244,5 +249,22 @@ namespace Bit.App.Pages
await Navigation.PushModalAsync(new NavigationPage(page)); await Navigation.PushModalAsync(new NavigationPage(page));
} }
} }
private async Task ShowPreviousPageAsync()
{
if(_previousPage == null)
{
return;
}
if(_previousPage.Page == "view" && !string.IsNullOrWhiteSpace(_previousPage.CipherId))
{
await Navigation.PushModalAsync(new NavigationPage(new ViewPage(_previousPage.CipherId)));
}
else if(_previousPage.Page == "edit" && !string.IsNullOrWhiteSpace(_previousPage.CipherId))
{
await Navigation.PushModalAsync(new NavigationPage(new AddEditPage(_previousPage.CipherId)));
}
_previousPage = null;
}
} }
} }

View File

@ -39,6 +39,8 @@ namespace Bit.App.Pages
} }
} }
public ViewPageViewModel ViewModel => _vm;
protected override async void OnAppearing() protected override async void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();

View File

@ -32,6 +32,7 @@
public static string MigratedFromV1AutofillPromptShown = "migratedV1AutofillPromptShown"; public static string MigratedFromV1AutofillPromptShown = "migratedV1AutofillPromptShown";
public static string TriedV1Resync = "triedV1Resync"; public static string TriedV1Resync = "triedV1Resync";
public static string EventCollectionKey = "eventCollection"; public static string EventCollectionKey = "eventCollection";
public static string PreviousPageKey = "previousPage";
public const int SelectFileRequestCode = 42; public const int SelectFileRequestCode = 42;
public const int SelectFilePermissionRequestCode = 43; public const int SelectFilePermissionRequestCode = 43;
} }