From 4076b2c9ed109edd94a582ae057ed96f6510654b Mon Sep 17 00:00:00 2001 From: gaoyuan Date: Mon, 7 Mar 2022 21:31:27 +0800 Subject: [PATCH] fix issue --- Billing.Shared/Themes/BaseTheme.cs | 2 ++ Billing.Shared/UI/BillingPage.cs | 10 +++++++- Billing.Shared/UI/OptionsCells.cs | 13 ++++++++++- Billing.Shared/Views/AddAccountPage.xaml | 4 +++- Billing.Shared/Views/AddAccountPage.xaml.cs | 11 +++++++++ Billing.Shared/Views/AddBillPage.xaml | 3 ++- Billing.Shared/Views/AddBillPage.xaml.cs | 11 +++++++++ Billing.Shared/Views/AddCategoryPage.xaml | 3 ++- Billing.Shared/Views/AddCategoryPage.xaml.cs | 23 +++++++++++++++---- Billing.Shared/Views/CategoryPage.xaml | 2 +- Billing.Shared/Views/CategoryPage.xaml.cs | 15 +++++++----- Billing.Shared/Views/CategorySelectPage.xaml | 4 ++-- .../Views/CategorySelectPage.xaml.cs | 2 +- Billing.Shared/Views/IconSelectPage.xaml | 2 +- .../Properties/AndroidManifest.xml | 2 +- Billing/Billing.iOS/Billing.iOS.csproj | 1 + Billing/Billing.iOS/Info.plist | 4 ++-- .../Renderers/BillingPageRenderer.cs | 20 ++++++++++++++++ .../Renderers/TintImageRenderer.cs | 11 +++++---- 19 files changed, 114 insertions(+), 29 deletions(-) create mode 100644 Billing/Billing.iOS/Renderers/BillingPageRenderer.cs diff --git a/Billing.Shared/Themes/BaseTheme.cs b/Billing.Shared/Themes/BaseTheme.cs index 70abb41..b2d8dfe 100644 --- a/Billing.Shared/Themes/BaseTheme.cs +++ b/Billing.Shared/Themes/BaseTheme.cs @@ -5,6 +5,8 @@ namespace Billing.Themes { public abstract class BaseTheme : ResourceDictionary { + public static Color CurrentPrimaryColor => (Color)Application.Current.Resources[PrimaryColor]; + public const string CascadiaFontRegular = nameof(CascadiaFontRegular); public const string CascadiaFontBold = nameof(CascadiaFontBold); public const string RobotoCondensedFontRegular = nameof(RobotoCondensedFontRegular); diff --git a/Billing.Shared/UI/BillingPage.cs b/Billing.Shared/UI/BillingPage.cs index b403ff9..a5d6743 100644 --- a/Billing.Shared/UI/BillingPage.cs +++ b/Billing.Shared/UI/BillingPage.cs @@ -1,14 +1,22 @@ -using Billing.Themes; +using System; +using Billing.Themes; using Xamarin.Forms; namespace Billing.UI { public abstract class BillingPage : ContentPage { + public event EventHandler Loaded; + public BillingPage() { SetDynamicResource(BackgroundColorProperty, BaseTheme.WindowBackgroundColor); Shell.SetTabBarIsVisible(this, false); } + + public virtual void OnLoaded() + { + Loaded?.Invoke(this, EventArgs.Empty); + } } } \ No newline at end of file diff --git a/Billing.Shared/UI/OptionsCells.cs b/Billing.Shared/UI/OptionsCells.cs index 82b8e9a..1f87ce2 100644 --- a/Billing.Shared/UI/OptionsCells.cs +++ b/Billing.Shared/UI/OptionsCells.cs @@ -1,5 +1,6 @@ using Billing.Themes; using System; +using System.Threading.Tasks; using Xamarin.Forms; namespace Billing.UI @@ -377,7 +378,17 @@ namespace Billing.UI set => SetValue(PlaceholderProperty, value); } - protected override View Content => new OptionEditor + OptionEditor editor; + + public void SetFocus() + { + if (editor != null) + { + editor.Focus(); + } + } + + protected override View Content => editor = new OptionEditor { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill diff --git a/Billing.Shared/Views/AddAccountPage.xaml b/Billing.Shared/Views/AddAccountPage.xaml index 735ef92..10c8c36 100644 --- a/Billing.Shared/Views/AddAccountPage.xaml +++ b/Billing.Shared/Views/AddAccountPage.xaml @@ -21,13 +21,15 @@ - - diff --git a/Billing.Shared/Views/AddBillPage.xaml.cs b/Billing.Shared/Views/AddBillPage.xaml.cs index 990fe2d..f58b780 100644 --- a/Billing.Shared/Views/AddBillPage.xaml.cs +++ b/Billing.Shared/Views/AddBillPage.xaml.cs @@ -116,6 +116,17 @@ namespace Billing.Views } } + private bool focused; + + public override void OnLoaded() + { + if (!focused) + { + focused = true; + editorAmount.SetFocus(); + } + } + private async void OnCheckBill() { if (Tap.IsBusy) diff --git a/Billing.Shared/Views/AddCategoryPage.xaml b/Billing.Shared/Views/AddCategoryPage.xaml index 5e4bd9a..1880820 100644 --- a/Billing.Shared/Views/AddCategoryPage.xaml +++ b/Billing.Shared/Views/AddCategoryPage.xaml @@ -20,7 +20,8 @@ - diff --git a/Billing.Shared/Views/AddCategoryPage.xaml.cs b/Billing.Shared/Views/AddCategoryPage.xaml.cs index 67938fe..d80e05e 100644 --- a/Billing.Shared/Views/AddCategoryPage.xaml.cs +++ b/Billing.Shared/Views/AddCategoryPage.xaml.cs @@ -58,7 +58,7 @@ namespace Billing.Views if (category.TintColor == Color.Transparent || category.TintColor == default) { - TintColor = (Color)Application.Current.Resources[BaseTheme.PrimaryColor]; + TintColor = BaseTheme.CurrentPrimaryColor; } else { @@ -67,7 +67,7 @@ namespace Billing.Views } else { - TintColor = (Color)Application.Current.Resources[BaseTheme.PrimaryColor]; + TintColor = BaseTheme.CurrentPrimaryColor; } TintColorString = Helper.WrapColorString(TintColor.ToHex()); @@ -77,6 +77,17 @@ namespace Billing.Views InitializeComponent(); } + private bool focused; + + public override void OnLoaded() + { + if (!focused) + { + focused = true; + editorName.SetFocus(); + } + } + private void ColorPicker_ColorChanged(object sender, Color e) { TintColor = e; @@ -91,6 +102,8 @@ namespace Billing.Views } using (Tap.Start()) { + var currentColor = BaseTheme.CurrentPrimaryColor; + var tintColor = TintColor; var category = App.Categories.FirstOrDefault(c => c.Id == categoryId); if (category == null) { @@ -99,8 +112,8 @@ namespace Billing.Views Id = -1, Name = CategoryName, Icon = CategoryIcon, - TintColor = TintColor, - ParentId = parent?.Id ?? -1, + TintColor = tintColor == currentColor ? Color.Transparent : tintColor, + ParentId = parent?.Id, Type = parent?.Type ?? CategoryType.Spending }); } @@ -108,7 +121,7 @@ namespace Billing.Views { category.Name = CategoryName; category.Icon = CategoryIcon; - category.TintColor = TintColor; + category.TintColor = tintColor == currentColor ? Color.Transparent : tintColor; CategoryChecked?.Invoke(this, category); } await Navigation.PopAsync(); diff --git a/Billing.Shared/Views/CategoryPage.xaml b/Billing.Shared/Views/CategoryPage.xaml index eaa5dec..bf8c825 100644 --- a/Billing.Shared/Views/CategoryPage.xaml +++ b/Billing.Shared/Views/CategoryPage.xaml @@ -13,7 +13,7 @@ - diff --git a/Billing.Shared/Views/CategoryPage.xaml.cs b/Billing.Shared/Views/CategoryPage.xaml.cs index 2545e8e..3755309 100644 --- a/Billing.Shared/Views/CategoryPage.xaml.cs +++ b/Billing.Shared/Views/CategoryPage.xaml.cs @@ -26,14 +26,15 @@ namespace Billing.Views public Command Tapped { get; } private readonly int parentId; + private readonly Category parent; public CategoryPage(int pid = -1) { parentId = pid; - var category = App.Categories.FirstOrDefault(c => c.Id == pid); - Title = category?.Name ?? Resource.CategoryManage; + parent = App.Categories.FirstOrDefault(c => c.Id == pid); + Title = parent?.Name ?? Resource.CategoryManage; - if (category != null) + if (parent != null) { SetValue(IsTopCategoryProperty, false); Categories = App.Categories.Where(c => c.ParentId == pid).Select(c => WrapCategory(c)).ToList(); @@ -68,7 +69,7 @@ namespace Billing.Views Name = category.Name, IsTopCategory = IsTopCategory, TintColor = category.TintColor == Color.Transparent || category.TintColor == default ? - (Color)Application.Current.Resources[BaseTheme.PrimaryColor] : + BaseTheme.CurrentPrimaryColor : category.TintColor }; } @@ -81,7 +82,7 @@ namespace Billing.Views } using (Tap.Start()) { - var page = new AddCategoryPage(); + var page = new AddCategoryPage(parent: parent); page.CategoryChecked += OnCategoryChecked; await Navigation.PushAsync(page); } @@ -189,7 +190,9 @@ namespace Billing.Views { c.Name = c.Category.Name; c.Icon = c.Category.Icon; - c.TintColor = c.Category.TintColor; + c.TintColor = c.Category.TintColor == Color.Transparent || c.Category.TintColor == default ? + BaseTheme.CurrentPrimaryColor : + c.Category.TintColor; } } diff --git a/Billing.Shared/Views/CategorySelectPage.xaml b/Billing.Shared/Views/CategorySelectPage.xaml index 559ac79..3cb34da 100644 --- a/Billing.Shared/Views/CategorySelectPage.xaml +++ b/Billing.Shared/Views/CategorySelectPage.xaml @@ -17,7 +17,7 @@ - @@ -48,7 +48,7 @@ - + - + diff --git a/Billing/Billing.Android/Properties/AndroidManifest.xml b/Billing/Billing.Android/Properties/AndroidManifest.xml index f0ced59..dd74d19 100644 --- a/Billing/Billing.Android/Properties/AndroidManifest.xml +++ b/Billing/Billing.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - + diff --git a/Billing/Billing.iOS/Billing.iOS.csproj b/Billing/Billing.iOS/Billing.iOS.csproj index afd00b8..264e97e 100644 --- a/Billing/Billing.iOS/Billing.iOS.csproj +++ b/Billing/Billing.iOS/Billing.iOS.csproj @@ -88,6 +88,7 @@ + diff --git a/Billing/Billing.iOS/Info.plist b/Billing/Billing.iOS/Info.plist index b7517b4..e75ea94 100644 --- a/Billing/Billing.iOS/Info.plist +++ b/Billing/Billing.iOS/Info.plist @@ -45,8 +45,8 @@ UIFileSharingEnabled CFBundleVersion - 4 + 6 CFBundleShortVersionString - 0.4.306 + 0.6.307 diff --git a/Billing/Billing.iOS/Renderers/BillingPageRenderer.cs b/Billing/Billing.iOS/Renderers/BillingPageRenderer.cs new file mode 100644 index 0000000..cc74add --- /dev/null +++ b/Billing/Billing.iOS/Renderers/BillingPageRenderer.cs @@ -0,0 +1,20 @@ +using Billing.iOS.Renderers; +using Billing.UI; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(BillingPage), typeof(BillingPageRenderer))] +namespace Billing.iOS.Renderers +{ + public class BillingPageRenderer : PageRenderer + { + public override void ViewDidAppear(bool animated) + { + base.ViewDidAppear(animated); + if (Element is BillingPage page) + { + page.OnLoaded(); + } + } + } +} diff --git a/Billing/Billing.iOS/Renderers/TintImageRenderer.cs b/Billing/Billing.iOS/Renderers/TintImageRenderer.cs index bf380c2..614ed8c 100644 --- a/Billing/Billing.iOS/Renderers/TintImageRenderer.cs +++ b/Billing/Billing.iOS/Renderers/TintImageRenderer.cs @@ -19,13 +19,14 @@ namespace Billing.iOS.Renderers return; } - if (e.PropertyName == nameof(Image.Source)) + if (e.PropertyName == nameof(Image.Source) || + e.PropertyName == nameof(TintImage.PrimaryColor)) { Control.Image = Control.Image.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysTemplate); - } - else if (e.PropertyName == nameof(TintImage.PrimaryColor) && Element is TintImage image) - { - Control.TintColor = image.PrimaryColor?.ToUIColor(); + if (Element is TintImage image) + { + Control.TintColor = image.PrimaryColor?.ToUIColor(); + } } } protected override void OnElementChanged(ElementChangedEventArgs e)