complete account page

This commit is contained in:
2022-03-02 17:31:49 +08:00
parent aa38e186c7
commit 51f8e4f2e8
26 changed files with 547 additions and 76 deletions

View File

@ -14,6 +14,7 @@
<ContentPage.Resources>
<ui:MoneyConverter x:Key="moneyConverter"/>
<ui:MoneyConverter x:Key="money2Converter" MarkVisible="False"/>
<ui:AccountCategoryConverter x:Key="categoryConverter"/>
<ui:IconConverter x:Key="iconConverter"/>
</ContentPage.Resources>
@ -43,11 +44,12 @@
Text="{Binding Liability, Converter={StaticResource moneyConverter}}"/>
</Grid>
</Grid>
<ui:GroupStackLayout x:Name="groupLayout" ItemsSource="{Binding Accounts}">
<ui:GroupStackLayout x:Name="groupLayout" ItemsSource="{Binding Accounts}" Margin="0, 10, 0, 0">
<ui:GroupStackLayout.GroupHeaderTemplate>
<DataTemplate x:DataType="v:AccountGrouping">
<StackLayout Orientation="Horizontal" Padding="10, 0">
<Label Text="{Binding Key}" TextColor="{DynamicResource SecondaryTextColor}"/>
<Label Text="{Binding Key, Converter={StaticResource categoryConverter}}"
TextColor="{DynamicResource SecondaryTextColor}"/>
<Label Text="{Binding Balance, Converter={StaticResource money2Converter}}"
Margin="10, 0" TextColor="{DynamicResource SecondaryTextColor}"/>
</StackLayout>
@ -55,7 +57,7 @@
</ui:GroupStackLayout.GroupHeaderTemplate>
<ui:GroupStackLayout.ItemTemplate>
<DataTemplate x:DataType="m:Account">
<StackLayout Orientation="Horizontal" Padding="20, 0, 10, 0" HeightRequest="44" Spacing="10">
<StackLayout Orientation="Horizontal" Padding="20, 0, 10, 0" Spacing="10">
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
<Label Text="{Binding Name}" TextColor="{DynamicResource TextColor}"

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Billing.Models;
using Billing.UI;
using Xamarin.Forms;
@ -20,17 +21,57 @@ namespace Billing.Views
public Command AddAccount { get; }
private readonly List<AccountGrouping> accounts;
private readonly List<AccountGrouping> accounts = new();
private bool initialized;
public AccountPage()
{
AddAccount = new Command(OnAddAccount);
accounts = new List<AccountGrouping>();
SetValue(AccountsProperty, accounts);
InitializeComponent();
}
protected override void OnAppearing()
{
if (!initialized)
{
initialized = true;
accounts.Clear();
foreach (var account in App.Accounts)
{
AddToAccountGroup(account);
}
}
groupLayout.Refresh(accounts);
}
private void AddToAccountGroup(Account account)
{
int maxId;
if (accounts.Count > 0)
{
maxId = accounts.Max(g => g.Max(a => a.Id));
}
else
{
maxId = -1;
}
account.Id = maxId + 1;
var group = accounts.FirstOrDefault(g => g.Key == account.Category);
if (group == null)
{
group = new AccountGrouping(account.Category, account.Balance) { account };
accounts.Add(group);
}
else
{
group.Add(account);
group.Balance += account.Balance;
}
}
private async void OnAddAccount()
{
if (Tap.IsBusy)
@ -47,28 +88,23 @@ namespace Billing.Views
private void AccountChecked(object sender, AccountEventArgs e)
{
Helper.Debug(e.Account.ToString());
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);
}
App.Accounts.Add(e.Account);
AddToAccountGroup(e.Account);
groupLayout.Refresh(accounts);
Task.Run(App.WriteAccounts);
}
}
public class AccountGrouping : List<Account>, IGrouping<AccountCategory, Account>
{
public AccountGrouping(AccountCategory key) : base() => Key = key;
public AccountCategory Key { get; }
public decimal Balance { get; set; }
public AccountGrouping(AccountCategory key, decimal balance) : base()
{
Key = key;
Balance = balance;
}
}
}

View File

@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<ui:BillingPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
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.AddAccountPage"
x:Name="addAccountPage"
x:DataType="v:AddAccountPage"
Title="{r:Text AddAccount}"
BindingContext="{x:Reference addAccountPage}"
NavigationPage.BackButtonTitle="">
BindingContext="{x:Reference addAccountPage}">
<ContentPage.Resources>
<ui:AccountCategoryConverter x:Key="categoryConverter"/>
@ -42,7 +41,7 @@
</TableSection.Title>
<ui:OptionEntryCell Height="44" Icon="sackdollar.png" Keyboard="Numeric"
Title="{r:Text Balance}"
Text="{Binding Balance, Mode=TwoWay}"
Text="{Binding Initial, Mode=TwoWay}"
Placeholder="{r:Text BalancePlaceholder}"/>
<ui:OptionTextCell Height="44" Icon="yuan.png"
Title="{r:Text Currency}"

View File

@ -12,7 +12,7 @@ namespace Billing.Views
private static readonly BindableProperty AccountNameProperty = BindableProperty.Create(nameof(AccountName), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty AccountIconProperty = BindableProperty.Create(nameof(AccountIcon), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty CategoryProperty = BindableProperty.Create(nameof(Category), typeof(AccountCategory), typeof(AddAccountPage));
private static readonly BindableProperty BalanceProperty = BindableProperty.Create(nameof(Balance), typeof(decimal), typeof(AddAccountPage));
private static readonly BindableProperty InitialProperty = BindableProperty.Create(nameof(Initial), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty MemoProperty = BindableProperty.Create(nameof(Memo), typeof(string), typeof(AddAccountPage));
public string AccountName
@ -30,10 +30,10 @@ namespace Billing.Views
get => (AccountCategory)GetValue(CategoryProperty);
set => SetValue(CategoryProperty, value);
}
public decimal Balance
public string Initial
{
get => (decimal)GetValue(BalanceProperty);
set => SetValue(BalanceProperty, value);
get => (string)GetValue(InitialProperty);
set => SetValue(InitialProperty, value);
}
public string Memo
{
@ -54,6 +54,7 @@ namespace Billing.Views
CheckAccount = new Command(OnCheckAccount);
SelectIcon = new Command(OnSelectIcon);
SelectCategory = new Command(OnSelectCategory);
AccountIcon = BaseModel.ICON_DEFAULT;
Category = AccountCategory.Cash;
InitializeComponent();
@ -61,13 +62,16 @@ namespace Billing.Views
public AddAccountPage(Account account)
{
CheckAccount = new Command(OnCheckAccount);
SelectIcon = new Command(OnSelectIcon);
SelectCategory = new Command(OnSelectCategory);
this.account = account;
AccountName = account.Name;
AccountIcon = account.Icon;
Category = account.Category;
Balance = account.Balance;
Initial = account.Initial.ToString();
Memo = account.Memo;
CheckAccount = new Command(OnCheckAccount);
InitializeComponent();
}
@ -80,6 +84,7 @@ namespace Billing.Views
using (Tap.Start())
{
await Navigation.PopAsync();
_ = decimal.TryParse(Initial, out decimal initial);
AccountChecked?.Invoke(this, new AccountEventArgs
{
Account = new Account
@ -88,7 +93,8 @@ namespace Billing.Views
Name = AccountName,
Icon = AccountIcon,
Category = Category,
Balance = Balance,
Initial = initial,
Balance = initial,
Memo = Memo
}
});

View File

@ -1,15 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?>
<ui:BillingPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
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.AddBillPage"
x:Name="billPage"
x:DataType="v:AddBillPage"
Title="Add Billing">
BindingContext="{x:Reference billPage}">
<StackLayout>
<Label Text="Add a billing here..."
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
<ContentPage.ToolbarItems>
<ToolbarItem Order="Primary" IconImageSource="check.png" Command="{Binding CheckBill}"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<TableView Intent="Settings" HasUnevenRows="True">
<TableSection Title=" ">
<ui:OptionEditorCell Height="120" Icon="pencil.png" FontSize="20" Keyboard="Text"
Title="{r:Text Account}"
Text="{Binding AccountName, Mode=TwoWay}"
Placeholder="0.00"/>
</TableSection>
<TableSection>
<TableSection.Title>
<OnPlatform x:TypeArguments="x:String" Android=" "/>
</TableSection.Title>
<ui:OptionSelectCell Height="44" Icon="project.png"
Title="{r:Text Category}"
Detail="{Binding Category, Converter={StaticResource categoryConverter}}"
Command="{Binding SelectCategory}"/>
<ui:OptionSelectCell Height="44" Icon="project.png"
Title="{r:Text Account}"
Detail="{Binding Category, Converter={StaticResource categoryConverter}}"
Command="{Binding SelectCategory}"/>
<ui:OptionSelectCell Height="44" Icon="project.png"
Title="{r:Text CreatedTime}"
Detail="{Binding Category, Converter={StaticResource categoryConverter}}"
Command="{Binding SelectCategory}"/>
</TableSection>
<TableSection>
<TableSection.Title>
<OnPlatform x:TypeArguments="x:String" Android=" "/>
</TableSection.Title>
<ui:OptionEditorCell Height="120" Icon="note.png" Keyboard="Plain"
Title="{r:Text Memo}"
Text="{Binding Memo, Mode=TwoWay}"
Placeholder="{r:Text MemoPlaceholder}"/>
</TableSection>
</TableView>
</ContentPage.Content>
</ui:BillingPage>

View File

@ -1,12 +1,37 @@
using System;
using Billing.Languages;
using Billing.Models;
using Billing.UI;
using Xamarin.Forms;
namespace Billing.Views
{
public partial class AddBillPage : BillingPage
{
public AddBillPage()
public Command CheckBill { get; }
private readonly Bill bill;
private readonly DateTime createDate;
public AddBillPage(DateTime date)
{
createDate = date;
CheckBill = new Command(OnCheckBill);
InitializeComponent();
Title = Resource.AddBill;
}
public AddBillPage(Bill bill)
{
this.bill = bill;
CheckBill = new Command(OnCheckBill);
InitializeComponent();
Title = Resource.EditBill;
}
private void OnCheckBill()
{
}
}
}

View File

@ -12,6 +12,10 @@
<ContentPage.Resources>
<ui:TitleDateConverter x:Key="titleDateConverter"/>
<ui:MoneyConverter x:Key="moneyConverter" MarkVisible="False" Absolute="True"/>
<ui:BalanceColorConverter x:Key="colorConverter"/>
<ui:UIBillConverter x:Key="billConverter"/>
<ui:IconConverter x:Key="iconConverter"/>
</ContentPage.Resources>
<Shell.TitleView>
@ -26,27 +30,44 @@
</Grid>
</Shell.TitleView>
<Grid RowDefinitions="Auto,*">
<Grid RowDefinitions="Auto, Auto, *">
<ui:BillingDate x:Name="billingDate" SelectedDate="{Binding SelectedDate}" DateSelected="OnDateSelected"/>
<ScrollView Grid.Row="1">
<Grid Padding="8" ColumnSpacing="8" ColumnDefinitions="Auto, *, Auto"
BackgroundColor="{DynamicResource PromptBackgroundColor}"
VerticalOptions="Start">
<ui:TintImage Source="bars.png" WidthRequest="23" HeightRequest="23"/>
<Label Grid.Column="1" Text="{r:Text NoRecords}" TextColor="{DynamicResource TextColor}"
<Grid Grid.Row="1" Padding="8" ColumnSpacing="8" ColumnDefinitions="Auto, *, Auto"
BackgroundColor="{DynamicResource PromptBackgroundColor}">
<ui:TintImage Source="bars.png" WidthRequest="23" HeightRequest="23"/>
<Label Grid.Column="1" Text="{r:Text NoRecords}" TextColor="{DynamicResource TextColor}"
VerticalOptions="Center"/>
<StackLayout Grid.Column="2" Orientation="Horizontal" Spacing="6">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding AddBilling}"/>
</StackLayout.GestureRecognizers>
<Label Text="{r:Text TapToMemo}" TextColor="{DynamicResource PrimaryColor}"
VerticalOptions="Center"/>
<StackLayout Grid.Column="2" Orientation="Horizontal" Spacing="6">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding AddBilling}"/>
</StackLayout.GestureRecognizers>
<Label Text="{r:Text TapToMemo}" TextColor="{DynamicResource PrimaryColor}"
VerticalOptions="Center"/>
<!--<Label Style="{DynamicResource IconLightStyle}"
Text="{x:Static local:Definition.IconRight}"
TextColor="{DynamicResource TabBarUnselectedColor}"/>-->
<ui:TintImage Source="right.png" WidthRequest="24" HeightRequest="24"/>
</StackLayout>
</Grid>
<ui:TintImage Source="right.png" WidthRequest="24" HeightRequest="24"/>
</StackLayout>
</Grid>
<!-- bill list -->
<ScrollView Grid.Row="2">
<ui:GroupStackLayout x:Name="billsLayout" ItemsSource="{Binding Bills}" Margin="0, 10, 0, 0">
<ui:GroupStackLayout.ItemTemplate>
<DataTemplate x:DataType="v:UIBill">
<Grid Padding="20, 0, 10, 0" ColumnSpacing="10"
ColumnDefinitions="Auto, *, Auto" RowDefinitions="Auto, Auto">
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
VerticalOptions="Center"
FontSize="Default" FontAttributes="Bold"/>
<Label Grid.Column="2" Text="{Binding Amount, Converter={StaticResource moneyConverter}}"
TextColor="{Binding Amount, Converter={StaticResource colorConverter}}"
VerticalOptions="Center"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding ., Converter={StaticResource billConverter}}"
FontSize="Small"
TextColor="{DynamicResource SecondaryTextColor}"/>
</Grid>
</DataTemplate>
</ui:GroupStackLayout.ItemTemplate>
</ui:GroupStackLayout>
</ScrollView>
<!--<ui:CircleButton Grid.Row="1" VerticalOptions="End" HorizontalOptions="End"
Margin="20" Padding="0"

View File

@ -1,5 +1,8 @@
using Billing.Models;
using Billing.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms;
namespace Billing.Views
@ -7,12 +10,18 @@ namespace Billing.Views
public partial class BillPage : BillingPage
{
private static readonly BindableProperty SelectedDateProperty = BindableProperty.Create(nameof(SelectedDate), typeof(DateTime), typeof(BillPage));
private static readonly BindableProperty BillsProperty = BindableProperty.Create(nameof(Bills), typeof(List<UIBill>), typeof(BillPage));
public DateTime SelectedDate
{
get => (DateTime)GetValue(SelectedDateProperty);
set => SetValue(SelectedDateProperty, value);
}
public List<UIBill> Bills
{
get => (List<UIBill>)GetValue(BillsProperty);
set => SetValue(BillsProperty, value);
}
public Command AddBilling { get; }
@ -29,7 +38,18 @@ namespace Billing.Views
{
SelectedDate = e.Date;
// TODO: while selecting date
var bills = App.Bills.Where(b =>
b.CreateTime.Year == e.Date.Year &&
b.CreateTime.Month == e.Date.Month &&
b.CreateTime.Day == e.Date.Day);
Bills = new List<UIBill>(bills.Select(b => new UIBill(b)
{
Icon = App.Categories.FirstOrDefault(c => c.Id == b.CategoryId)?.Icon ?? BaseModel.ICON_DEFAULT,
Name = b.Name,
DateCreation = b.CreateTime,
Amount = b.Amount,
Wallet = App.Accounts.FirstOrDefault(a => a.Id == b.WalletId)?.Name
}));
}
private void OnTitleDateLongPressed(object sender, EventArgs e)
@ -45,8 +65,51 @@ namespace Billing.Views
}
using (Tap.Start())
{
await Navigation.PushAsync(new AddBillPage());
var page = new AddBillPage(SelectedDate);
await Navigation.PushAsync(page);
}
}
}
public class UIBill : BindableObject
{
public static readonly BindableProperty IconProperty = BindableProperty.Create(nameof(Icon), typeof(string), typeof(UIBill));
public static readonly BindableProperty NameProperty = BindableProperty.Create(nameof(Name), typeof(string), typeof(UIBill));
public static readonly BindableProperty DateCreationProperty = BindableProperty.Create(nameof(DateCreation), typeof(DateTime), typeof(UIBill));
public static readonly BindableProperty AmountProperty = BindableProperty.Create(nameof(Amount), typeof(decimal), typeof(UIBill));
public static readonly BindableProperty WalletProperty = BindableProperty.Create(nameof(Wallet), typeof(string), typeof(UIBill));
public string Icon
{
get => (string)GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
public string Name
{
get => (string)GetValue(NameProperty);
set => SetValue(NameProperty, value);
}
public DateTime DateCreation
{
get => (DateTime)GetValue(DateCreationProperty);
set => SetValue(DateCreationProperty, value);
}
public decimal Amount
{
get => (decimal)GetValue(AmountProperty);
set => SetValue(AmountProperty, value);
}
public string Wallet
{
get => (string)GetValue(WalletProperty);
set => SetValue(WalletProperty, value);
}
public Bill Bill { get; }
public UIBill(Bill bill)
{
Bill = bill;
}
}
}

View File

@ -38,7 +38,9 @@ namespace Billing.Views
var source = new List<BillingIcon>
{
new() { Icon = BaseModel.ICON_DEFAULT },
new() { Icon = "wallet" }
new() { Icon = "wallet" },
new() { Icon = "creditcard" },
new() { Icon = "debitcard" }
};
source.AddRange(IconConverter.IconPreset.Select(icon => new BillingIcon { Icon = $"#brand#{icon.Key}" }));
foreach (var icon in source)