first test-flight version
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Billing.Languages;
|
||||
using Billing.Models;
|
||||
using Billing.UI;
|
||||
using Xamarin.Forms;
|
||||
@ -20,6 +21,7 @@ namespace Billing.Views
|
||||
public List<AccountGrouping> Accounts => (List<AccountGrouping>)GetValue(AccountsProperty);
|
||||
|
||||
public Command EditAccount { get; }
|
||||
public Command DeleteAccount { get; }
|
||||
|
||||
private readonly List<AccountGrouping> accounts = new();
|
||||
private bool initialized;
|
||||
@ -27,6 +29,7 @@ namespace Billing.Views
|
||||
public AccountPage()
|
||||
{
|
||||
EditAccount = new Command(OnEditAccount);
|
||||
DeleteAccount = new Command(OnDeleteAccount);
|
||||
SetValue(AccountsProperty, accounts);
|
||||
|
||||
InitializeComponent();
|
||||
@ -34,7 +37,7 @@ namespace Billing.Views
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
if (!initialized)
|
||||
if (!initialized || accounts.Count == 0)
|
||||
{
|
||||
initialized = true;
|
||||
accounts.Clear();
|
||||
@ -52,6 +55,12 @@ namespace Billing.Views
|
||||
}
|
||||
}
|
||||
groupLayout.Refresh(accounts);
|
||||
RefreshBalance();
|
||||
}
|
||||
|
||||
private void RefreshBalance()
|
||||
{
|
||||
SetValue(BalanceProperty, App.Accounts.Sum(a => a.Balance));
|
||||
}
|
||||
|
||||
private void AddToAccountGroup(Account account)
|
||||
@ -94,6 +103,35 @@ namespace Billing.Views
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnDeleteAccount(object o)
|
||||
{
|
||||
if (Tap.IsBusy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using (Tap.Start())
|
||||
{
|
||||
if (o is Account account)
|
||||
{
|
||||
var result = await this.ShowConfirm(Resource.ConfirmDeleteAccount);
|
||||
if (result)
|
||||
{
|
||||
var group = accounts.FirstOrDefault(a => a.Key == account.Category);
|
||||
if (group == null)
|
||||
{
|
||||
Helper.Error("account.delete", "unexpected deleting account, cannot find the current category");
|
||||
return;
|
||||
}
|
||||
group.Remove(account);
|
||||
groupLayout.Refresh(accounts);
|
||||
RefreshBalance();
|
||||
|
||||
_ = Task.Run(App.WriteAccounts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AccountChecked(object sender, AccountEventArgs e)
|
||||
{
|
||||
if (e.Account.Id < 0)
|
||||
@ -102,6 +140,7 @@ namespace Billing.Views
|
||||
AddToAccountGroup(e.Account);
|
||||
}
|
||||
groupLayout.Refresh(accounts);
|
||||
RefreshBalance();
|
||||
|
||||
Task.Run(App.WriteAccounts);
|
||||
}
|
||||
|
Reference in New Issue
Block a user