format BindableProperty & fix a tiny issue about rank page refreshing

This commit is contained in:
2022-03-11 13:17:00 +08:00
parent 71c1a7f0f1
commit f5f16d43f4
25 changed files with 256 additions and 108 deletions

View File

@ -16,7 +16,8 @@ namespace Billing.Views
{
public enum DateType : int
{
Monthly = 0,
Custom = 0,
Monthly,
Today,
PastMonth,
PastQuarter,
@ -27,10 +28,13 @@ namespace Billing.Views
public partial class RankPage : BillingPage
{
private static RankPage instance;
public static RankPage Instance => instance;
private static readonly DateTime today = DateTime.Today;
private static readonly BindableProperty SegmentTypeProperty = Helper.Create<int, RankPage>(nameof(SegmentType), defaultValue: 0, propertyChanged: OnSegmentTypeChanged);
private static readonly BindableProperty SegmentDateProperty = Helper.Create<int, RankPage>(nameof(SegmentDate), defaultValue: 0, propertyChanged: OnSegmentDateChanged);
private static readonly BindableProperty SegmentDateProperty = Helper.Create<int, RankPage>(nameof(SegmentDate), defaultValue: 1, propertyChanged: OnSegmentDateChanged);
private static readonly BindableProperty StartDateProperty = Helper.Create<DateTime, RankPage>(nameof(StartDate),
defaultValue: today.AddDays(1 - today.Day),
propertyChanged: OnDateChanged);
@ -83,7 +87,7 @@ namespace Billing.Views
{
if (!page.isLocked)
{
page.SegmentDate = -1;
page.SegmentDate = 0;
page.StartDate = @new.Date;
}
}
@ -91,7 +95,7 @@ namespace Billing.Views
{
if (!page.isLocked)
{
page.SegmentDate = -1;
page.SegmentDate = 0;
page.EndDate = @new.Date.LastMoment();
}
}
@ -160,6 +164,8 @@ namespace Billing.Views
public decimal Spending => (decimal)GetValue(SpendingProperty);
public decimal Balance => (decimal)GetValue(BalanceProperty);
public List<string> DateTypes { get; }
public Command LeftCommand { get; }
public Command RightCommand { get; }
public Command FilterCommand { get; }
@ -170,11 +176,15 @@ namespace Billing.Views
private bool isFilterToggled;
private bool isFreezed;
private bool isLocked;
private bool needRefresh = true;
private const int FILTER_HEIGHT = 100;
private readonly SKTypeface font;
public RankPage()
{
instance = this;
LeftCommand = new Command(OnLeftCommand);
RightCommand = new Command(OnRightCommand);
FilterCommand = new Command(OnFilterCommand);
@ -186,20 +196,41 @@ namespace Billing.Views
font = style.CreateTypeface(SKFontStyle.Normal);
}
DateTypes = new List<string>
{
Resource.Custom,
Resource.Monthly,
Resource.Today,
Resource.PastMonth,
Resource.PastQuarter,
Resource.PastSixMonths,
Resource.PastYear,
Resource.Total
};
InitializeComponent();
gridFilter.TranslationY = -60;
panelFilter.TranslationY = -60;
gridFilter.TranslationY = -FILTER_HEIGHT;
panelFilter.TranslationY = -FILTER_HEIGHT;
}
public override void OnLoaded()
public void SetNeedRefresh()
{
OnDateChanged(this);
needRefresh = true;
}
protected override void OnAppearing()
{
if (needRefresh)
{
needRefresh = false;
OnDateChanged(this);
}
}
private void OnDateTypeCommand(DateType index)
{
if (index < 0)
if (index < DateType.Monthly || index > DateType.Total)
{
return;
}
@ -251,6 +282,10 @@ namespace Billing.Views
max = b.CreateTime;
}
});
if (min == DateTime.MaxValue && max == DateTime.MinValue)
{
return;
}
StartDate = min.Date;
EndDate = max.Date.LastMoment();
break;
@ -402,9 +437,9 @@ namespace Billing.Views
else
{
await Task.WhenAll(
gridFilter.TranslateTo(0, -60, easing: Easing.CubicIn),
gridFilter.TranslateTo(0, -FILTER_HEIGHT, easing: Easing.CubicIn),
gridFilter.FadeTo(0, easing: Easing.CubicIn),
panelFilter.TranslateTo(0, -60, easing: Easing.CubicIn),
panelFilter.TranslateTo(0, -FILTER_HEIGHT, easing: Easing.CubicIn),
panelFilter.FadeTo(0, easing: Easing.CubicIn));
}
}