add account page detail

This commit is contained in:
2022-02-28 17:32:40 +08:00
parent 283acf7d35
commit 589c7514f2
17 changed files with 307 additions and 56 deletions

View File

@ -13,7 +13,7 @@
<ContentPage.Resources>
<ui:MoneyConverter x:Key="moneyConverter"/>
<ui:MoneyConverter x:Key="money2Converter"/>
<ui:MoneyConverter x:Key="money2Converter" MarkVisible="False"/>
</ContentPage.Resources>
<ContentPage.ToolbarItems>
@ -42,8 +42,17 @@
Text="{Binding Liability, Converter={StaticResource moneyConverter}}"/>
</Grid>
</Grid>
<CollectionView VerticalScrollBarVisibility="Never" ItemsSource="{Binding Accounts}">
<CollectionView.ItemTemplate>
<ui:GroupStackLayout x:Name="groupLayout" ItemsSource="{Binding Accounts}">
<ui:GroupStackLayout.GroupHeaderTemplate>
<DataTemplate x:DataType="v:AccountGrouping">
<StackLayout Orientation="Horizontal" Padding="10, 0">
<Label Text="{Binding Key}" TextColor="{DynamicResource SecondaryTextColor}"/>
<Label Text="{Binding Balance, Converter={StaticResource money2Converter}}"
Margin="10, 0" TextColor="{DynamicResource SecondaryTextColor}"/>
</StackLayout>
</DataTemplate>
</ui:GroupStackLayout.GroupHeaderTemplate>
<ui:GroupStackLayout.ItemTemplate>
<DataTemplate x:DataType="m:Account">
<StackLayout Orientation="Horizontal" Padding="20, 0" HeightRequest="44" Spacing="10">
<Image Source="{Binding Icon}" HeightRequest="20" VerticalOptions="Center"/>
@ -56,8 +65,8 @@
<ui:TintImage Source="right.png" HeightRequest="20"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ui:GroupStackLayout.ItemTemplate>
</ui:GroupStackLayout>
</StackLayout>
</ScrollView>
</ui:BillingPage>

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Billing.Models;
using Billing.UI;
using Xamarin.Forms;
@ -10,21 +12,21 @@ namespace Billing.Views
private static readonly BindableProperty BalanceProperty = BindableProperty.Create(nameof(Balance), typeof(decimal), typeof(AccountPage));
private static readonly BindableProperty AssetProperty = BindableProperty.Create(nameof(Asset), typeof(decimal), typeof(AccountPage));
private static readonly BindableProperty LiabilityProperty = BindableProperty.Create(nameof(Liability), typeof(decimal), typeof(AccountPage));
private static readonly BindableProperty AccountsProperty = BindableProperty.Create(nameof(Accounts), typeof(ObservableCollection<Account>), typeof(AccountPage));
private static readonly BindableProperty AccountsProperty = BindableProperty.Create(nameof(Accounts), typeof(List<AccountGrouping>), typeof(AccountPage));
public decimal Balance => (decimal)GetValue(BalanceProperty);
public decimal Asset => (decimal)GetValue(AssetProperty);
public decimal Liability => (decimal)GetValue(LiabilityProperty);
public ObservableCollection<Account> Accounts => (ObservableCollection<Account>)GetValue(AccountsProperty);
public List<AccountGrouping> Accounts => (List<AccountGrouping>)GetValue(AccountsProperty);
public Command AddAccount { get; }
private readonly ObservableCollection<Account> accounts;
private readonly List<AccountGrouping> accounts;
public AccountPage()
{
AddAccount = new Command(OnAddAccount);
accounts = new ObservableCollection<Account>();
accounts = new List<AccountGrouping>();
SetValue(AccountsProperty, accounts);
InitializeComponent();
@ -47,7 +49,27 @@ namespace Billing.Views
private void AccountChecked(object sender, AccountEventArgs e)
{
Helper.Debug(e.Account.ToString());
accounts.Add(e.Account);
var group = accounts.FirstOrDefault(g => g.Key == e.Account.Category);
if (group == null)
{
group = new AccountGrouping(e.Account.Category)
{
e.Account
};
accounts.Add(group);
}
else
{
group.Add(e.Account);
}
groupLayout.Refresh(accounts);
}
}
public class AccountGrouping : List<Account>, IGrouping<AccountCategory, Account>
{
public AccountGrouping(AccountCategory key) : base() => Key = key;
public AccountCategory Key { get; }
public decimal Balance { get; set; }
}
}

View File

@ -13,7 +13,6 @@
<ContentPage.Resources>
<ui:AccountCategoryConverter x:Key="categoryConverter"/>
<ui:MoneyConverter x:Key="moneyConverter" MarkVisible="False"/>
</ContentPage.Resources>
<ContentPage.ToolbarItems>
@ -23,14 +22,16 @@
<ContentPage.Content>
<TableView Intent="Settings" HasUnevenRows="True">
<TableSection Title=" ">
<ui:OptionEditorCell Title="{r:Text AccountName}" Height="120" FontSize="20"
Icon="pencil.png"
<ui:OptionEditorCell Height="120" Icon="pencil.png" FontSize="20" Keyboard="Text"
Title="{r:Text AccountName}"
Text="{Binding AccountName, Mode=TwoWay}"
Keyboard="Text" Placeholder="{r:Text AccountNamePlaceholder}"/>
<ui:OptionImageCell Title="{r:Text Icon}" Height="44" Icon="face.png"
Placeholder="{r:Text AccountNamePlaceholder}"/>
<ui:OptionImageCell Height="44" Icon="face.png"
Title="{r:Text Icon}"
ImageSource="{Binding AccountIcon}"
Command="{Binding SelectIcon}"/>
<ui:OptionSelectCell Title="{r:Text Category}" Height="44" Icon="project.png"
<ui:OptionSelectCell Height="44" Icon="project.png"
Title="{r:Text Category}"
Detail="{Binding Category, Converter={StaticResource categoryConverter}}"
Command="{Binding SelectCategory}"/>
</TableSection>
@ -38,20 +39,22 @@
<TableSection.Title>
<OnPlatform x:TypeArguments="x:String" Android=" "/>
</TableSection.Title>
<ui:OptionEntryCell Title="{r:Text Balance}" Height="44" Icon="sackdollar.png"
Text="{Binding Balance, Converter={StaticResource moneyConverter}}"
Keyboard="Numeric" Placeholder="{r:Text BalancePlaceholder}"
Unfocused="Balance_Unfocused"/>
<ui:OptionTextCell Title="{r:Text Currency}" Height="44" Icon="dollar.png"
<ui:OptionEntryCell Height="44" Icon="sackdollar.png" Keyboard="Numeric"
Title="{r:Text Balance}"
Text="{Binding Balance, Mode=TwoWay}"
Placeholder="{r:Text BalancePlaceholder}"/>
<ui:OptionTextCell Height="44" Icon="dollar.png"
Title="{r:Text Currency}"
Detail="{r:Text CNY}"/>
</TableSection>
<TableSection>
<TableSection.Title>
<OnPlatform x:TypeArguments="x:String" Android=" "/>
</TableSection.Title>
<ui:OptionEditorCell Title="{r:Text Memo}" Height="120" Icon="note.png"
<ui:OptionEditorCell Height="120" Icon="note.png" Keyboard="Plain"
Title="{r:Text Memo}"
Text="{Binding Memo, Mode=TwoWay}"
Keyboard="Plain" Placeholder="{r:Text MemoPlaceholder}"/>
Placeholder="{r:Text MemoPlaceholder}"/>
</TableSection>
</TableView>
</ContentPage.Content>

View File

@ -1,6 +1,8 @@
using Billing.Models;
using Billing.Languages;
using Billing.Models;
using Billing.UI;
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Billing.Views
@ -69,16 +71,6 @@ namespace Billing.Views
InitializeComponent();
}
private void Balance_Unfocused(object sender, FocusEventArgs e)
{
if (sender is OptionEntry entry && decimal.TryParse(entry.Text, out decimal d))
{
var converter = (MoneyConverter)Resources["moneyConverter"];
entry.Text = converter.Convert(d, null, null, null)?.ToString();
//Balance = d;
}
}
private async void OnCheckAccount()
{
if (Tap.IsBusy)
@ -108,9 +100,22 @@ namespace Billing.Views
}
private void OnSelectCategory()
private async void OnSelectCategory()
{
if (Tap.IsBusy)
{
return;
}
using (Tap.Start())
{
await Navigation.PushAsync(new ItemSelectPage(new List<SelectItem<AccountCategory>>
{
new() { Icon = "sackdollar", Value = AccountCategory.Cash, Name = Resource.Cash },
new() { Icon = "creditcard", Value = AccountCategory.CreditCard, Name = Resource.CreditCard },
new() { Icon = "", Value = AccountCategory.DebitCard, Name = Resource.DebitCard },
new() { Icon = "", Value = AccountCategory.ElecAccount, Name = Resource.ElecAccount }
}));
}
}
}