mirror of
https://github.com/bitwarden/mobile
synced 2026-01-08 11:33:31 +00:00
[EC-528] Refactor Custom Fields into separate components (#1662)
* Refactored CustomFields to stop using RepeaterView and use BindableLayout and divided the different types on different files and added a factory to create them * Fix formatting
This commit is contained in:
committed by
GitHub
parent
2016eadb0d
commit
b7048de2a1
23
src/App/Utilities/AppSetup.cs
Normal file
23
src/App/Utilities/AppSetup.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Bit.App.Lists.ItemViewModels.CustomFields;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
{
|
||||
public interface IAppSetup
|
||||
{
|
||||
void InitializeServicesLastChance();
|
||||
}
|
||||
|
||||
public class AppSetup : IAppSetup
|
||||
{
|
||||
public void InitializeServicesLastChance()
|
||||
{
|
||||
var i18nService = ServiceContainer.Resolve<II18nService>("i18nService");
|
||||
var eventService = ServiceContainer.Resolve<IEventService>("eventService");
|
||||
|
||||
// TODO: This could be further improved by Lazy Registration since it may not be needed at all
|
||||
ServiceContainer.Register<ICustomFieldItemFactory>("customFieldItemFactory", new CustomFieldItemFactory(i18nService, eventService));
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/App/Utilities/BoxRowVsBoxRowInputPaddingConverter.cs
Normal file
24
src/App/Utilities/BoxRowVsBoxRowInputPaddingConverter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
{
|
||||
public class BooleanToBoxRowInputPaddingConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter,
|
||||
System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (targetType == typeof(Thickness))
|
||||
{
|
||||
return ((bool?)value).GetValueOrDefault() ? new Thickness(0, 10, 0, 0) : new Thickness(0, 10);
|
||||
}
|
||||
throw new InvalidOperationException("The target must be a thickness.");
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter,
|
||||
System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/App/Utilities/IPasswordPromptable.cs
Normal file
9
src/App/Utilities/IPasswordPromptable.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
{
|
||||
public interface IPasswordPromptable
|
||||
{
|
||||
Task<bool> PromptPasswordAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.View;
|
||||
using Xamarin.Forms;
|
||||
|
||||
@@ -11,54 +9,24 @@ namespace Bit.App.Utilities
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var cipher = value as CipherView;
|
||||
return GetIcon(cipher);
|
||||
if (value is CipherView cipher)
|
||||
{
|
||||
return cipher.GetIcon();
|
||||
}
|
||||
|
||||
if (value is bool boolVal
|
||||
&&
|
||||
parameter is BooleanGlyphType boolGlyphType)
|
||||
{
|
||||
return IconGlyphExtensions.GetBooleanIconGlyph(boolVal, boolGlyphType);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private string GetIcon(CipherView cipher)
|
||||
{
|
||||
string icon = null;
|
||||
switch (cipher.Type)
|
||||
{
|
||||
case CipherType.Login:
|
||||
icon = GetLoginIconGlyph(cipher);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
icon = BitwardenIcons.StickyNote;
|
||||
break;
|
||||
case CipherType.Card:
|
||||
icon = BitwardenIcons.CreditCard;
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
icon = BitwardenIcons.IdCard;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
string GetLoginIconGlyph(CipherView cipher)
|
||||
{
|
||||
var icon = BitwardenIcons.Globe;
|
||||
if (cipher.Login.Uri != null)
|
||||
{
|
||||
var hostnameUri = cipher.Login.Uri;
|
||||
if (hostnameUri.StartsWith(Constants.AndroidAppProtocol))
|
||||
{
|
||||
icon = BitwardenIcons.Android;
|
||||
}
|
||||
else if (hostnameUri.StartsWith(Constants.iOSAppProtocol))
|
||||
{
|
||||
icon = BitwardenIcons.Apple;
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
69
src/App/Utilities/IconGlyphExtensions.cs
Normal file
69
src/App/Utilities/IconGlyphExtensions.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Bit.Core;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.View;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
{
|
||||
public static class IconGlyphExtensions
|
||||
{
|
||||
public static string GetIcon(this CipherView cipher)
|
||||
{
|
||||
string icon = null;
|
||||
switch (cipher.Type)
|
||||
{
|
||||
case CipherType.Login:
|
||||
icon = GetLoginIconGlyph(cipher);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
icon = BitwardenIcons.StickyNote;
|
||||
break;
|
||||
case CipherType.Card:
|
||||
icon = BitwardenIcons.CreditCard;
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
icon = BitwardenIcons.IdCard;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
static string GetLoginIconGlyph(CipherView cipher)
|
||||
{
|
||||
var icon = BitwardenIcons.Globe;
|
||||
if (cipher.Login.Uri != null)
|
||||
{
|
||||
var hostnameUri = cipher.Login.Uri;
|
||||
if (hostnameUri.StartsWith(Constants.AndroidAppProtocol))
|
||||
{
|
||||
icon = BitwardenIcons.Android;
|
||||
}
|
||||
else if (hostnameUri.StartsWith(Constants.iOSAppProtocol))
|
||||
{
|
||||
icon = BitwardenIcons.Apple;
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static string GetBooleanIconGlyph(bool value, BooleanGlyphType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case BooleanGlyphType.Checkbox:
|
||||
return value ? BitwardenIcons.CheckSquare : BitwardenIcons.Square;
|
||||
case BooleanGlyphType.Eye:
|
||||
return value ? BitwardenIcons.Eye : BitwardenIcons.EyeSlash;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum BooleanGlyphType
|
||||
{
|
||||
Checkbox,
|
||||
Eye
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user