mirror of
https://github.com/bitwarden/mobile
synced 2026-01-07 02:53:56 +00:00
app options for add/edit page
This commit is contained in:
@@ -18,5 +18,8 @@ namespace Bit.App.Abstractions
|
||||
string okButtonText = null, string cancelButtonText = null, bool numericKeyboard = false);
|
||||
void RateApp();
|
||||
bool SupportsFaceId();
|
||||
bool SupportsNfc();
|
||||
bool SupportsCamera();
|
||||
bool SupportsAutofillService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Bit.App.Models;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models;
|
||||
using Bit.App.Pages;
|
||||
using Bit.App.Resources;
|
||||
using Bit.App.Services;
|
||||
@@ -34,9 +35,12 @@ namespace Bit.App
|
||||
private readonly IPlatformUtilsService _platformUtilsService;
|
||||
private readonly IAuthService _authService;
|
||||
private readonly IStorageService _storageService;
|
||||
private readonly IDeviceActionService _deviceActionService;
|
||||
private readonly AppOptions _appOptions;
|
||||
|
||||
public App()
|
||||
public App(AppOptions appOptions)
|
||||
{
|
||||
_appOptions = appOptions ?? new AppOptions();
|
||||
_userService = ServiceContainer.Resolve<IUserService>("userService");
|
||||
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
||||
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
||||
@@ -56,6 +60,7 @@ namespace Bit.App
|
||||
_passwordGenerationService = ServiceContainer.Resolve<IPasswordGenerationService>(
|
||||
"passwordGenerationService");
|
||||
_i18nService = ServiceContainer.Resolve<II18nService>("i18nService") as MobileI18nService;
|
||||
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||
|
||||
InitializeComponent();
|
||||
SetCulture();
|
||||
@@ -107,21 +112,24 @@ namespace Bit.App
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
protected async override void OnStart()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("XF App: OnStart");
|
||||
await ClearCacheIfNeededAsync();
|
||||
}
|
||||
|
||||
protected async override void OnSleep()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("XF App: OnSleep");
|
||||
await HandleLockingAsync();
|
||||
SetTabsPageFromAutofill();
|
||||
}
|
||||
|
||||
protected override void OnResume()
|
||||
protected async override void OnResume()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("XF App: OnResume");
|
||||
_messagingService.Send("cancelLockTimer");
|
||||
await ClearCacheIfNeededAsync();
|
||||
}
|
||||
|
||||
private void SetCulture()
|
||||
@@ -168,6 +176,10 @@ namespace Bit.App
|
||||
{
|
||||
Current.MainPage = new NavigationPage(new LockPage());
|
||||
}
|
||||
else if(_appOptions.FromAutofillFramework && _appOptions.SaveType.HasValue)
|
||||
{
|
||||
Current.MainPage = new NavigationPage(new AddEditPage(appOptions: _appOptions));
|
||||
}
|
||||
else
|
||||
{
|
||||
Current.MainPage = new TabsPage();
|
||||
@@ -205,5 +217,30 @@ namespace Bit.App
|
||||
await _lockService.LockAsync(true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ClearCacheIfNeededAsync()
|
||||
{
|
||||
var lastClear = await _storageService.GetAsync<DateTime?>(Constants.LastFileCacheClearKey);
|
||||
if((DateTime.UtcNow - lastClear.GetValueOrDefault(DateTime.MinValue)).TotalDays >= 1)
|
||||
{
|
||||
var task = Task.Run(() => _deviceActionService.ClearCacheAsync());
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTabsPageFromAutofill()
|
||||
{
|
||||
if(Device.RuntimePlatform == Device.Android && !string.IsNullOrWhiteSpace(_appOptions.Uri) &&
|
||||
!_appOptions.FromAutofillFramework)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Current.MainPage = new TabsPage();
|
||||
_appOptions.Uri = null;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
src/App/Models/AppOptions.cs
Normal file
21
src/App/Models/AppOptions.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public class AppOptions
|
||||
{
|
||||
public bool MyVaultTile { get; set; }
|
||||
public bool FromAutofillFramework { get; set; }
|
||||
public CipherType? FillType { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public CipherType? SaveType { get; set; }
|
||||
public string SaveName { get; set; }
|
||||
public string SaveUsername { get; set; }
|
||||
public string SavePassword { get; set; }
|
||||
public string SaveCardName { get; set; }
|
||||
public string SaveCardNumber { get; set; }
|
||||
public string SaveCardExpMonth { get; set; }
|
||||
public string SaveCardExpYear { get; set; }
|
||||
public string SaveCardCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.App.Models;
|
||||
using Bit.Core.Enums;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms;
|
||||
|
||||
@@ -7,13 +8,16 @@ namespace Bit.App.Pages
|
||||
public partial class AddEditPage : BaseContentPage
|
||||
{
|
||||
private AddEditPageViewModel _vm;
|
||||
private readonly AppOptions _appOptions;
|
||||
|
||||
public AddEditPage(
|
||||
string cipherId = null,
|
||||
CipherType? type = null,
|
||||
string folderId = null,
|
||||
string collectionId = null)
|
||||
string collectionId = null,
|
||||
AppOptions appOptions = null)
|
||||
{
|
||||
_appOptions = appOptions;
|
||||
InitializeComponent();
|
||||
_vm = BindingContext as AddEditPageViewModel;
|
||||
_vm.Page = this;
|
||||
@@ -40,7 +44,7 @@ namespace Bit.App.Pages
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync());
|
||||
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync(_appOptions));
|
||||
if(_vm.EditMode && Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
if(_vm.Cipher.OrganizationId == null)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models;
|
||||
using Bit.App.Resources;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Enums;
|
||||
@@ -264,7 +265,7 @@ namespace Bit.App.Pages
|
||||
PageTitle = EditMode ? AppResources.EditItem : AppResources.AddItem;
|
||||
}
|
||||
|
||||
public async Task LoadAsync()
|
||||
public async Task LoadAsync(AppOptions appOptions = null)
|
||||
{
|
||||
var myEmail = await _userService.GetEmailAsync();
|
||||
OwnershipOptions.Add(new KeyValuePair<string, string>(myEmail, null));
|
||||
@@ -310,6 +311,21 @@ namespace Bit.App.Pages
|
||||
Cipher.Login.Uris = new List<LoginUriView> { new LoginUriView() };
|
||||
Cipher.SecureNote.Type = SecureNoteType.Generic;
|
||||
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
|
||||
|
||||
if(appOptions != null)
|
||||
{
|
||||
Cipher.Type = appOptions.SaveType.GetValueOrDefault(Cipher.Type);
|
||||
Cipher.Login.Username = appOptions.SaveUsername;
|
||||
Cipher.Login.Password = appOptions.SavePassword;
|
||||
Cipher.Card.Code = appOptions.SaveCardCode;
|
||||
if(int.TryParse(appOptions.SaveCardExpMonth, out int month) && month <= 12 && month >= 1)
|
||||
{
|
||||
Cipher.Card.ExpMonth = month.ToString();
|
||||
}
|
||||
Cipher.Card.ExpYear = appOptions.SaveCardExpYear;
|
||||
Cipher.Card.CardholderName = appOptions.SaveCardName;
|
||||
Cipher.Card.Number = appOptions.SaveCardNumber;
|
||||
}
|
||||
}
|
||||
|
||||
FolderSelectedIndex = string.IsNullOrWhiteSpace(Cipher.FolderId) ? FolderOptions.Count - 1 :
|
||||
|
||||
Reference in New Issue
Block a user