icon select

This commit is contained in:
2022-03-02 10:45:40 +08:00
parent 2179c6a981
commit aa38e186c7
24 changed files with 288 additions and 35 deletions

View File

@ -1,6 +1,7 @@
using Billing.Languages;
using Billing.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using Xamarin.Forms;
@ -95,4 +96,62 @@ namespace Billing.UI
return value;
}
}
public class IconConverter : IValueConverter
{
public static readonly Dictionary<string, string> IconPreset = new()
{
{ "alipay", "\uf642" },
{ "appstore", "\uf370" },
{ "apple-pay", "\uf416" },
{ "btc", "\uf15a" },
{ "jcb", "\uf24b" },
{ "master-card", "\uf1f1" },
{ "visa", "\uf1f0" },
{ "g-pay", "\ue079" },
{ "paypal", "\uf1ed" },
{ "qq", "\uf1d6" },
{ "steam", "\uf1b6" },
{ "uber", "\uf402" },
{ "weixin", "\uf1d7" },
{ "youtube", "\uf167" }
};
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is ImageSource source)
{
return source;
}
if (value is string name)
{
if (name.StartsWith("#brand#"))
{
var key = name[7..];
if (!IconPreset.TryGetValue(key, out var glyph))
{
if (!int.TryParse(key, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int i))
{
return ImageSource.FromFile(BaseModel.ICON_DEFAULT);
}
glyph = char.ConvertFromUtf32(i);
}
return new FontImageSource
{
FontFamily = Definition.GetBrandsFontFamily(),
Size = 20,
Glyph = glyph,
Color = Color.Black
};
}
return ImageSource.FromFile(name);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
}