using Billing.Themes; using System; using Xamarin.Forms; namespace Billing.UI { public class TintImage : Image { public static readonly BindableProperty PrimaryColorProperty = BindableProperty.Create(nameof(PrimaryColor), typeof(Color?), typeof(TintImage)); public Color? PrimaryColor { get => (Color?)GetValue(PrimaryColorProperty); set => SetValue(PrimaryColorProperty, value); } } public class LongPressButton : Button { public event EventHandler LongPressed; public LongPressButton() { Padding = 0; BackgroundColor = Color.Transparent; } public void TriggerLongPress() { LongPressed?.Invoke(this, EventArgs.Empty); } } public class OptionEntry : Entry { } 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 string Title { get => (string)GetValue(TitleProperty); set => SetValue(TitleProperty, value); } public Color BackgroundColor { get => (Color)GetValue(BackgroundColorProperty); set => SetValue(BackgroundColorProperty, value); } protected abstract View Content { get; } public OptionCell() { View = new Grid { BindingContext = this, Padding = new Thickness(20, 0), ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(.3, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(.7, GridUnitType.Star) } }, Children = { new Label { LineBreakMode = LineBreakMode.TailTruncation, VerticalOptions = LayoutOptions.Center } .Binding(Label.TextProperty, nameof(Title)) .DynamicResource(Label.TextColorProperty, BaseTheme.TextColor), Content.GridColumn(1) } } .DynamicResource(VisualElement.BackgroundColorProperty, BaseTheme.OptionTintColor); } } public class OptionTextCell : OptionCell { public static readonly BindableProperty DetailProperty = BindableProperty.Create(nameof(Detail), typeof(string), typeof(OptionTextCell)); public string Detail { get => (string)GetValue(DetailProperty); set => SetValue(DetailProperty, value); } protected override View Content => new Label { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center } .Binding(Label.TextProperty, nameof(Detail)) .DynamicResource(Label.TextColorProperty, BaseTheme.SecondaryTextColor); } public class OptionSwitchCell : OptionCell { public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(OptionSwitchCell)); public bool IsToggled { get => (bool)GetValue(IsToggledProperty); set => SetValue(IsToggledProperty, value); } protected override View Content => new Switch { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center } .Binding(Switch.IsToggledProperty, nameof(IsToggled), BindingMode.TwoWay); } 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 string Text { get => (string)GetValue(TextProperty); set => SetValue(TextProperty, value); } public Keyboard Keyboard { get => (Keyboard)GetValue(KeyboardProperty); set => SetValue(KeyboardProperty, value); } public string Placeholder { get => (string)GetValue(PlaceholderProperty); set => SetValue(PlaceholderProperty, value); } protected override View Content => new OptionEntry { HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, VerticalOptions = LayoutOptions.Center, ReturnType = ReturnType.Next } .Binding(Entry.TextProperty, nameof(Text), BindingMode.TwoWay) .Binding(InputView.KeyboardProperty, nameof(Keyboard)) .Binding(Entry.PlaceholderProperty, nameof(Placeholder)) .DynamicResource(Entry.TextColorProperty, BaseTheme.TextColor) .DynamicResource(Entry.PlaceholderColorProperty, BaseTheme.SecondaryTextColor) .DynamicResource(VisualElement.BackgroundColorProperty, BaseTheme.OptionTintColor); } }