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

@ -14,6 +14,7 @@
<ContentPage.Resources>
<ui:MoneyConverter x:Key="moneyConverter"/>
<ui:MoneyConverter x:Key="money2Converter" MarkVisible="False"/>
<ui:IconConverter x:Key="iconConverter"/>
</ContentPage.Resources>
<ContentPage.ToolbarItems>
@ -55,7 +56,8 @@
<ui:GroupStackLayout.ItemTemplate>
<DataTemplate x:DataType="m:Account">
<StackLayout Orientation="Horizontal" Padding="20, 0, 10, 0" HeightRequest="44" Spacing="10">
<Image Source="{Binding Icon}" HeightRequest="20" VerticalOptions="Center"/>
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
<Label Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
HorizontalOptions="FillAndExpand" VerticalOptions="Center"
FontSize="Default" FontAttributes="Bold"/>

View File

@ -13,6 +13,7 @@
<ContentPage.Resources>
<ui:AccountCategoryConverter x:Key="categoryConverter"/>
<ui:IconConverter x:Key="iconConverter"/>
</ContentPage.Resources>
<ContentPage.ToolbarItems>
@ -28,7 +29,7 @@
Placeholder="{r:Text AccountNamePlaceholder}"/>
<ui:OptionImageCell Height="44" Icon="face.png"
Title="{r:Text Icon}"
ImageSource="{Binding AccountIcon}"
ImageSource="{Binding AccountIcon, Converter={StaticResource iconConverter}}"
Command="{Binding SelectIcon}"/>
<ui:OptionSelectCell Height="44" Icon="project.png"
Title="{r:Text Category}"

View File

@ -95,9 +95,23 @@ namespace Billing.Views
}
}
private void OnSelectIcon()
private async void OnSelectIcon()
{
if (Tap.IsBusy)
{
return;
}
using (Tap.Start())
{
var page = new IconSelectPage(AccountIcon);
page.IconChecked += Account_IconChecked;
await Navigation.PushAsync(page);
}
}
private void Account_IconChecked(object sender, string icon)
{
AccountIcon = icon;
}
private async void OnSelectCategory()

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ui:BillingPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:ui="clr-namespace:Billing.UI"
xmlns:v="clr-namespace:Billing.Views"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Billing.Views.AddBillPage"
x:DataType="v:AddBillPage"

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" ?>
<ui:BillingPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:r="clr-namespace:Billing.Languages"
xmlns:ui="clr-namespace:Billing.UI"
xmlns:v="clr-namespace:Billing.Views"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Billing.Views.IconSelectPage"
x:Name="iconSelectPage"
x:DataType="v:IconSelectPage"
Title="{r:Text IconSelector}"
BindingContext="{x:Reference iconSelectPage}">
<ContentPage.Resources>
<ui:IconConverter x:Key="iconConverter"/>
</ContentPage.Resources>
<Grid RowDefinitions="*, Auto">
<ScrollView>
<ui:WrapLayout ItemsSource="{Binding IconsSource}" Margin="10">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="v:BillingIcon">
<Grid WidthRequest="60" HeightRequest="60">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding IconCheck, Source={x:Reference iconSelectPage}}"
CommandParameter="{Binding Icon}"/>
</Grid.GestureRecognizers>
<Grid BackgroundColor="{DynamicResource PromptBackgroundColor}"
IsVisible="{Binding IsChecked}"/>
<ui:TintImage WidthRequest="20" HeightRequest="20" Aspect="AspectFit"
HorizontalOptions="Center" VerticalOptions="Center"
Source="{Binding Icon, Converter={StaticResource iconConverter}}"/>
</Grid>
</DataTemplate>
</BindableLayout.ItemTemplate>
</ui:WrapLayout>
</ScrollView>
</Grid>
</ui:BillingPage>

View File

@ -0,0 +1,80 @@
using Billing.Models;
using Billing.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms;
namespace Billing.Views
{
public partial class IconSelectPage : BillingPage
{
public static readonly BindableProperty IconsSourceProperty = BindableProperty.Create(nameof(IconsSource), typeof(IList<BillingIcon>), typeof(IconSelectPage));
public IList<BillingIcon> IconsSource
{
get => (IList<BillingIcon>)GetValue(IconsSourceProperty);
set => SetValue(IconsSourceProperty, value);
}
public Command IconCheck { get; }
public event EventHandler<string> IconChecked;
private string iconChecked;
public IconSelectPage(string icon)
{
iconChecked = icon;
IconCheck = new Command(OnIconCheck);
InitializeComponent();
InitIcons();
}
private void InitIcons()
{
var source = new List<BillingIcon>
{
new() { Icon = BaseModel.ICON_DEFAULT },
new() { Icon = "wallet" }
};
source.AddRange(IconConverter.IconPreset.Select(icon => new BillingIcon { Icon = $"#brand#{icon.Key}" }));
foreach (var icon in source)
{
if (icon.Icon == iconChecked)
{
icon.IsChecked = true;
}
}
IconsSource = source;
}
private async void OnIconCheck(object o)
{
if (o is string icon)
{
foreach (var ic in IconsSource)
{
ic.IsChecked = ic.Icon == icon;
}
iconChecked = icon;
IconChecked?.Invoke(this, icon);
await Navigation.PopAsync();
}
}
}
public class BillingIcon : BindableObject
{
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(BillingIcon));
public bool IsChecked
{
get => (bool)GetValue(IsCheckedProperty);
set => SetValue(IsCheckedProperty, value);
}
public string Icon { get; set; }
}
}