add account page detail

This commit is contained in:
2022-02-28 17:32:40 +08:00
parent 283acf7d35
commit 589c7514f2
17 changed files with 307 additions and 56 deletions

View File

@ -7,13 +7,13 @@ namespace Billing.UI
{
#region UI Properties
private static readonly BindableProperty SundayProperty = BindableProperty.Create(nameof(Sunday), typeof(BillingDay), typeof(BillingDate));
private static readonly BindableProperty MondayProperty = BindableProperty.Create(nameof(Monday), typeof(BillingDay), typeof(BillingDate));
private static readonly BindableProperty TuesdayProperty = BindableProperty.Create(nameof(Tuesday), typeof(BillingDay), typeof(BillingDate));
private static readonly BindableProperty WednesdayProperty = BindableProperty.Create(nameof(Wednesday), typeof(BillingDay), typeof(BillingDate));
private static readonly BindableProperty ThursdayProperty = BindableProperty.Create(nameof(Thursday), typeof(BillingDay), typeof(BillingDate));
private static readonly BindableProperty FridayProperty = BindableProperty.Create(nameof(Friday), typeof(BillingDay), typeof(BillingDate));
private static readonly BindableProperty SaturdayProperty = BindableProperty.Create(nameof(Saturday), typeof(BillingDay), typeof(BillingDate));
public static readonly BindableProperty SundayProperty = BindableProperty.Create(nameof(Sunday), typeof(BillingDay), typeof(BillingDate));
public static readonly BindableProperty MondayProperty = BindableProperty.Create(nameof(Monday), typeof(BillingDay), typeof(BillingDate));
public static readonly BindableProperty TuesdayProperty = BindableProperty.Create(nameof(Tuesday), typeof(BillingDay), typeof(BillingDate));
public static readonly BindableProperty WednesdayProperty = BindableProperty.Create(nameof(Wednesday), typeof(BillingDay), typeof(BillingDate));
public static readonly BindableProperty ThursdayProperty = BindableProperty.Create(nameof(Thursday), typeof(BillingDay), typeof(BillingDate));
public static readonly BindableProperty FridayProperty = BindableProperty.Create(nameof(Friday), typeof(BillingDay), typeof(BillingDate));
public static readonly BindableProperty SaturdayProperty = BindableProperty.Create(nameof(Saturday), typeof(BillingDay), typeof(BillingDate));
public BillingDay Sunday => (BillingDay)GetValue(SundayProperty);
public BillingDay Monday => (BillingDay)GetValue(MondayProperty);
@ -219,12 +219,12 @@ namespace Billing.UI
public class BillingDay : BindableObject
{
private static readonly BindableProperty DateProperty = BindableProperty.Create(nameof(Date), typeof(DateTime), typeof(BillingDay), propertyChanged: OnDatePropertyChanged);
private static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(BillingDay));
private static readonly BindableProperty FontFamilyProperty = BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(BillingDay), defaultValue: Definition.GetCascadiaRegularFontFamily());
private static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(BillingDay));
private static readonly BindableProperty OpacityProperty = BindableProperty.Create(nameof(Opacity), typeof(double), typeof(BillingDay), defaultValue: 1.0);
private static readonly BindableProperty TextOpacityProperty = BindableProperty.Create(nameof(TextOpacity), typeof(double), typeof(BillingDay), defaultValue: 1.0);
public static readonly BindableProperty DateProperty = BindableProperty.Create(nameof(Date), typeof(DateTime), typeof(BillingDay), propertyChanged: OnDatePropertyChanged);
public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(BillingDay));
public static readonly BindableProperty FontFamilyProperty = BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(BillingDay), defaultValue: Definition.GetCascadiaRegularFontFamily());
public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(BillingDay));
public static readonly BindableProperty OpacityProperty = BindableProperty.Create(nameof(Opacity), typeof(double), typeof(BillingDay), defaultValue: 1.0);
public static readonly BindableProperty TextOpacityProperty = BindableProperty.Create(nameof(TextOpacity), typeof(double), typeof(BillingDay), defaultValue: 1.0);
private static void OnDatePropertyChanged(BindableObject obj, object old, object @new)
{

View File

@ -0,0 +1,159 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Xamarin.Forms;
namespace Billing.UI
{
public class GroupStackLayout : Layout<View>
{
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 DataTemplate GroupHeaderTemplate
{
get => (DataTemplate)GetValue(GroupHeaderTemplateProperty);
set => SetValue(GroupHeaderTemplateProperty, value);
}
public DataTemplate ItemTemplate
{
get => (DataTemplate)GetValue(ItemTemplateProperty);
set => SetValue(ItemTemplateProperty, value);
}
public IList ItemsSource
{
get => (IList)GetValue(ItemsSourceProperty);
set => SetValue(ItemsSourceProperty, value);
}
public double Spacing
{
get => (double)GetValue(SpacingProperty);
set => SetValue(SpacingProperty, value);
}
private static void OnItemsSourcePropertyChanged(BindableObject obj, object old, object @new)
{
var stack = (GroupStackLayout)obj;
stack.lastWidth = -1;
if (@new == null)
{
stack.cachedLayout.Clear();
stack.Children.Clear();
stack.InvalidateLayout();
}
else if (@new is IList list)
{
stack.freezed = true;
stack.cachedLayout.Clear();
stack.Children.Clear();
var groupTemplate = stack.GroupHeaderTemplate;
var itemTemplate = stack.ItemTemplate;
for (var i = 0; i < list.Count; i++)
{
var item = list[i];
if (item is IList sublist)
{
if (groupTemplate != null)
{
var child = groupTemplate.CreateContent();
if (child is View view)
{
view.BindingContext = item;
stack.Children.Add(view);
}
}
foreach (var it in sublist)
{
var child = itemTemplate.CreateContent();
if (child is View view)
{
view.BindingContext = it;
stack.Children.Add(view);
}
}
}
else
{
var child = itemTemplate.CreateContent();
if (child is View view)
{
view.BindingContext = list[i];
stack.Children.Add(view);
}
}
}
stack.freezed = false;
stack.UpdateChildrenLayout();
stack.InvalidateLayout();
}
}
private readonly Dictionary<View, Rectangle> cachedLayout = new();
private bool freezed;
private double lastWidth = -1;
private SizeRequest lastSizeRequest;
public void Refresh(IList list)
{
OnItemsSourcePropertyChanged(this, null, list);
}
protected override void LayoutChildren(double x, double y, double width, double height)
{
if (freezed)
{
return;
}
var source = ItemsSource;
if (source == null || source.Count <= 0)
{
return;
}
var spacing = Spacing;
var lastHeight = 0.0;
foreach (var item in Children)
{
var measured = item.Measure(width, height, MeasureFlags.IncludeMargins);
var rect = new Rectangle(
0, lastHeight, width,
measured.Request.Height);
if (cachedLayout.TryGetValue(item, out var v))
{
if (v != rect)
{
cachedLayout[item] = rect;
item.Layout(rect);
}
}
else
{
cachedLayout.Add(item, rect);
item.Layout(rect);
}
lastHeight += rect.Height + spacing;
}
}
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
{
if (lastWidth == widthConstraint)
{
return lastSizeRequest;
}
lastWidth = widthConstraint;
var spacing = Spacing;
var lastHeight = 0.0;
foreach (var item in Children)
{
var measured = item.Measure(widthConstraint, heightConstraint, MeasureFlags.IncludeMargins);
lastHeight += measured.Request.Height + spacing;
}
lastSizeRequest = new SizeRequest(new Size(widthConstraint, lastHeight));
return lastSizeRequest;
}
}
}

View File

@ -0,0 +1,51 @@
using Billing.Themes;
using System.Collections;
using Xamarin.Forms;
namespace Billing.UI
{
public class ItemSelectPage : ContentPage
{
public ItemSelectPage(IList source)
{
Content = new ListView
{
ItemsSource = source,
ItemTemplate = new DataTemplate(() => new StackLayout
{
Orientation = StackOrientation.Horizontal,
Padding = new Thickness(20, 0),
Spacing = 10,
Children =
{
new Image
{
WidthRequest = 22,
HeightRequest = 22,
Aspect = Aspect.AspectFit,
VerticalOptions = LayoutOptions.Center
}
.Binding(Image.SourceProperty, "Icon"),
new Label
{
VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.TailTruncation
}
.Binding(Label.TextProperty, "Name")
.DynamicResource(Label.TextColorProperty, BaseTheme.TextColor)
}
})
}
.DynamicResource(BackgroundColorProperty, BaseTheme.WindowBackgroundColor);
}
}
public class SelectItem<T>
{
public string Icon { get; set; }
public T Value { get; set; }
public string Name { get; set; }
}
}

View File

@ -4,7 +4,6 @@ using Xamarin.Forms;
namespace Billing.UI
{
public class OptionEntry : Entry { }
public class OptionEditor : Editor { }