Change context options to action sheet w/ button

This commit is contained in:
Kyle Spearrin 2018-03-13 17:33:45 -04:00
parent 1031ddcd83
commit 262c19b194
5 changed files with 92 additions and 91 deletions

View file

@ -436,7 +436,7 @@ namespace Bit.App.Pages
UrisSection = new TableSection(Helpers.GetEmptyTableSectionTitle()); UrisSection = new TableSection(Helpers.GetEmptyTableSectionTitle());
AddUriCell = new ExtendedTextCell AddUriCell = new ExtendedTextCell
{ {
Text = AppResources.NewUri, Text = $"+ {AppResources.NewUri}",
TextColor = Colors.Primary TextColor = Colors.Primary
}; };
UrisSection.Add(AddUriCell); UrisSection.Add(AddUriCell);
@ -558,7 +558,7 @@ namespace Bit.App.Pages
FieldsSection = new TableSection(AppResources.CustomFields); FieldsSection = new TableSection(AppResources.CustomFields);
AddFieldCell = new ExtendedTextCell AddFieldCell = new ExtendedTextCell
{ {
Text = AppResources.NewCustomField, Text = $"+ {AppResources.NewCustomField}",
TextColor = Colors.Primary TextColor = Colors.Primary
}; };
FieldsSection.Add(AddFieldCell); FieldsSection.Add(AddFieldCell);

View file

@ -202,7 +202,7 @@ namespace Bit.App.Pages
UrisSection = new TableSection(Helpers.GetEmptyTableSectionTitle()); UrisSection = new TableSection(Helpers.GetEmptyTableSectionTitle());
AddUriCell = new ExtendedTextCell AddUriCell = new ExtendedTextCell
{ {
Text = AppResources.NewUri, Text = $"+ {AppResources.NewUri}",
TextColor = Colors.Primary TextColor = Colors.Primary
}; };
UrisSection.Add(AddUriCell); UrisSection.Add(AddUriCell);
@ -408,7 +408,7 @@ namespace Bit.App.Pages
{ {
var label = field.Name?.Decrypt(Cipher.OrganizationId) ?? string.Empty; var label = field.Name?.Decrypt(Cipher.OrganizationId) ?? string.Empty;
var value = field.Value?.Decrypt(Cipher.OrganizationId); var value = field.Value?.Decrypt(Cipher.OrganizationId);
var cell = Helpers.MakeFieldCell(field.Type, label, value, FieldsSection); var cell = Helpers.MakeFieldCell(field.Type, label, value, FieldsSection, this);
if(cell != null) if(cell != null)
{ {
FieldsSection.Add(cell); FieldsSection.Add(cell);
@ -417,7 +417,7 @@ namespace Bit.App.Pages
} }
AddFieldCell = new ExtendedTextCell AddFieldCell = new ExtendedTextCell
{ {
Text = AppResources.NewCustomField, Text = $"+ {AppResources.NewCustomField}",
TextColor = Colors.Primary TextColor = Colors.Primary
}; };
FieldsSection.Add(AddFieldCell); FieldsSection.Add(AddFieldCell);

View file

@ -421,7 +421,7 @@ namespace Bit.App.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Base Domain. /// Looks up a localized string similar to Base domain.
/// </summary> /// </summary>
public static string BaseDomain { public static string BaseDomain {
get { get {

View file

@ -1257,7 +1257,7 @@
<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"> <data name="BaseDomain" xml:space="preserve">
<value>Base Domain</value> <value>Base domain</value>
</data> </data>
<data name="Default" xml:space="preserve"> <data name="Default" xml:space="preserve">
<value>Default</value> <value>Default</value>

View file

@ -238,7 +238,7 @@ namespace Bit.App.Utilities
return; return;
} }
var cell = MakeFieldCell(fieldType, label, string.Empty, fieldsSection); var cell = MakeFieldCell(fieldType, label, string.Empty, fieldsSection, page);
if(cell != null) if(cell != null)
{ {
fieldsSection.Insert(fieldsSection.Count - 1, cell); fieldsSection.Insert(fieldsSection.Count - 1, cell);
@ -249,7 +249,8 @@ namespace Bit.App.Utilities
} }
} }
public static Cell MakeFieldCell(FieldType type, string label, string value, TableSection fieldsSection) public static Cell MakeFieldCell(FieldType type, string label, string value,
TableSection fieldsSection, Page page)
{ {
Cell cell; Cell cell;
switch(type) switch(type)
@ -258,7 +259,7 @@ namespace Bit.App.Utilities
case FieldType.Hidden: case FieldType.Hidden:
var hidden = type == FieldType.Hidden; var hidden = type == FieldType.Hidden;
var textFieldCell = new FormEntryCell(label, isPassword: hidden, var textFieldCell = new FormEntryCell(label, isPassword: hidden,
button1: hidden ? "eye.png" : null); button1: hidden ? "eye.png" : "cog.png", button2: hidden ? "cog.png" : null);
textFieldCell.Entry.Text = value; textFieldCell.Entry.Text = value;
textFieldCell.Entry.DisableAutocapitalize = true; textFieldCell.Entry.DisableAutocapitalize = true;
textFieldCell.Entry.Autocorrect = false; textFieldCell.Entry.Autocorrect = false;
@ -289,56 +290,55 @@ namespace Bit.App.Utilities
break; break;
} }
if(cell != null) if(cell is FormEntryCell feCell)
{ {
var deleteAction = new MenuItem { Text = AppResources.Remove, IsDestructive = true }; var optionsButton = feCell.Button2 ?? feCell.Button1;
deleteAction.Clicked += (sender, e) => optionsButton.Command = new Command(async () =>
{ {
if(fieldsSection.Contains(cell)) var optionsVal = await page.DisplayActionSheet(AppResources.Options, AppResources.Cancel,
null, AppResources.Edit, AppResources.Remove);
if(optionsVal == AppResources.Remove)
{ {
fieldsSection.Remove(cell); if(fieldsSection.Contains(cell))
} {
fieldsSection.Remove(cell);
}
if(cell is FormEntryCell feCell) if(cell is IDisposable disposableCell)
{ {
feCell.Dispose(); disposableCell.Dispose();
}
cell = feCell = null;
} }
cell = null; else if(optionsVal == AppResources.Edit)
};
var editNameAction = new MenuItem { Text = AppResources.Edit };
editNameAction.Clicked += async (sender, e) =>
{
string existingLabel = null;
var feCell = cell as FormEntryCell;
var esCell = cell as ExtendedSwitchCell;
if(feCell != null)
{
existingLabel = feCell.Label.Text;
}
else if(esCell != null)
{
existingLabel = esCell.Text;
}
var daService = Resolver.Resolve<IDeviceActionService>();
var editLabel = await daService.DisplayPromptAync(AppResources.CustomFieldName,
null, existingLabel);
if(editLabel != null)
{ {
string existingLabel = null;
var esCell = cell as ExtendedSwitchCell;
if(feCell != null) if(feCell != null)
{ {
feCell.Label.Text = editLabel; existingLabel = feCell.Label.Text;
} }
else if(esCell != null) else if(esCell != null)
{ {
esCell.Text = editLabel; existingLabel = esCell.Text;
}
var daService = Resolver.Resolve<IDeviceActionService>();
var editLabel = await daService.DisplayPromptAync(AppResources.CustomFieldName,
null, existingLabel);
if(editLabel != null)
{
if(feCell != null)
{
feCell.Label.Text = editLabel;
}
else if(esCell != null)
{
esCell.Text = editLabel;
}
} }
} }
}; });
cell.ContextActions.Add(editNameAction);
cell.ContextActions.Add(deleteAction);
} }
return cell; return cell;
@ -386,63 +386,64 @@ namespace Bit.App.Utilities
public static FormEntryCell MakeUriCell(string value, UriMatchType? match, TableSection urisSection, Page page) 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, button1: "cog.png");
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 }; cell.MetaData = new Dictionary<string, object> { ["match"] = match };
var deleteAction = new MenuItem { Text = AppResources.Remove, IsDestructive = true }; cell.Button1.Command = new Command(async () =>
deleteAction.Clicked += (sender, e) =>
{ {
if(urisSection.Contains(cell)) var optionsVal = await page.DisplayActionSheet(AppResources.Options, AppResources.Cancel,
{ null, AppResources.Edit, AppResources.Remove);
urisSection.Remove(cell);
if(cell is FormEntryCell feCell)
{
feCell.Dispose();
}
cell = null;
for(int i = 0; i < urisSection.Count; i++) if(optionsVal == AppResources.Edit)
{
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)
{ {
if(urisSection[i] is FormEntryCell uriCell) selectedVal = exactingMatchVal;
}
else if(val != AppResources.Default)
{
selectedVal = UriMatchOptionsMap.ElementAt(Array.IndexOf(optionsArr, val) - 1).Key;
}
cell.MetaData["match"] = selectedVal;
}
else if(optionsVal == AppResources.Remove)
{
if(urisSection.Contains(cell))
{
urisSection.Remove(cell);
if(cell is FormEntryCell feCell)
{ {
uriCell.Label.Text = string.Format(AppResources.URIPosition, i + 1); feCell.Dispose();
}
cell = null;
for(int i = 0; i < urisSection.Count; i++)
{
if(urisSection[i] is FormEntryCell uriCell)
{
uriCell.Label.Text = string.Format(AppResources.URIPosition, i + 1);
}
} }
} }
} }
}; });
var optionsAction = new MenuItem { Text = AppResources.Options };
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(deleteAction);
return cell; return cell;
} }