bitwarden-mobile/src/App/Pages/Settings/SettingsPage/SettingsPage.xaml.cs

186 lines
6.1 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel;
using System.Linq;
2019-05-31 20:18:32 +02:00
using System.Threading.Tasks;
using Bit.App.Abstractions;
using Bit.App.Controls;
using Bit.App.Pages.Accounts;
using Bit.App.Resources;
using Bit.Core.Utilities;
2019-03-28 01:12:44 +01:00
using Xamarin.Forms;
2019-03-28 22:10:10 +01:00
namespace Bit.App.Pages
2019-03-28 01:12:44 +01:00
{
2019-05-14 17:53:41 +02:00
public partial class SettingsPage : BaseContentPage
2019-03-28 01:12:44 +01:00
{
2019-05-31 04:45:48 +02:00
private readonly IDeviceActionService _deviceActionService;
private readonly TabsPage _tabsPage;
2019-05-14 15:09:35 +02:00
private SettingsPageViewModel _vm;
public SettingsPage(TabsPage tabsPage)
2019-03-28 01:12:44 +01:00
{
_tabsPage = tabsPage;
2019-03-28 01:12:44 +01:00
InitializeComponent();
2019-05-31 04:45:48 +02:00
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
2019-05-14 15:09:35 +02:00
_vm = BindingContext as SettingsPageViewModel;
_vm.Page = this;
2019-03-28 01:12:44 +01:00
}
2019-05-14 17:53:41 +02:00
2019-05-31 20:18:32 +02:00
public async Task InitAsync()
2019-05-16 20:55:18 +02:00
{
await _vm.InitAsync();
}
2019-06-03 18:05:18 +02:00
public void BuildList()
{
_vm.BuildList();
}
protected override bool OnBackButtonPressed()
{
if (Device.RuntimePlatform == Device.Android && _tabsPage != null)
{
_tabsPage.ResetToVaultPage();
return true;
}
return base.OnBackButtonPressed();
}
void ActivateTimePicker(object sender, EventArgs args)
{
var stackLayout = (ExtendedStackLayout)sender;
SettingsPageListItem item = (SettingsPageListItem)stackLayout.BindingContext;
if (item.ShowTimeInput)
{
var timePicker = stackLayout.Children.Where(x => x is TimePicker).FirstOrDefault();
((TimePicker)timePicker)?.Focus();
}
}
2021-09-23 15:42:38 +02:00
async void OnTimePickerPropertyChanged(object sender, PropertyChangedEventArgs args)
{
2022-04-26 17:21:17 +02:00
var s = (TimePicker)sender;
2021-09-23 15:42:38 +02:00
var time = s.Time.TotalMinutes;
if (s.IsFocused && args.PropertyName == "Time")
{
await _vm.VaultTimeoutAsync(false, (int)time);
}
}
private async void RowSelected(object sender, SelectionChangedEventArgs e)
2019-05-14 17:53:41 +02:00
{
((ExtendedCollectionView)sender).SelectedItem = null;
if (!DoOnce())
2019-05-14 17:53:41 +02:00
{
return;
}
if (!(e.CurrentSelection?.FirstOrDefault() is SettingsPageListItem item))
2019-05-14 17:53:41 +02:00
{
return;
}
if (item.Name == AppResources.Sync)
2019-05-14 18:05:30 +02:00
{
await Navigation.PushModalAsync(new NavigationPage(new SyncPage()));
}
else if (item.Name == AppResources.AutofillServices)
2019-05-31 04:45:48 +02:00
{
await Navigation.PushModalAsync(new NavigationPage(new AutofillServicesPage(this)));
2019-05-31 04:45:48 +02:00
}
else if (item.Name == AppResources.PasswordAutofill)
2019-05-31 04:45:48 +02:00
{
2019-07-02 19:15:00 +02:00
await Navigation.PushModalAsync(new NavigationPage(new AutofillPage()));
2019-05-31 04:45:48 +02:00
}
else if (item.Name == AppResources.AppExtension)
2019-05-31 04:45:48 +02:00
{
2019-07-02 19:15:00 +02:00
await Navigation.PushModalAsync(new NavigationPage(new ExtensionPage()));
2019-05-31 04:45:48 +02:00
}
else if (item.Name == AppResources.Options)
2019-05-29 15:08:47 +02:00
{
await Navigation.PushModalAsync(new NavigationPage(new OptionsPage()));
}
else if (item.Name == AppResources.Folders)
2019-05-14 23:02:24 +02:00
{
await Navigation.PushModalAsync(new NavigationPage(new FoldersPage()));
}
else if (item.Name == AppResources.About)
2019-05-15 15:14:49 +02:00
{
await _vm.AboutAsync();
}
else if (item.Name == AppResources.HelpAndFeedback)
2019-05-15 18:54:48 +02:00
{
_vm.Help();
}
else if (item.Name == AppResources.FingerprintPhrase)
2019-05-15 18:54:48 +02:00
{
await _vm.FingerprintAsync();
}
else if (item.Name == AppResources.RateTheApp)
2019-05-15 19:09:49 +02:00
{
_vm.Rate();
}
else if (item.Name == AppResources.ImportItems)
2019-05-15 19:26:55 +02:00
{
_vm.Import();
}
else if (item.Name == AppResources.ExportVault)
2019-05-15 19:26:55 +02:00
{
await Navigation.PushModalAsync(new NavigationPage(new ExportVaultPage()));
2019-05-15 19:26:55 +02:00
}
else if (item.Name == AppResources.LearnOrg)
2019-05-15 19:26:55 +02:00
{
await _vm.ShareAsync();
}
else if (item.Name == AppResources.WebVault)
2019-05-15 19:26:55 +02:00
{
_vm.WebVault();
}
else if (item.Name == AppResources.ChangeMasterPassword)
2019-05-15 19:26:55 +02:00
{
await _vm.ChangePasswordAsync();
}
else if (item.Name == AppResources.TwoStepLogin)
2019-05-15 19:26:55 +02:00
{
await _vm.TwoStepAsync();
}
else if (item.Name == AppResources.LogOut)
2019-05-15 19:26:55 +02:00
{
await _vm.LogOutAsync();
}
else if (item.Name == AppResources.DeleteAccount)
{
await Navigation.PushModalAsync(new NavigationPage(new DeleteAccountPage()));
}
else if (item.Name == AppResources.LockNow)
2019-05-15 21:47:50 +02:00
{
await _vm.LockAsync();
}
[Auto Logout] Final review of feature (#932) * Initial commit of LockService name refactor (#831) * [Auto-Logout] Update Service layer logic (#835) * Initial commit of service logic update * Added default value for action * Updated ToggleTokensAsync conditional * Removed unused variables, updated action conditional * Initial commit: lockOption/lock refactor app layer (#840) * [Auto-Logout] Settings Refactor - Application Layer Part 2 (#844) * Initial commit of app layer part 2 * Updated biometrics position * Reverted resource name refactor * LockOptions refactor revert * Updated method casing :: Removed VaultTimeout prefix for timeouts * Fixed dupe string resource (#854) * Updated dependency to use VaultTimeoutService (#896) * [Auto Logout] Xamarin Forms in AutoFill flow (iOS) (#902) * fix typo in PINRequireMasterPasswordRestart (#900) * initial commit for xf usage in autofill * Fixed databinding for hint button * Updated Two Factor page launch - removed unused imports * First pass at broadcast/messenger implentation for autofill * setting theme in extension using theme manager * extension app resources * App resources from main app * fix ref to twoFactorPage * apply resources to page * load empty app for sytling in extension * move ios renderers to ios core * static ref to resources and GetResourceColor helper * fix method ref * move application.current.resources refs to helper * switch login page alerts to device action dialogs * run on main thread * showDialog with device action service * abstract action sheet to device action service * add support for yubikey * add yubikey iimages to extension * support close button action * add support to action extension * remove empty lines Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * [Auto Logout] Update lock option to be default value (#929) * Initial commit - make lock action default * Removed extra whitespace Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-05-29 18:26:36 +02:00
else if (item.Name == AppResources.VaultTimeout)
2019-05-16 20:55:18 +02:00
{
[Auto Logout] Final review of feature (#932) * Initial commit of LockService name refactor (#831) * [Auto-Logout] Update Service layer logic (#835) * Initial commit of service logic update * Added default value for action * Updated ToggleTokensAsync conditional * Removed unused variables, updated action conditional * Initial commit: lockOption/lock refactor app layer (#840) * [Auto-Logout] Settings Refactor - Application Layer Part 2 (#844) * Initial commit of app layer part 2 * Updated biometrics position * Reverted resource name refactor * LockOptions refactor revert * Updated method casing :: Removed VaultTimeout prefix for timeouts * Fixed dupe string resource (#854) * Updated dependency to use VaultTimeoutService (#896) * [Auto Logout] Xamarin Forms in AutoFill flow (iOS) (#902) * fix typo in PINRequireMasterPasswordRestart (#900) * initial commit for xf usage in autofill * Fixed databinding for hint button * Updated Two Factor page launch - removed unused imports * First pass at broadcast/messenger implentation for autofill * setting theme in extension using theme manager * extension app resources * App resources from main app * fix ref to twoFactorPage * apply resources to page * load empty app for sytling in extension * move ios renderers to ios core * static ref to resources and GetResourceColor helper * fix method ref * move application.current.resources refs to helper * switch login page alerts to device action dialogs * run on main thread * showDialog with device action service * abstract action sheet to device action service * add support for yubikey * add yubikey iimages to extension * support close button action * add support to action extension * remove empty lines Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * [Auto Logout] Update lock option to be default value (#929) * Initial commit - make lock action default * Removed extra whitespace Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-05-29 18:26:36 +02:00
await _vm.VaultTimeoutAsync();
}
else if (item.Name == AppResources.VaultTimeoutAction)
{
await _vm.VaultTimeoutActionAsync();
2019-05-16 20:55:18 +02:00
}
else if (item.Name == AppResources.UnlockWithPIN)
2019-05-16 21:54:21 +02:00
{
await _vm.UpdatePinAsync();
}
2019-07-22 16:12:14 +02:00
else
{
2020-06-08 14:25:13 +02:00
var biometricName = AppResources.Biometrics;
if (Device.RuntimePlatform == Device.iOS)
2019-07-22 16:12:14 +02:00
{
2019-10-23 15:11:48 +02:00
var supportsFace = await _deviceActionService.SupportsFaceBiometricAsync();
2020-06-08 14:25:13 +02:00
biometricName = supportsFace ? AppResources.FaceID : AppResources.TouchID;
2019-07-22 16:12:14 +02:00
}
2020-06-08 14:25:13 +02:00
if (item.Name == string.Format(AppResources.UnlockWith, biometricName))
2019-10-23 15:24:34 +02:00
{
2020-06-08 14:25:13 +02:00
await _vm.UpdateBiometricAsync();
2019-07-22 16:12:14 +02:00
}
2019-05-16 23:30:07 +02:00
}
2019-05-14 17:53:41 +02:00
}
2019-03-28 01:12:44 +01:00
}
}