select URI match option from action sheet

This commit is contained in:
Kyle Spearrin 2018-03-06 11:58:02 -05:00
parent 0bccc8f0d5
commit fb6e488339
7 changed files with 154 additions and 12 deletions

View File

@ -6475,17 +6475,17 @@ namespace Bit.Android
// aapt resource value: 0x7f090051 // aapt resource value: 0x7f090051
public const int ApplicationName = 2131296337; public const int ApplicationName = 2131296337;
// aapt resource value: 0x7f0900ab // aapt resource value: 0x7f0900b2
public const int AutoFillServiceDescription = 2131296427; public const int AutoFillServiceDescription = 2131296434;
// aapt resource value: 0x7f0900aa // aapt resource value: 0x7f0900b1
public const int AutoFillServiceSummary = 2131296426; public const int AutoFillServiceSummary = 2131296433;
// aapt resource value: 0x7f090050 // aapt resource value: 0x7f090050
public const int Hello = 2131296336; public const int Hello = 2131296336;
// aapt resource value: 0x7f0900ac // aapt resource value: 0x7f0900b3
public const int MyVault = 2131296428; public const int MyVault = 2131296435;
// aapt resource value: 0x7f090027 // aapt resource value: 0x7f090027
public const int abc_action_bar_home_description = 2131296295; public const int abc_action_bar_home_description = 2131296295;
@ -6640,6 +6640,27 @@ namespace Bit.Android
// aapt resource value: 0x7f09000f // aapt resource value: 0x7f09000f
public const int common_signin_button_text_long = 2131296271; public const int common_signin_button_text_long = 2131296271;
// aapt resource value: 0x7f0900ac
public const int default_web_client_id = 2131296428;
// aapt resource value: 0x7f0900ad
public const int firebase_database_url = 2131296429;
// aapt resource value: 0x7f0900aa
public const int gcm_defaultSenderId = 2131296426;
// aapt resource value: 0x7f0900ae
public const int google_api_key = 2131296430;
// aapt resource value: 0x7f0900ab
public const int google_app_id = 2131296427;
// aapt resource value: 0x7f0900af
public const int google_crash_reporting_api_key = 2131296431;
// aapt resource value: 0x7f0900b0
public const int google_storage_bucket = 2131296432;
// aapt resource value: 0x7f090052 // aapt resource value: 0x7f090052
public const int hockeyapp_crash_dialog_app_name_fallback = 2131296338; public const int hockeyapp_crash_dialog_app_name_fallback = 2131296338;

View File

@ -1,6 +1,7 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using FFImageLoading.Forms; using FFImageLoading.Forms;
using System; using System;
using System.Collections.Generic;
using Xamarin.Forms; using Xamarin.Forms;
using XLabs.Ioc; using XLabs.Ioc;
@ -150,6 +151,7 @@ namespace Bit.App.Controls
} }
} }
} }
public Dictionary<string, object> MetaData { get; set; }
public void InitEvents() public void InitEvents()
{ {

View File

@ -452,7 +452,7 @@ namespace Bit.App.Pages
TextColor = Colors.Primary TextColor = Colors.Primary
}; };
UrisSection.Add(AddUriCell); UrisSection.Add(AddUriCell);
UrisSection.Insert(0, Helpers.MakeUriCell(string.Empty, UrisSection)); UrisSection.Insert(0, Helpers.MakeUriCell(string.Empty, null, UrisSection, this));
} }
else if(_type == CipherType.Card) else if(_type == CipherType.Card)
{ {
@ -833,7 +833,7 @@ namespace Bit.App.Pages
private void AddUriCell_Tapped(object sender, EventArgs e) private void AddUriCell_Tapped(object sender, EventArgs e)
{ {
var cell = Helpers.MakeUriCell(string.Empty, UrisSection); var cell = Helpers.MakeUriCell(string.Empty, null, UrisSection, this);
if(cell != null) if(cell != null)
{ {
UrisSection.Insert(UrisSection.Count - 1, cell); UrisSection.Insert(UrisSection.Count - 1, cell);

View File

@ -223,7 +223,8 @@ namespace Bit.App.Pages
foreach(var uri in Cipher.Login.Uris) foreach(var uri in Cipher.Login.Uris)
{ {
var value = uri.Uri?.Decrypt(Cipher.OrganizationId); var value = uri.Uri?.Decrypt(Cipher.OrganizationId);
UrisSection.Insert(UrisSection.Count - 1, Helpers.MakeUriCell(value, UrisSection)); UrisSection.Insert(UrisSection.Count - 1,
Helpers.MakeUriCell(value, uri.Match, UrisSection, this));
} }
} }
} }
@ -930,7 +931,7 @@ namespace Bit.App.Pages
private void AddUriCell_Tapped(object sender, EventArgs e) private void AddUriCell_Tapped(object sender, EventArgs e)
{ {
var cell = Helpers.MakeUriCell(string.Empty, UrisSection); var cell = Helpers.MakeUriCell(string.Empty, null, UrisSection, this);
if(cell != null) if(cell != null)
{ {
UrisSection.Insert(UrisSection.Count - 1, cell); UrisSection.Insert(UrisSection.Count - 1, cell);

View File

@ -420,6 +420,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Base Domain.
/// </summary>
public static string BaseDomain {
get {
return ResourceManager.GetString("BaseDomain", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Beta. /// Looks up a localized string similar to Beta.
/// </summary> /// </summary>
@ -924,6 +933,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Default.
/// </summary>
public static string Default {
get {
return ResourceManager.GetString("Default", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Delete. /// Looks up a localized string similar to Delete.
/// </summary> /// </summary>
@ -1158,6 +1176,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Exact.
/// </summary>
public static string Exact {
get {
return ResourceManager.GetString("Exact", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Re-enable App Extension. /// Looks up a localized string similar to Re-enable App Extension.
/// </summary> /// </summary>
@ -1554,6 +1581,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Host.
/// </summary>
public static string Host {
get {
return ResourceManager.GetString("Host", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Icons. /// Looks up a localized string similar to Icons.
/// </summary> /// </summary>
@ -2472,6 +2508,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Regular expression.
/// </summary>
public static string RegEx {
get {
return ResourceManager.GetString("RegEx", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Remember me. /// Looks up a localized string similar to Remember me.
/// </summary> /// </summary>
@ -2706,6 +2751,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Starts with.
/// </summary>
public static string StartsWith {
get {
return ResourceManager.GetString("StartsWith", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to State / Province. /// Looks up a localized string similar to State / Province.
/// </summary> /// </summary>
@ -2949,6 +3003,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to URI Match Detection.
/// </summary>
public static string URIMatchDetection {
get {
return ResourceManager.GetString("URIMatchDetection", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to URI {0}. /// Looks up a localized string similar to URI {0}.
/// </summary> /// </summary>

View File

@ -1256,4 +1256,27 @@
<value>URI {0}</value> <value>URI {0}</value>
<comment>Label for a uri/url with position. i.e. URI 1, URI 2, etc</comment> <comment>Label for a uri/url with position. i.e. URI 1, URI 2, etc</comment>
</data> </data>
<data name="BaseDomain" xml:space="preserve">
<value>Base Domain</value>
</data>
<data name="Default" xml:space="preserve">
<value>Default</value>
</data>
<data name="Exact" xml:space="preserve">
<value>Exact</value>
</data>
<data name="Host" xml:space="preserve">
<value>Host</value>
<comment>A URL's host value. For example, the host of https://sub.domain.com:443 is 'sub.domain.com:443'.</comment>
</data>
<data name="RegEx" xml:space="preserve">
<value>Regular expression</value>
<comment>A programming term, also known as 'RegEx'.</comment>
</data>
<data name="StartsWith" xml:space="preserve">
<value>Starts with</value>
</data>
<data name="URIMatchDetection" xml:space="preserve">
<value>URI Match Detection</value>
</data>
</root> </root>

View File

@ -18,6 +18,15 @@ namespace Bit.App.Utilities
public static class Helpers public static class Helpers
{ {
public static readonly DateTime Epoc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); public static readonly DateTime Epoc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static IDictionary<UriMatchType?, string> UriMatchOptionsMap = new Dictionary<UriMatchType?, string>
{
[UriMatchType.Domain] = AppResources.BaseDomain,
[UriMatchType.Host] = AppResources.Host,
[UriMatchType.StartsWith] = AppResources.StartsWith,
[UriMatchType.RegularExpression] = AppResources.RegEx,
[UriMatchType.Exact] = AppResources.Exact,
[UriMatchType.Never] = AppResources.Never
};
public static long EpocUtcNow() public static long EpocUtcNow()
{ {
@ -374,13 +383,14 @@ namespace Bit.App.Utilities
} }
} }
public static FormEntryCell MakeUriCell(string value, TableSection urisSection) public static FormEntryCell MakeUriCell(string value, UriMatchType? match, TableSection urisSection, Page page)
{ {
var label = string.Format(AppResources.URIPosition, urisSection.Count); var label = string.Format(AppResources.URIPosition, urisSection.Count);
var cell = new FormEntryCell(label, entryKeyboard: Keyboard.Url); var cell = new FormEntryCell(label, entryKeyboard: Keyboard.Url);
cell.Entry.Text = value; cell.Entry.Text = value;
cell.Entry.DisableAutocapitalize = true; cell.Entry.DisableAutocapitalize = true;
cell.Entry.Autocorrect = false; cell.Entry.Autocorrect = false;
cell.MetaData = new Dictionary<string, object> { ["match"] = match };
var deleteAction = new MenuItem { Text = AppResources.Remove, IsDestructive = true }; var deleteAction = new MenuItem { Text = AppResources.Remove, IsDestructive = true };
deleteAction.Clicked += (sender, e) => deleteAction.Clicked += (sender, e) =>
@ -407,7 +417,28 @@ namespace Bit.App.Utilities
var optionsAction = new MenuItem { Text = AppResources.Options }; var optionsAction = new MenuItem { Text = AppResources.Options };
optionsAction.Clicked += async (sender, e) => optionsAction.Clicked += async (sender, e) =>
{ {
var options = UriMatchOptionsMap.Select(v => v.Value).ToList();
options.Insert(0, AppResources.Default);
var exactingMatchVal = cell.MetaData["match"] as UriMatchType?;
var matchIndex = exactingMatchVal.HasValue ?
Array.IndexOf(UriMatchOptionsMap.Keys.ToArray(), exactingMatchVal) + 1 : 0;
options[matchIndex] = $"✓ {options[matchIndex]}";
var optionsArr = options.ToArray();
var val = await page.DisplayActionSheet(AppResources.URIMatchDetection, AppResources.Cancel,
null, options.ToArray());
UriMatchType? selectedVal = null;
if(val == AppResources.Cancel)
{
selectedVal = exactingMatchVal;
}
else if(val != AppResources.Default)
{
selectedVal = UriMatchOptionsMap.ElementAt(Array.IndexOf(optionsArr, val) - 1).Key;
}
cell.MetaData["match"] = selectedVal;
}; };
cell.ContextActions.Add(optionsAction); cell.ContextActions.Add(optionsAction);
@ -424,10 +455,11 @@ namespace Bit.App.Utilities
{ {
if(cell is FormEntryCell entryCell && !string.IsNullOrWhiteSpace(entryCell.Entry.Text)) if(cell is FormEntryCell entryCell && !string.IsNullOrWhiteSpace(entryCell.Entry.Text))
{ {
var match = entryCell?.MetaData["match"] as UriMatchType?;
uris.Add(new LoginUri uris.Add(new LoginUri
{ {
Uri = entryCell.Entry.Text.Encrypt(cipher.OrganizationId), Uri = entryCell.Entry.Text.Encrypt(cipher.OrganizationId),
Match = null Match = match
}); });
} }
} }