1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-23 10:04:49 +02:00
bitwarden-mobile/src/iOS.ShareExtension/LockPasswordViewController.cs
Federico Maccaroni 292908f53f
[EC-259] Added Account Switching to Share extension on iOS (#1971)
* EC-259 Added Account switching on share extension on iOS, also improved performance for this and exception handling

* EC-259 code formatting

* EC-259 Added account switching to Share extension Send view

* EC-259 Fixed navigation on share extension when a forms page is already presented

* EC-259 Fix send text UI update when going from the iOS extension

* EC-259 Improved DateTimeViewModel with helper property to easily setup date and time at the same time and applied on usage
2022-07-12 14:12:23 -03:00

108 lines
3.6 KiB
C#

using Bit.App.Controls;
using Bit.Core.Utilities;
using Bit.iOS.Core.Utilities;
using System;
using UIKit;
namespace Bit.iOS.ShareExtension
{
public partial class LockPasswordViewController : Core.Controllers.BaseLockPasswordViewController
{
AccountSwitchingOverlayView _accountSwitchingOverlayView;
AccountSwitchingOverlayHelper _accountSwitchingOverlayHelper;
public LockPasswordViewController()
{
BiometricIntegrityKey = Bit.Core.Constants.iOSShareExtensionBiometricIntegrityKey;
DismissModalAction = Cancel;
}
public LockPasswordViewController(IntPtr handle)
: base(handle)
{
BiometricIntegrityKey = Bit.Core.Constants.iOSShareExtensionBiometricIntegrityKey;
DismissModalAction = Cancel;
}
public LoadingViewController LoadingController { get; set; }
public override UINavigationItem BaseNavItem => _navItem;
public override UIBarButtonItem BaseCancelButton => _cancelButton;
public override UIBarButtonItem BaseSubmitButton => _submitButton;
public override Action Success => () =>
{
LoadingController?.Navigate(Bit.Core.Enums.NavigationTarget.Home);
LoadingController = null;
};
public override Action Cancel => () =>
{
LoadingController?.CompleteRequest();
LoadingController = null;
};
public override UITableView TableView => _mainTableView;
public override async void ViewDidLoad()
{
base.ViewDidLoad();
_cancelButton.TintColor = ThemeHelpers.NavBarTextColor;
_submitButton.TintColor = ThemeHelpers.NavBarTextColor;
_accountSwitchingOverlayHelper = new AccountSwitchingOverlayHelper();
_accountSwitchingButton.Image = await _accountSwitchingOverlayHelper.CreateAvatarImageAsync();
_accountSwitchingOverlayView = _accountSwitchingOverlayHelper.CreateAccountSwitchingOverlayView(_overlayView);
}
protected override void UpdateNavigationBarTheme()
{
UpdateNavigationBarTheme(_navBar);
}
partial void AccountSwitchingButton_Activated(UIBarButtonItem sender)
{
_accountSwitchingOverlayHelper.OnToolbarItemActivated(_accountSwitchingOverlayView, _overlayView);
}
partial void SubmitButton_Activated(UIBarButtonItem sender)
{
CheckPasswordAsync().FireAndForget();
}
partial void CancelButton_Activated(UIBarButtonItem sender)
{
Cancel();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (TableView != null)
{
TableView.Source?.Dispose();
}
if (_accountSwitchingButton?.Image != null)
{
var img = _accountSwitchingButton.Image;
_accountSwitchingButton.Image = null;
img.Dispose();
}
if (_accountSwitchingOverlayView != null && _overlayView?.Subviews != null)
{
foreach (var subView in _overlayView.Subviews)
{
subView.RemoveFromSuperview();
subView.Dispose();
}
_accountSwitchingOverlayView = null;
_overlayView.RemoveFromSuperview();
}
_accountSwitchingOverlayHelper = null;
}
base.Dispose(disposing);
}
}
}