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

@ -10,10 +10,10 @@ namespace Billing.Views
{
public partial class AccountPage : BillingPage
{
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(List<AccountGrouping>), typeof(AccountPage));
private static readonly BindableProperty BalanceProperty = Helper.Create<decimal, AccountPage>(nameof(Balance));
private static readonly BindableProperty AssetProperty = Helper.Create<decimal, AccountPage>(nameof(Asset));
private static readonly BindableProperty LiabilityProperty = Helper.Create<decimal, AccountPage>(nameof(Liability));
private static readonly BindableProperty AccountsProperty = Helper.Create<List<AccountGrouping>, AccountPage>(nameof(Accounts));
public decimal Balance => (decimal)GetValue(BalanceProperty);
public decimal Asset => (decimal)GetValue(AssetProperty);
@ -129,6 +129,8 @@ namespace Billing.Views
}
RefreshBalance();
groupLayout.Refresh(accounts);
RankPage.Instance?.SetNeedRefresh();
_ = Task.Run(App.WriteAccounts);
}
@ -147,6 +149,8 @@ namespace Billing.Views
RefreshBalance(!add);
groupLayout.Refresh(accounts);
RankPage.Instance?.SetNeedRefresh();
Task.Run(App.WriteAccounts);
}
}

View File

@ -9,11 +9,11 @@ namespace Billing.Views
{
public partial class AddAccountPage : BillingPage
{
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 InitialProperty = BindableProperty.Create(nameof(Initial), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty MemoProperty = BindableProperty.Create(nameof(Memo), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty AccountNameProperty = Helper.Create<string, AddAccountPage>(nameof(AccountName));
private static readonly BindableProperty AccountIconProperty = Helper.Create<string, AddAccountPage>(nameof(AccountIcon));
private static readonly BindableProperty CategoryProperty = Helper.Create<AccountCategory, AddAccountPage>(nameof(Category));
private static readonly BindableProperty InitialProperty = Helper.Create<string, AddAccountPage>(nameof(Initial));
private static readonly BindableProperty MemoProperty = Helper.Create<string, AddAccountPage>(nameof(Memo));
public string AccountName
{

View File

@ -10,14 +10,14 @@ namespace Billing.Views
{
public partial class AddBillPage : BillingPage
{
private static readonly BindableProperty AmountProperty = BindableProperty.Create(nameof(Amount), typeof(string), typeof(AddBillPage));
private static readonly BindableProperty NameProperty = BindableProperty.Create(nameof(Name), typeof(string), typeof(AddBillPage));
private static readonly BindableProperty CategoryNameProperty = BindableProperty.Create(nameof(CategoryName), typeof(string), typeof(AddBillPage));
private static readonly BindableProperty WalletNameProperty = BindableProperty.Create(nameof(WalletName), typeof(string), typeof(AddBillPage));
private static readonly BindableProperty StoreProperty = BindableProperty.Create(nameof(Store), typeof(string), typeof(AddBillPage));
private static readonly BindableProperty CreatedDateProperty = BindableProperty.Create(nameof(CreatedDate), typeof(DateTime), typeof(AddBillPage));
private static readonly BindableProperty CreatedTimeProperty = BindableProperty.Create(nameof(CreatedTime), typeof(TimeSpan), typeof(AddBillPage));
private static readonly BindableProperty NoteProperty = BindableProperty.Create(nameof(Note), typeof(string), typeof(AddBillPage));
private static readonly BindableProperty AmountProperty = Helper.Create<string, AddBillPage>(nameof(Amount));
private static readonly BindableProperty NameProperty = Helper.Create<string, AddBillPage>(nameof(Name));
private static readonly BindableProperty CategoryNameProperty = Helper.Create<string, AddBillPage>(nameof(CategoryName));
private static readonly BindableProperty WalletNameProperty = Helper.Create<string, AddBillPage>(nameof(WalletName));
private static readonly BindableProperty StoreProperty = Helper.Create<string, AddBillPage>(nameof(Store));
private static readonly BindableProperty CreatedDateProperty = Helper.Create<DateTime, AddBillPage>(nameof(CreatedDate));
private static readonly BindableProperty CreatedTimeProperty = Helper.Create<TimeSpan, AddBillPage>(nameof(CreatedTime));
private static readonly BindableProperty NoteProperty = Helper.Create<string, AddBillPage>(nameof(Note));
public string Amount
{

View File

@ -10,10 +10,10 @@ namespace Billing.Views
{
public partial class AddCategoryPage : BillingPage
{
private static readonly BindableProperty CategoryNameProperty = BindableProperty.Create(nameof(CategoryName), typeof(string), typeof(AddCategoryPage));
private static readonly BindableProperty CategoryIconProperty = BindableProperty.Create(nameof(CategoryIcon), typeof(string), typeof(AddCategoryPage));
private static readonly BindableProperty TintColorProperty = BindableProperty.Create(nameof(TintColor), typeof(Color), typeof(AddCategoryPage));
private static readonly BindableProperty TintColorStringProperty = BindableProperty.Create(nameof(TintColorString), typeof(string), typeof(AddCategoryPage));
private static readonly BindableProperty CategoryNameProperty = Helper.Create<string, AddCategoryPage>(nameof(CategoryName));
private static readonly BindableProperty CategoryIconProperty = Helper.Create<string, AddCategoryPage>(nameof(CategoryIcon));
private static readonly BindableProperty TintColorProperty = Helper.Create<Color, AddCategoryPage>(nameof(TintColor));
private static readonly BindableProperty TintColorStringProperty = Helper.Create<string, AddCategoryPage>(nameof(TintColorString));
public string CategoryName
{

View File

@ -155,6 +155,8 @@ namespace Billing.Views
App.Bills.Remove(bill.Bill);
billsLayout.Refresh(bills);
RefreshBalance(bills);
RankPage.Instance?.SetNeedRefresh();
_ = Task.Run(App.WriteBills);
}
@ -191,17 +193,19 @@ namespace Billing.Views
}
RefreshBalance(Bills);
RankPage.Instance?.SetNeedRefresh();
Task.Run(App.WriteBills);
}
}
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 static readonly BindableProperty IconProperty = Helper.Create<string, UIBill>(nameof(Icon));
public static readonly BindableProperty NameProperty = Helper.Create<string, UIBill>(nameof(Name));
public static readonly BindableProperty DateCreationProperty = Helper.Create<DateTime, UIBill>(nameof(DateCreation));
public static readonly BindableProperty AmountProperty = Helper.Create<decimal, UIBill>(nameof(Amount));
public static readonly BindableProperty WalletProperty = Helper.Create<string, UIBill>(nameof(Wallet));
public string Icon
{

View File

@ -12,8 +12,8 @@ namespace Billing.Views
{
public partial class CategoryPage : BillingPage
{
private static readonly BindableProperty CategoriesProperty = BindableProperty.Create(nameof(Categories), typeof(IList), typeof(CategoryPage));
private static readonly BindableProperty IsTopCategoryProperty = BindableProperty.Create(nameof(IsTopCategory), typeof(bool), typeof(CategoryPage));
private static readonly BindableProperty CategoriesProperty = Helper.Create<IList, CategoryPage>(nameof(Categories));
private static readonly BindableProperty IsTopCategoryProperty = Helper.Create<bool, CategoryPage>(nameof(IsTopCategory));
public IList Categories
{
@ -198,11 +198,11 @@ namespace Billing.Views
public class UICategory : BindableObject
{
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(UICategory));
public static readonly BindableProperty IconProperty = BindableProperty.Create(nameof(Icon), typeof(string), typeof(UICategory));
public static readonly BindableProperty NameProperty = BindableProperty.Create(nameof(Name), typeof(string), typeof(UICategory));
public static readonly BindableProperty TintColorProperty = BindableProperty.Create(nameof(TintColor), typeof(Color), typeof(UICategory));
public static readonly BindableProperty IsTopCategoryProperty = BindableProperty.Create(nameof(IsTopCategory), typeof(bool), typeof(UICategory));
public static readonly BindableProperty IsCheckedProperty = Helper.Create<bool, UICategory>(nameof(IsChecked));
public static readonly BindableProperty IconProperty = Helper.Create<string, UICategory>(nameof(Icon));
public static readonly BindableProperty NameProperty = Helper.Create<string, UICategory>(nameof(Name));
public static readonly BindableProperty TintColorProperty = Helper.Create<Color, UICategory>(nameof(TintColor));
public static readonly BindableProperty IsTopCategoryProperty = Helper.Create<bool, UICategory>(nameof(IsTopCategory));
public bool IsChecked
{

View File

@ -11,8 +11,8 @@ namespace Billing.Views
{
public partial class CategorySelectPage : BillingPage
{
private static readonly BindableProperty TopCategoriesProperty = BindableProperty.Create(nameof(TopCategories), typeof(List<CategoryGrouping>), typeof(CategorySelectPage));
private static readonly BindableProperty SubCategoriesProperty = BindableProperty.Create(nameof(SubCategories), typeof(List<UICategory>), typeof(CategorySelectPage));
private static readonly BindableProperty TopCategoriesProperty = Helper.Create<List<CategoryGrouping>, CategorySelectPage>(nameof(TopCategories));
private static readonly BindableProperty SubCategoriesProperty = Helper.Create<List<UICategory>, CategorySelectPage>(nameof(SubCategories));
public List<CategoryGrouping> TopCategories
{

View File

@ -9,7 +9,7 @@ namespace Billing.Views
{
public partial class IconSelectPage : BillingPage
{
public static readonly BindableProperty IconsSourceProperty = BindableProperty.Create(nameof(IconsSource), typeof(IList<BillingIcon>), typeof(IconSelectPage));
public static readonly BindableProperty IconsSourceProperty = Helper.Create<IList<BillingIcon>, IconSelectPage>(nameof(IconsSource));
public IList<BillingIcon> IconsSource
{
@ -103,7 +103,7 @@ namespace Billing.Views
public class BillingIcon : BindableObject
{
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(BillingIcon));
public static readonly BindableProperty IsCheckedProperty = Helper.Create<bool, BillingIcon>(nameof(IsChecked));
public bool IsChecked
{

View File

@ -142,7 +142,7 @@
BackgroundColor="{DynamicResource WindowBackgroundColor}"
HeightRequest="{Binding Height, Source={x:Reference gridFilter}}"/>
<Grid x:Name="gridFilter" VerticalOptions="Start" Opacity="0" RowDefinitions="Auto, Auto, Auto, Auto">
<ui:SegmentedControl Margin="16, 16, 16, 3" VerticalOptions="Center"
<ui:SegmentedControl VerticalOptions="Center" Margin="10, 10, 10, 3"
SelectedSegmentIndex="{Binding SegmentType, Mode=TwoWay}"
SelectedTextColor="{DynamicResource TextColor}"
TintColor="{DynamicResource PromptBackgroundColor}">
@ -151,22 +151,13 @@
<ui:SegmentedControlOption Text="{r:Text Income}"/>
</ui:SegmentedControl.Children>
</ui:SegmentedControl>
<ScrollView Grid.Row="1" Margin="16, 6, 16, 3">
<ui:SegmentedControl SelectedSegmentIndex="{Binding SegmentDate, Mode=TwoWay}"
SelectedTextColor="{DynamicResource TextColor}"
TintColor="{DynamicResource PromptBackgroundColor}">
<ui:SegmentedControl.Children>
<ui:SegmentedControlOption Text="{r:Text Monthly}"/>
<ui:SegmentedControlOption Text="{r:Text Today}"/>
<ui:SegmentedControlOption Text="{r:Text PastMonth}"/>
<ui:SegmentedControlOption Text="{r:Text PastQuarter}"/>
<ui:SegmentedControlOption Text="{r:Text PastSixMonths}"/>
<ui:SegmentedControlOption Text="{r:Text PastYear}"/>
<ui:SegmentedControlOption Text="{r:Text Total}"/>
</ui:SegmentedControl.Children>
</ui:SegmentedControl>
</ScrollView>
<Grid Grid.Row="2" ColumnDefinitions="*, Auto, *" Margin="10">
<ui:OptionPicker Grid.Row="1" VerticalOptions="Center" Margin="10, 3"
HorizontalTextAlignment="Center" FontSize="16"
ItemsSource="{Binding DateTypes}"
SelectedIndex="{Binding SegmentDate, Mode=TwoWay}"
TextColor="{DynamicResource TextColor}"
ios:Picker.UpdateMode="WhenFinished"/>
<Grid Grid.Row="2" ColumnDefinitions="*, Auto, *" Margin="10, 3">
<ui:OptionDatePicker Date="{Binding StartPickerDate, Mode=TwoWay}"
FontSize="16" TextColor="{DynamicResource TextColor}"
VerticalOptions="Center"

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));
}
}