From f5f16d43f434e7e034f876abf0a36f4b899ade6f Mon Sep 17 00:00:00 2001 From: Tsanie Date: Fri, 11 Mar 2022 13:17:00 +0800 Subject: [PATCH] format BindableProperty & fix a tiny issue about rank page refreshing --- Billing.Shared/Languages/Resource.cs | 8 +++ Billing.Shared/Languages/en.xml | 3 + Billing.Shared/Languages/zh-CN.xml | 3 + Billing.Shared/Themes/BaseTheme.cs | 8 +++ Billing.Shared/UI/CustomControl.cs | 4 +- Billing.Shared/UI/GroupStackLayout.cs | 19 +++---- Billing.Shared/UI/OptionsCells.cs | 52 +++++++++++------ Billing.Shared/UI/WrapLayout.cs | 15 +++-- Billing.Shared/Views/AccountPage.xaml.cs | 12 ++-- Billing.Shared/Views/AddAccountPage.xaml.cs | 10 ++-- Billing.Shared/Views/AddBillPage.xaml.cs | 16 +++--- Billing.Shared/Views/AddCategoryPage.xaml.cs | 8 +-- Billing.Shared/Views/BillPage.xaml.cs | 14 +++-- Billing.Shared/Views/CategoryPage.xaml.cs | 14 ++--- .../Views/CategorySelectPage.xaml.cs | 4 +- Billing.Shared/Views/IconSelectPage.xaml.cs | 4 +- Billing.Shared/Views/RankPage.xaml | 25 +++----- Billing.Shared/Views/RankPage.xaml.cs | 57 +++++++++++++++---- .../Billing.Android/Billing.Android.csproj | 1 + .../Properties/AndroidManifest.xml | 2 +- .../Renderers/OptionPickerRenderer.cs | 29 ++++++++++ .../Renderers/OptionTimePickerRenderer.cs | 5 +- Billing/Billing.iOS/Billing.iOS.csproj | 1 + Billing/Billing.iOS/Info.plist | 4 +- .../Renderers/OptionPickerRenderer.cs | 46 +++++++++++++++ 25 files changed, 256 insertions(+), 108 deletions(-) create mode 100644 Billing/Billing.Android/Renderers/OptionPickerRenderer.cs create mode 100644 Billing/Billing.iOS/Renderers/OptionPickerRenderer.cs diff --git a/Billing.Shared/Languages/Resource.cs b/Billing.Shared/Languages/Resource.cs index 081a3a5..4eec6cf 100644 --- a/Billing.Shared/Languages/Resource.cs +++ b/Billing.Shared/Languages/Resource.cs @@ -16,6 +16,14 @@ namespace Billing.Languages public static string ConfirmDeleteBill => Text(nameof(ConfirmDeleteBill)); public static string TitleDateFormat => Text(nameof(TitleDateFormat)); public static string DateRangeFormat => Text(nameof(DateRangeFormat)); + public static string Custom => Text(nameof(Custom)); + public static string Monthly => Text(nameof(Monthly)); + public static string Today => Text(nameof(Today)); + public static string PastMonth => Text(nameof(PastMonth)); + public static string PastQuarter => Text(nameof(PastQuarter)); + public static string PastSixMonths => Text(nameof(PastSixMonths)); + public static string PastYear => Text(nameof(PastYear)); + public static string Total => Text(nameof(Total)); public static string Cash => Text(nameof(Cash)); public static string CreditCard => Text(nameof(CreditCard)); public static string DebitCard => Text(nameof(DebitCard)); diff --git a/Billing.Shared/Languages/en.xml b/Billing.Shared/Languages/en.xml index 7bc6922..942e2e3 100644 --- a/Billing.Shared/Languages/en.xml +++ b/Billing.Shared/Languages/en.xml @@ -21,6 +21,9 @@ MM/dd/yyyy MM/dd To + Type + Preset + Custom Monthly Today Past Month diff --git a/Billing.Shared/Languages/zh-CN.xml b/Billing.Shared/Languages/zh-CN.xml index 1dab13b..a786a4b 100644 --- a/Billing.Shared/Languages/zh-CN.xml +++ b/Billing.Shared/Languages/zh-CN.xml @@ -21,6 +21,9 @@ yyyy年MM月dd日 MM月dd日 + 类型 + 预设 + 自定义 当月 今日 一个月 diff --git a/Billing.Shared/Themes/BaseTheme.cs b/Billing.Shared/Themes/BaseTheme.cs index 26f820e..de45714 100644 --- a/Billing.Shared/Themes/BaseTheme.cs +++ b/Billing.Shared/Themes/BaseTheme.cs @@ -80,6 +80,14 @@ namespace Billing.Themes new Setter { Property = TimePicker.FontFamilyProperty, Value = regularFontFamily } } }); + Add(new Style(typeof(OptionPicker)) + { + Setters = + { + new Setter { Property = Picker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(TimePicker)) }, + new Setter { Property = Picker.FontFamilyProperty, Value = regularFontFamily } + } + }); Add(new Style(typeof(TintImage)) { Setters = diff --git a/Billing.Shared/UI/CustomControl.cs b/Billing.Shared/UI/CustomControl.cs index 17baaab..8ee262f 100644 --- a/Billing.Shared/UI/CustomControl.cs +++ b/Billing.Shared/UI/CustomControl.cs @@ -34,8 +34,8 @@ namespace Billing.UI public class LongPressGrid : Grid { - public static readonly BindableProperty LongCommandProperty = BindableProperty.Create(nameof(LongCommand), typeof(Command), typeof(LongPressGrid)); - public static readonly BindableProperty LongCommandParameterProperty = BindableProperty.Create(nameof(LongCommandParameter), typeof(object), typeof(LongPressGrid)); + public static readonly BindableProperty LongCommandProperty = Helper.Create(nameof(LongCommand)); + public static readonly BindableProperty LongCommandParameterProperty = Helper.Create(nameof(LongCommandParameter)); public Command LongCommand { diff --git a/Billing.Shared/UI/GroupStackLayout.cs b/Billing.Shared/UI/GroupStackLayout.cs index 37bd0b7..b4d639e 100644 --- a/Billing.Shared/UI/GroupStackLayout.cs +++ b/Billing.Shared/UI/GroupStackLayout.cs @@ -5,12 +5,12 @@ namespace Billing.UI { public class GroupStackLayout : Layout { - public static readonly BindableProperty GroupHeaderTemplateProperty = BindableProperty.Create(nameof(GroupHeaderTemplate), typeof(DataTemplate), typeof(GroupStackLayout)); - public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(GroupStackLayout)); - public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IList), typeof(GroupStackLayout), propertyChanged: OnItemsSourcePropertyChanged); - public static readonly BindableProperty SpacingProperty = BindableProperty.Create(nameof(Spacing), typeof(double), typeof(GroupStackLayout), defaultValue: 4d); - public static readonly BindableProperty RowHeightProperty = BindableProperty.Create(nameof(RowHeight), typeof(double), typeof(GroupStackLayout), defaultValue: 32d); - public static readonly BindableProperty GroupHeightProperty = BindableProperty.Create(nameof(GroupHeight), typeof(double), typeof(GroupStackLayout), defaultValue: 24d); + public static readonly BindableProperty GroupHeaderTemplateProperty = Helper.Create(nameof(GroupHeaderTemplate)); + public static readonly BindableProperty ItemTemplateProperty = Helper.Create(nameof(ItemTemplate)); + public static readonly BindableProperty ItemsSourceProperty = Helper.Create(nameof(ItemsSource), propertyChanged: OnItemsSourcePropertyChanged); + public static readonly BindableProperty SpacingProperty = Helper.Create(nameof(Spacing), defaultValue: 4d); + public static readonly BindableProperty RowHeightProperty = Helper.Create(nameof(RowHeight), defaultValue: 32d); + public static readonly BindableProperty GroupHeightProperty = Helper.Create(nameof(GroupHeight), defaultValue: 24d); public DataTemplate GroupHeaderTemplate { @@ -43,17 +43,16 @@ namespace Billing.UI set => SetValue(GroupHeightProperty, value); } - private static void OnItemsSourcePropertyChanged(BindableObject obj, object old, object @new) + private static void OnItemsSourcePropertyChanged(GroupStackLayout stack, IList old, IList list) { - var stack = (GroupStackLayout)obj; stack.lastWidth = -1; - if (@new == null) + if (list == null) { //stack.cachedLayout.Clear(); stack.Children.Clear(); stack.InvalidateLayout(); } - else if (@new is IList list) + else { stack.freezed = true; //stack.cachedLayout.Clear(); diff --git a/Billing.Shared/UI/OptionsCells.cs b/Billing.Shared/UI/OptionsCells.cs index 9a4e1dd..35766b4 100644 --- a/Billing.Shared/UI/OptionsCells.cs +++ b/Billing.Shared/UI/OptionsCells.cs @@ -4,16 +4,32 @@ using Xamarin.Forms; namespace Billing.UI { + public enum BorderStyle + { + None = 0, + RoundedRect + } + public class OptionEntry : Entry { } public class OptionEditor : Editor { } + public class OptionPicker : Picker + { + public static readonly BindableProperty BorderStyleProperty = Helper.Create(nameof(BorderStyle)); + + public BorderStyle BorderStyle + { + get => (BorderStyle)GetValue(BorderStyleProperty); + set => SetValue(BorderStyleProperty, value); + } + } public class OptionDatePicker : DatePicker { } public class OptionTimePicker : TimePicker { } public abstract class OptionCell : ViewCell { - public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(OptionCell)); - public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(OptionCell)); - public static readonly BindableProperty IconProperty = BindableProperty.Create(nameof(Icon), typeof(ImageSource), typeof(OptionCell)); + public static readonly BindableProperty TitleProperty = Helper.Create(nameof(Title)); + public static readonly BindableProperty BackgroundColorProperty = Helper.Create(nameof(BackgroundColor)); + public static readonly BindableProperty IconProperty = Helper.Create(nameof(Icon)); public string Title { @@ -124,7 +140,7 @@ namespace Billing.UI public class OptionTextCell : OptionCell { - public static readonly BindableProperty DetailProperty = BindableProperty.Create(nameof(Detail), typeof(string), typeof(OptionTextCell)); + public static readonly BindableProperty DetailProperty = Helper.Create(nameof(Detail)); public string Detail { @@ -143,8 +159,8 @@ namespace Billing.UI public class OptionSelectCell : OptionTextCell { - public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(Command), typeof(OptionSelectCell)); - public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(OptionSelectCell)); + public static readonly BindableProperty CommandProperty = Helper.Create(nameof(Command)); + public static readonly BindableProperty CommandParameterProperty = Helper.Create(nameof(CommandParameter)); public Command Command { @@ -189,8 +205,8 @@ namespace Billing.UI public class OptionImageCell : OptionSelectCell { - public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create(nameof(ImageSource), typeof(ImageSource), typeof(OptionImageCell)); - public static readonly BindableProperty TintColorProperty = BindableProperty.Create(nameof(TintColor), typeof(Color?), typeof(OptionImageCell)); + public static readonly BindableProperty ImageSourceProperty = Helper.Create(nameof(ImageSource)); + public static readonly BindableProperty TintColorProperty = Helper.Create(nameof(TintColor)); [TypeConverter(typeof(ImageSourceConverter))] public ImageSource ImageSource @@ -240,7 +256,7 @@ namespace Billing.UI public class OptionSwitchCell : OptionCell { - public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(OptionSwitchCell)); + public static readonly BindableProperty IsToggledProperty = Helper.Create(nameof(IsToggled)); public bool IsToggled { @@ -258,7 +274,7 @@ namespace Billing.UI public class OptionDatePickerCell : OptionCell { - public static readonly BindableProperty DateProperty = BindableProperty.Create(nameof(Date), typeof(DateTime), typeof(OptionDatePickerCell)); + public static readonly BindableProperty DateProperty = Helper.Create(nameof(Date)); public DateTime Date { @@ -278,7 +294,7 @@ namespace Billing.UI public class OptionTimePickerCell : OptionCell { - public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan), typeof(OptionTimePickerCell)); + public static readonly BindableProperty TimeProperty = Helper.Create(nameof(Time)); public TimeSpan Time { @@ -298,9 +314,9 @@ namespace Billing.UI public class OptionEntryCell : OptionCell { - public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(OptionEntryCell)); - public static readonly BindableProperty KeyboardProperty = BindableProperty.Create(nameof(Keyboard), typeof(Keyboard), typeof(OptionEntryCell)); - public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create(nameof(Placeholder), typeof(string), typeof(OptionEntryCell)); + public static readonly BindableProperty TextProperty = Helper.Create(nameof(Text)); + public static readonly BindableProperty KeyboardProperty = Helper.Create(nameof(Keyboard), defaultValue: Keyboard.Default); + public static readonly BindableProperty PlaceholderProperty = Helper.Create(nameof(Placeholder)); public string Text { @@ -351,10 +367,10 @@ namespace Billing.UI public class OptionEditorCell : OptionVerticalCell { - public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(OptionEditorCell)); - public static readonly BindableProperty FontSizeProperty = BindableProperty.Create(nameof(FontSize), typeof(double), typeof(OptionEditorCell), defaultValue: Device.GetNamedSize(NamedSize.Default, typeof(Editor))); - public static readonly BindableProperty KeyboardProperty = BindableProperty.Create(nameof(Keyboard), typeof(Keyboard), typeof(OptionEditorCell), defaultValue: Keyboard.Default); - public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create(nameof(Placeholder), typeof(string), typeof(OptionEditorCell)); + public static readonly BindableProperty TextProperty = Helper.Create(nameof(Text)); + public static readonly BindableProperty FontSizeProperty = Helper.Create(nameof(FontSize), defaultValue: Device.GetNamedSize(NamedSize.Default, typeof(Editor))); + public static readonly BindableProperty KeyboardProperty = Helper.Create(nameof(Keyboard), defaultValue: Keyboard.Default); + public static readonly BindableProperty PlaceholderProperty = Helper.Create(nameof(Placeholder)); public string Text { diff --git a/Billing.Shared/UI/WrapLayout.cs b/Billing.Shared/UI/WrapLayout.cs index fa51728..80f796f 100644 --- a/Billing.Shared/UI/WrapLayout.cs +++ b/Billing.Shared/UI/WrapLayout.cs @@ -7,24 +7,23 @@ namespace Billing.UI { public class WrapLayout : Layout { - public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IList), typeof(WrapLayout), propertyChanged: OnItemsSourcePropertyChanged); - public static readonly BindableProperty ColumnSpacingProperty = BindableProperty.Create(nameof(ColumnSpacing), typeof(double), typeof(WrapLayout), defaultValue: 4d, propertyChanged: (obj, _, _) => ((WrapLayout)obj).InvalidateLayout()); - public static readonly BindableProperty RowSpacingProperty = BindableProperty.Create(nameof(RowSpacing), typeof(double), typeof(WrapLayout), defaultValue: 4d, propertyChanged: (obj, _, _) => ((WrapLayout)obj).InvalidateLayout()); + public static readonly BindableProperty ItemsSourceProperty = Helper.Create(nameof(ItemsSource), propertyChanged: OnItemsSourcePropertyChanged); + public static readonly BindableProperty ColumnSpacingProperty = Helper.Create(nameof(ColumnSpacing), defaultValue: 4d, propertyChanged: (layout, _, _) => layout.InvalidateLayout()); + public static readonly BindableProperty RowSpacingProperty = Helper.Create(nameof(RowSpacing), defaultValue: 4d, propertyChanged: (layout, _, _) => layout.InvalidateLayout()); - private static void OnItemsSourcePropertyChanged(BindableObject obj, object old, object @new) + private static void OnItemsSourcePropertyChanged(WrapLayout layout, IList old, IList list) { - var itemTemplate = BindableLayout.GetItemTemplate(obj); + var itemTemplate = BindableLayout.GetItemTemplate(layout); if (itemTemplate == null) { return; } - var layout = (WrapLayout)obj; - if (@new == null) + if (list == null) { layout.Children.Clear(); layout.InvalidateLayout(); } - else if (@new is IList list) + else { layout.freezed = true; layout.Children.Clear(); diff --git a/Billing.Shared/Views/AccountPage.xaml.cs b/Billing.Shared/Views/AccountPage.xaml.cs index 17e0ec4..3604e71 100644 --- a/Billing.Shared/Views/AccountPage.xaml.cs +++ b/Billing.Shared/Views/AccountPage.xaml.cs @@ -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), typeof(AccountPage)); + private static readonly BindableProperty BalanceProperty = Helper.Create(nameof(Balance)); + private static readonly BindableProperty AssetProperty = Helper.Create(nameof(Asset)); + private static readonly BindableProperty LiabilityProperty = Helper.Create(nameof(Liability)); + private static readonly BindableProperty AccountsProperty = Helper.Create, 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); } } diff --git a/Billing.Shared/Views/AddAccountPage.xaml.cs b/Billing.Shared/Views/AddAccountPage.xaml.cs index 8a3f463..ddae6cd 100644 --- a/Billing.Shared/Views/AddAccountPage.xaml.cs +++ b/Billing.Shared/Views/AddAccountPage.xaml.cs @@ -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(nameof(AccountName)); + private static readonly BindableProperty AccountIconProperty = Helper.Create(nameof(AccountIcon)); + private static readonly BindableProperty CategoryProperty = Helper.Create(nameof(Category)); + private static readonly BindableProperty InitialProperty = Helper.Create(nameof(Initial)); + private static readonly BindableProperty MemoProperty = Helper.Create(nameof(Memo)); public string AccountName { diff --git a/Billing.Shared/Views/AddBillPage.xaml.cs b/Billing.Shared/Views/AddBillPage.xaml.cs index f87aa2d..5d47c21 100644 --- a/Billing.Shared/Views/AddBillPage.xaml.cs +++ b/Billing.Shared/Views/AddBillPage.xaml.cs @@ -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(nameof(Amount)); + private static readonly BindableProperty NameProperty = Helper.Create(nameof(Name)); + private static readonly BindableProperty CategoryNameProperty = Helper.Create(nameof(CategoryName)); + private static readonly BindableProperty WalletNameProperty = Helper.Create(nameof(WalletName)); + private static readonly BindableProperty StoreProperty = Helper.Create(nameof(Store)); + private static readonly BindableProperty CreatedDateProperty = Helper.Create(nameof(CreatedDate)); + private static readonly BindableProperty CreatedTimeProperty = Helper.Create(nameof(CreatedTime)); + private static readonly BindableProperty NoteProperty = Helper.Create(nameof(Note)); public string Amount { diff --git a/Billing.Shared/Views/AddCategoryPage.xaml.cs b/Billing.Shared/Views/AddCategoryPage.xaml.cs index 9b9f108..f9d3430 100644 --- a/Billing.Shared/Views/AddCategoryPage.xaml.cs +++ b/Billing.Shared/Views/AddCategoryPage.xaml.cs @@ -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(nameof(CategoryName)); + private static readonly BindableProperty CategoryIconProperty = Helper.Create(nameof(CategoryIcon)); + private static readonly BindableProperty TintColorProperty = Helper.Create(nameof(TintColor)); + private static readonly BindableProperty TintColorStringProperty = Helper.Create(nameof(TintColorString)); public string CategoryName { diff --git a/Billing.Shared/Views/BillPage.xaml.cs b/Billing.Shared/Views/BillPage.xaml.cs index 9f08a56..e5f9d1b 100644 --- a/Billing.Shared/Views/BillPage.xaml.cs +++ b/Billing.Shared/Views/BillPage.xaml.cs @@ -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(nameof(Icon)); + public static readonly BindableProperty NameProperty = Helper.Create(nameof(Name)); + public static readonly BindableProperty DateCreationProperty = Helper.Create(nameof(DateCreation)); + public static readonly BindableProperty AmountProperty = Helper.Create(nameof(Amount)); + public static readonly BindableProperty WalletProperty = Helper.Create(nameof(Wallet)); public string Icon { diff --git a/Billing.Shared/Views/CategoryPage.xaml.cs b/Billing.Shared/Views/CategoryPage.xaml.cs index 3755309..b71a978 100644 --- a/Billing.Shared/Views/CategoryPage.xaml.cs +++ b/Billing.Shared/Views/CategoryPage.xaml.cs @@ -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(nameof(Categories)); + private static readonly BindableProperty IsTopCategoryProperty = Helper.Create(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(nameof(IsChecked)); + public static readonly BindableProperty IconProperty = Helper.Create(nameof(Icon)); + public static readonly BindableProperty NameProperty = Helper.Create(nameof(Name)); + public static readonly BindableProperty TintColorProperty = Helper.Create(nameof(TintColor)); + public static readonly BindableProperty IsTopCategoryProperty = Helper.Create(nameof(IsTopCategory)); public bool IsChecked { diff --git a/Billing.Shared/Views/CategorySelectPage.xaml.cs b/Billing.Shared/Views/CategorySelectPage.xaml.cs index 5c5c321..2e6f9e5 100644 --- a/Billing.Shared/Views/CategorySelectPage.xaml.cs +++ b/Billing.Shared/Views/CategorySelectPage.xaml.cs @@ -11,8 +11,8 @@ namespace Billing.Views { public partial class CategorySelectPage : BillingPage { - private static readonly BindableProperty TopCategoriesProperty = BindableProperty.Create(nameof(TopCategories), typeof(List), typeof(CategorySelectPage)); - private static readonly BindableProperty SubCategoriesProperty = BindableProperty.Create(nameof(SubCategories), typeof(List), typeof(CategorySelectPage)); + private static readonly BindableProperty TopCategoriesProperty = Helper.Create, CategorySelectPage>(nameof(TopCategories)); + private static readonly BindableProperty SubCategoriesProperty = Helper.Create, CategorySelectPage>(nameof(SubCategories)); public List TopCategories { diff --git a/Billing.Shared/Views/IconSelectPage.xaml.cs b/Billing.Shared/Views/IconSelectPage.xaml.cs index b5fc772..9347e7f 100644 --- a/Billing.Shared/Views/IconSelectPage.xaml.cs +++ b/Billing.Shared/Views/IconSelectPage.xaml.cs @@ -9,7 +9,7 @@ namespace Billing.Views { public partial class IconSelectPage : BillingPage { - public static readonly BindableProperty IconsSourceProperty = BindableProperty.Create(nameof(IconsSource), typeof(IList), typeof(IconSelectPage)); + public static readonly BindableProperty IconsSourceProperty = Helper.Create, IconSelectPage>(nameof(IconsSource)); public IList 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(nameof(IsChecked)); public bool IsChecked { diff --git a/Billing.Shared/Views/RankPage.xaml b/Billing.Shared/Views/RankPage.xaml index 3111df6..aa21262 100644 --- a/Billing.Shared/Views/RankPage.xaml +++ b/Billing.Shared/Views/RankPage.xaml @@ -142,7 +142,7 @@ BackgroundColor="{DynamicResource WindowBackgroundColor}" HeightRequest="{Binding Height, Source={x:Reference gridFilter}}"/> - @@ -151,22 +151,13 @@ - - - - - - - - - - - - - - + + instance; + private static readonly DateTime today = DateTime.Today; private static readonly BindableProperty SegmentTypeProperty = Helper.Create(nameof(SegmentType), defaultValue: 0, propertyChanged: OnSegmentTypeChanged); - private static readonly BindableProperty SegmentDateProperty = Helper.Create(nameof(SegmentDate), defaultValue: 0, propertyChanged: OnSegmentDateChanged); + private static readonly BindableProperty SegmentDateProperty = Helper.Create(nameof(SegmentDate), defaultValue: 1, propertyChanged: OnSegmentDateChanged); private static readonly BindableProperty StartDateProperty = Helper.Create(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 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 + { + 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)); } } diff --git a/Billing/Billing.Android/Billing.Android.csproj b/Billing/Billing.Android/Billing.Android.csproj index c82cc49..9c3a3be 100644 --- a/Billing/Billing.Android/Billing.Android.csproj +++ b/Billing/Billing.Android/Billing.Android.csproj @@ -91,6 +91,7 @@ + diff --git a/Billing/Billing.Android/Properties/AndroidManifest.xml b/Billing/Billing.Android/Properties/AndroidManifest.xml index 3de630b..5ccce71 100644 --- a/Billing/Billing.Android/Properties/AndroidManifest.xml +++ b/Billing/Billing.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/Billing/Billing.Android/Renderers/OptionPickerRenderer.cs b/Billing/Billing.Android/Renderers/OptionPickerRenderer.cs new file mode 100644 index 0000000..d172813 --- /dev/null +++ b/Billing/Billing.Android/Renderers/OptionPickerRenderer.cs @@ -0,0 +1,29 @@ +using Android.Content; +using Android.Graphics.Drawables; +using Billing.Droid.Renderers; +using Billing.UI; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Android; + +[assembly: ExportRenderer(typeof(OptionPicker), typeof(OptionPickerRenderer))] +namespace Billing.Droid.Renderers +{ + public class OptionPickerRenderer : PickerRenderer + { + public OptionPickerRenderer(Context context) : base(context) + { + } + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + var control = Control; + if (e.NewElement != null && control != null) + { + var drawable = new ColorDrawable(e.NewElement.BackgroundColor.ToAndroid()); + control.SetBackground(drawable); + } + } + } +} diff --git a/Billing/Billing.Android/Renderers/OptionTimePickerRenderer.cs b/Billing/Billing.Android/Renderers/OptionTimePickerRenderer.cs index 7dcbb21..e69c652 100644 --- a/Billing/Billing.Android/Renderers/OptionTimePickerRenderer.cs +++ b/Billing/Billing.Android/Renderers/OptionTimePickerRenderer.cs @@ -18,10 +18,11 @@ namespace Billing.Droid.Renderers { base.OnElementChanged(e); - if (e.NewElement != null) + var control = Control; + if (e.NewElement != null && control != null) { var drawable = new ColorDrawable(e.NewElement.BackgroundColor.ToAndroid()); - Control.SetBackground(drawable); + control.SetBackground(drawable); } } } diff --git a/Billing/Billing.iOS/Billing.iOS.csproj b/Billing/Billing.iOS/Billing.iOS.csproj index a65f362..9188daf 100644 --- a/Billing/Billing.iOS/Billing.iOS.csproj +++ b/Billing/Billing.iOS/Billing.iOS.csproj @@ -91,6 +91,7 @@ + diff --git a/Billing/Billing.iOS/Info.plist b/Billing/Billing.iOS/Info.plist index e2f0733..13847c2 100644 --- a/Billing/Billing.iOS/Info.plist +++ b/Billing/Billing.iOS/Info.plist @@ -44,8 +44,8 @@ UIFileSharingEnabled CFBundleVersion - 8 + 9 CFBundleShortVersionString - 0.8.309 + 0.9.311 diff --git a/Billing/Billing.iOS/Renderers/OptionPickerRenderer.cs b/Billing/Billing.iOS/Renderers/OptionPickerRenderer.cs new file mode 100644 index 0000000..fb1159d --- /dev/null +++ b/Billing/Billing.iOS/Renderers/OptionPickerRenderer.cs @@ -0,0 +1,46 @@ +using System.ComponentModel; +using Billing.iOS.Renderers; +using Billing.UI; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(OptionPicker), typeof(OptionPickerRenderer))] +namespace Billing.iOS.Renderers +{ + public class OptionPickerRenderer : PickerRenderer + { + protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) + { + base.OnElementPropertyChanged(sender, e); + + if (e.PropertyName == nameof(OptionPicker.BorderStyle)) + { + var control = Control; + if (control != null && Element is OptionPicker picker) + { + control.BorderStyle = picker.BorderStyle switch + { + BorderStyle.RoundedRect => UITextBorderStyle.RoundedRect, + _ => UITextBorderStyle.None + }; + } + } + } + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + var control = Control; + if (control != null && e.NewElement is OptionPicker picker) + { + control.BorderStyle = picker.BorderStyle switch + { + BorderStyle.RoundedRect => UITextBorderStyle.RoundedRect, + _ => UITextBorderStyle.None + }; + } + } + } +}