using System; using InABox.Core; using Xamarin.Forms; namespace InABox.Mobile { public abstract class MobileViewModel : BindableObject, IMobileViewModel { public Color SelectedColor => XF.Material.Forms.Material.Color.Surface; public Color SelectedTextColor => XF.Material.Forms.Material.Color.OnSurface; public Color UnselectedColor => XF.Material.Forms.Material.Color.Primary; public Color UnselectedTextColor => XF.Material.Forms.Material.Color.OnPrimary; public event MobileViewModelLoadedEvent Loaded; protected void OnLoaded() => Loaded?.Invoke(this, new MobileViewModelLoadedEventArgs()); } public abstract class MobileViewModel : MobileViewModel where TEntity : Entity, IRemotable, IPersistent where TShell : IShell { public static readonly BindableProperty ItemProperty = BindableProperty.Create( nameof(Item), typeof(TShell), typeof(MobileViewModel) ); public TShell Item { get => (TShell)GetValue(ItemProperty); set { SetValue(ItemProperty,value); DoLoad(); OnLoaded(); OnPropertyChanged(nameof(IsChanged)); } } protected abstract void DoLoad(); public abstract bool IsChanged { get; } public void DoChanged() => OnPropertyChanged(nameof(IsChanged)); } }