mirror of
https://github.com/bitwarden/mobile
synced 2025-12-23 19:53:50 +00:00
reset for v2
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AuthenticationServices;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models;
|
||||
|
||||
namespace Bit.iOS.Core.Utilities
|
||||
{
|
||||
public static class ASHelpers
|
||||
{
|
||||
public static async Task ReplaceAllIdentities(ICipherService cipherService)
|
||||
{
|
||||
if (await AutofillEnabled())
|
||||
{
|
||||
var identities = new List<ASPasswordCredentialIdentity>();
|
||||
var ciphers = await cipherService.GetAllAsync();
|
||||
foreach (var cipher in ciphers)
|
||||
{
|
||||
var identity = ToCredentialIdentity(cipher);
|
||||
if (identity != null)
|
||||
{
|
||||
identities.Add(identity);
|
||||
}
|
||||
}
|
||||
if (identities.Any())
|
||||
{
|
||||
await ASCredentialIdentityStore.SharedStore?.ReplaceCredentialIdentitiesAsync(identities.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> IdentitiesCanIncremental()
|
||||
{
|
||||
var state = await ASCredentialIdentityStore.SharedStore?.GetCredentialIdentityStoreStateAsync();
|
||||
return state != null && state.Enabled && state.SupportsIncrementalUpdates;
|
||||
}
|
||||
|
||||
public static async Task<bool> AutofillEnabled()
|
||||
{
|
||||
var state = await ASCredentialIdentityStore.SharedStore?.GetCredentialIdentityStoreStateAsync();
|
||||
return state != null && state.Enabled;
|
||||
}
|
||||
|
||||
public static async Task<ASPasswordCredentialIdentity> GetCipherIdentityAsync(string cipherId, ICipherService cipherService)
|
||||
{
|
||||
var cipher = await cipherService.GetByIdAsync(cipherId);
|
||||
return ToCredentialIdentity(cipher);
|
||||
}
|
||||
|
||||
public static ASPasswordCredentialIdentity ToCredentialIdentity(Cipher cipher)
|
||||
{
|
||||
if (!cipher?.Login?.Uris?.Any() ?? true)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var uri = cipher.Login.Uris.FirstOrDefault()?.Uri?.Decrypt(cipher.OrganizationId);
|
||||
if (string.IsNullOrWhiteSpace(uri))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var username = cipher.Login.Username?.Decrypt(cipher.OrganizationId);
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var serviceId = new ASCredentialServiceIdentifier(uri, ASCredentialServiceIdentifierType.Url);
|
||||
return new ASPasswordCredentialIdentity(serviceId, username, cipher.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using CoreGraphics;
|
||||
using UIKit;
|
||||
|
||||
namespace Bit.iOS.Core.Utilities
|
||||
{
|
||||
public static class Dialogs
|
||||
{
|
||||
public static UIAlertController CreateLoadingAlert(string message)
|
||||
{
|
||||
var loadingIndicator = new UIActivityIndicatorView(new CGRect(10, 5, 50, 50));
|
||||
loadingIndicator.HidesWhenStopped = true;
|
||||
loadingIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
|
||||
loadingIndicator.StartAnimating();
|
||||
|
||||
var alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
|
||||
alert.View.TintColor = UIColor.Black;
|
||||
alert.View.Add(loadingIndicator);
|
||||
return alert;
|
||||
}
|
||||
|
||||
public static UIAlertController CreateMessageAlert(string message)
|
||||
{
|
||||
var alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
|
||||
alert.View.TintColor = UIColor.Black;
|
||||
return alert;
|
||||
}
|
||||
|
||||
public static UIAlertController CreateAlert(string title, string message, string accept, Action<UIAlertAction> acceptHandle = null)
|
||||
{
|
||||
var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
|
||||
var oldFrame = alert.View.Frame;
|
||||
alert.View.Frame = new RectangleF((float)oldFrame.X, (float)oldFrame.Y, (float)oldFrame.Width, (float)oldFrame.Height - 20);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user