mirror of
https://github.com/bitwarden/android.git
synced 2024-12-19 07:41:52 +03:00
Added username/password copy options to extension when no password field is detected on the page details intitiated from.
This commit is contained in:
parent
9f54296ff0
commit
bb4b732b76
3 changed files with 66 additions and 1 deletions
|
@ -35,5 +35,21 @@ namespace Bit.iOS.Core.Utilities
|
|||
alert.AddAction(UIAlertAction.Create(accept, UIAlertActionStyle.Default, acceptHandle));
|
||||
return alert;
|
||||
}
|
||||
|
||||
public static UIAlertController CreateActionSheet(string title, UIViewController controller)
|
||||
{
|
||||
var sheet = UIAlertController.Create(title, null, UIAlertControllerStyle.ActionSheet);
|
||||
if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
|
||||
{
|
||||
var x = controller.View.Bounds.Width / 2;
|
||||
var y = controller.View.Bounds.Bottom;
|
||||
var rect = new CGRect(x, y, 0, 0);
|
||||
|
||||
sheet.PopoverPresentationController.SourceView = controller.View;
|
||||
sheet.PopoverPresentationController.SourceRect = rect;
|
||||
sheet.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Unknown;
|
||||
}
|
||||
return sheet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.iOS.Extension.Models
|
||||
{
|
||||
|
@ -13,6 +14,7 @@ namespace Bit.iOS.Extension.Models
|
|||
public Dictionary<string, Form> Forms { get; set; }
|
||||
public List<Field> Fields { get; set; }
|
||||
public long CollectedTimestamp { get; set; }
|
||||
public bool HasPasswordField => Fields.Any(f => f.Type == "password");
|
||||
|
||||
public class Form
|
||||
{
|
||||
|
|
|
@ -11,6 +11,8 @@ using Newtonsoft.Json;
|
|||
using UIKit;
|
||||
using XLabs.Ioc;
|
||||
using Plugin.Settings.Abstractions;
|
||||
using CoreGraphics;
|
||||
using Bit.iOS.Core.Utilities;
|
||||
|
||||
namespace Bit.iOS.Extension
|
||||
{
|
||||
|
@ -147,6 +149,9 @@ namespace Bit.iOS.Extension
|
|||
|
||||
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
|
||||
{
|
||||
tableView.DeselectRow(indexPath, true);
|
||||
tableView.EndEditing(true);
|
||||
|
||||
if(_tableItems.Count() == 0)
|
||||
{
|
||||
_controller.PerformSegue("siteAddSegue", this);
|
||||
|
@ -162,8 +167,50 @@ namespace Bit.iOS.Extension
|
|||
return;
|
||||
}
|
||||
|
||||
if(_context?.Details?.HasPasswordField ?? false && !string.IsNullOrWhiteSpace(item.Password))
|
||||
{
|
||||
_controller.LoadingController.CompleteUsernamePasswordRequest(item.Username, item.Password);
|
||||
}
|
||||
else if(!string.IsNullOrWhiteSpace(item.Username) || !string.IsNullOrWhiteSpace(item.Password))
|
||||
{
|
||||
var sheet = Dialogs.CreateActionSheet(item.Name, _controller);
|
||||
if(!string.IsNullOrWhiteSpace(item.Username))
|
||||
{
|
||||
sheet.AddAction(UIAlertAction.Create("Copy Username", UIAlertActionStyle.Default, a =>
|
||||
{
|
||||
UIPasteboard clipboard = UIPasteboard.General;
|
||||
clipboard.String = item.Username;
|
||||
var alert = Dialogs.CreateMessageAlert("Copied username!");
|
||||
_controller.PresentViewController(alert, true, () =>
|
||||
{
|
||||
_controller.DismissViewController(true, null);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(item.Password))
|
||||
{
|
||||
sheet.AddAction(UIAlertAction.Create("Copy Password", UIAlertActionStyle.Default, a =>
|
||||
{
|
||||
UIPasteboard clipboard = UIPasteboard.General;
|
||||
clipboard.String = item.Password;
|
||||
var alert = Dialogs.CreateMessageAlert("Copied password!");
|
||||
_controller.PresentViewController(alert, true, () =>
|
||||
{
|
||||
_controller.DismissViewController(true, null);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
sheet.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
|
||||
_controller.PresentViewController(sheet, true, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
var alert = Dialogs.CreateAlert(null, "This site does not have a username or password configured.", "Ok");
|
||||
_controller.PresentViewController(alert, true, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue