allow to select a date & fix issue

This commit is contained in:
2022-03-08 14:19:50 +08:00
parent 91db3caa15
commit 63ee572e8b
27 changed files with 368 additions and 158 deletions

View File

@ -1,4 +1,3 @@
using Billing.Languages;
using Billing.Models;
using Billing.UI;
using System;
@ -13,12 +12,19 @@ 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));
private static readonly BindableProperty NoBillsProperty = BindableProperty.Create(nameof(NoBills), typeof(bool), typeof(BillPage));
private static readonly BindableProperty IncomeProperty = BindableProperty.Create(nameof(Income), typeof(decimal), typeof(BillPage));
private static readonly BindableProperty SpendingProperty = BindableProperty.Create(nameof(Spending), typeof(decimal), typeof(BillPage));
private static readonly BindableProperty BalanceProperty = BindableProperty.Create(nameof(Balance), typeof(decimal), typeof(BillPage));
private static readonly DateTime dateNow = DateTime.Today;
private static readonly BindableProperty SelectedDateProperty = Helper.Create<DateTime, BillPage>(nameof(SelectedDate), defaultValue: dateNow, propertyChanged: OnSelectedDateChanged);
private static readonly BindableProperty BillsProperty = Helper.Create<List<UIBill>, BillPage>(nameof(Bills));
private static readonly BindableProperty NoBillsProperty = Helper.Create<bool, BillPage>(nameof(NoBills));
private static readonly BindableProperty IncomeProperty = Helper.Create<decimal, BillPage>(nameof(Income));
private static readonly BindableProperty SpendingProperty = Helper.Create<decimal, BillPage>(nameof(Spending));
private static readonly BindableProperty BalanceProperty = Helper.Create<decimal, BillPage>(nameof(Balance));
private static void OnSelectedDateChanged(BillPage page, DateTime old, DateTime @new)
{
page.titleDatePicker.Unfocus();
}
public DateTime SelectedDate
{
@ -35,20 +41,21 @@ namespace Billing.Views
public decimal Spending => (decimal)GetValue(SpendingProperty);
public decimal Balance => (decimal)GetValue(BalanceProperty);
public Command TitleDateTap { get; }
public Command TitleLongPressed { get; }
public Command EditBilling { get; }
public Command DeleteBilling { get; }
public BillPage()
{
TitleDateTap = new Command(OnTitleDateTapped);
TitleLongPressed = new Command(OnTitleDateLongPressed);
EditBilling = new Command(OnEditBilling);
DeleteBilling = new Command(OnDeleteBilling);
SelectedDate = DateTime.Now;
InitializeComponent();
billingDate.SetDateTime(DateTime.Now);
billingDate.SetDateTime(dateNow);
}
private void OnDateSelected(object sender, DateEventArgs e)
@ -57,10 +64,7 @@ namespace Billing.Views
Task.Run(() =>
{
var bills = App.Bills.Where(b =>
b.CreateTime.Year == e.Date.Year &&
b.CreateTime.Month == e.Date.Month &&
b.CreateTime.Day == e.Date.Day);
var bills = App.Bills.Where(b => Helper.IsSameDay(b.CreateTime, e.Date));
Bills = new List<UIBill>(bills.OrderBy(b => b.CreateTime).Select(b => WrapBill(b)));
RefreshBalance(Bills);
MainThread.BeginInvokeOnMainThread(async () => await scrollView.ScrollToAsync(0, 0, true));
@ -98,9 +102,19 @@ namespace Billing.Views
bill.Wallet = App.Accounts.FirstOrDefault(a => a.Id == bill.Bill.WalletId)?.Name;
}
private void OnTitleDateTapped()
{
titleDatePicker.Focus();
}
private void TitlePicker_DateSelected(object sender, DateChangedEventArgs e)
{
billingDate.SetDateTime(e.NewDate);
}
private void OnTitleDateLongPressed()
{
billingDate.SetDateTime(DateTime.Now);
billingDate.SetDateTime(DateTime.Today);
}
private async void OnEditBilling(object o)