diff --git a/src/iOS.Core/Utilities/Dialogs.cs b/src/iOS.Core/Utilities/Dialogs.cs index 344c94fb6..817013632 100644 --- a/src/iOS.Core/Utilities/Dialogs.cs +++ b/src/iOS.Core/Utilities/Dialogs.cs @@ -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; + } } } diff --git a/src/iOS.Extension/Models/PageDetails.cs b/src/iOS.Extension/Models/PageDetails.cs index f2fc44e4f..0b60f6c00 100644 --- a/src/iOS.Extension/Models/PageDetails.cs +++ b/src/iOS.Extension/Models/PageDetails.cs @@ -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 Forms { get; set; } public List Fields { get; set; } public long CollectedTimestamp { get; set; } + public bool HasPasswordField => Fields.Any(f => f.Type == "password"); public class Form { diff --git a/src/iOS.Extension/SiteListViewController.cs b/src/iOS.Extension/SiteListViewController.cs index b52bc03e6..ec5a6308b 100644 --- a/src/iOS.Extension/SiteListViewController.cs +++ b/src/iOS.Extension/SiteListViewController.cs @@ -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,7 +167,49 @@ namespace Bit.iOS.Extension return; } - _controller.LoadingController.CompleteUsernamePasswordRequest(item.Username, item.Password); + 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); + } } } }