MobileModuleItem.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.ComponentModel;
  3. using System.Runtime.CompilerServices;
  4. using Xamarin.Forms;
  5. namespace InABox.Mobile
  6. {
  7. public class ModuleMenuItemTappedArgs :EventArgs
  8. {
  9. }
  10. public delegate void ModuleMenuItemTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args);
  11. public interface IModuleMenuItem
  12. {
  13. String Header { get; set; }
  14. String Description { get; set; }
  15. ImageSource Thumbnail { get; set; }
  16. bool IsEnabled { get; set; }
  17. bool IsVisible { get; set; }
  18. event ModuleMenuItemTapped Tapped;
  19. string Alert { get; set; }
  20. void Tap();
  21. }
  22. public class MobileModuleItem : BindableObject, IModuleMenuItem
  23. {
  24. public static readonly BindableProperty HeaderProperty =
  25. BindableProperty.Create(nameof(Header), typeof(String), typeof(MobileModuleItem), "");
  26. public string Header
  27. {
  28. get => (String)GetValue(HeaderProperty);
  29. set => SetValue(HeaderProperty, value);
  30. }
  31. public static readonly BindableProperty DescriptionProperty =
  32. BindableProperty.Create(nameof(Description), typeof(String), typeof(MobileModuleItem), "");
  33. public string Description
  34. {
  35. get => (String)GetValue(DescriptionProperty);
  36. set => SetValue(DescriptionProperty, value);
  37. }
  38. public static readonly BindableProperty ThumbnailProperty =
  39. BindableProperty.Create(nameof(Thumbnail), typeof(ImageSource), typeof(MobileModuleItem), null);
  40. public ImageSource Thumbnail
  41. {
  42. get => (ImageSource)GetValue(ThumbnailProperty);
  43. set => SetValue(ThumbnailProperty, value);
  44. }
  45. public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(
  46. nameof(BackgroundColor),
  47. typeof(Color),
  48. typeof(MobileModuleItem),
  49. XF.Material.Forms.Material.Color.Surface);
  50. public Color BackgroundColor
  51. {
  52. get => (Color)GetValue(BackgroundColorProperty);
  53. set => SetValue(BackgroundColorProperty, value);
  54. }
  55. public static readonly BindableProperty BorderColorProperty = BindableProperty.Create(
  56. nameof(BorderColor),
  57. typeof(Color),
  58. typeof(MobileModuleItem),
  59. XF.Material.Forms.Material.Color.SecondaryVariant);
  60. public Color BorderColor
  61. {
  62. get => (Color)GetValue(BorderColorProperty);
  63. set => SetValue(BorderColorProperty, value);
  64. }
  65. public static readonly BindableProperty TextColorProperty = BindableProperty.Create(
  66. nameof(TextColor),
  67. typeof(Color),
  68. typeof(MobileModuleItem),
  69. XF.Material.Forms.Material.Color.OnSurface);
  70. public Color TextColor
  71. {
  72. get => (Color)GetValue(TextColorProperty);
  73. set => SetValue(TextColorProperty, value);
  74. }
  75. public static readonly BindableProperty IsEnabledProperty =
  76. BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(MobileModuleItem), true);
  77. public bool IsEnabled
  78. {
  79. get => (bool)GetValue(IsEnabledProperty);
  80. set => SetValue(IsEnabledProperty, value);
  81. }
  82. public static readonly BindableProperty IsVisibleProperty =
  83. BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(MobileModuleItem), true);
  84. public bool IsVisible
  85. {
  86. get => (bool)GetValue(IsVisibleProperty);
  87. set => SetValue(IsVisibleProperty, value);
  88. }
  89. public static readonly BindableProperty AlertProperty = BindableProperty.Create(
  90. nameof(Alert),
  91. typeof(string),
  92. typeof(MobileModuleItem),
  93. null);
  94. public string Alert
  95. {
  96. get { return (string)GetValue(AlertProperty); }
  97. set {
  98. SetValue(AlertProperty, value);
  99. OnPropertyChanged(nameof(AlertVisible));
  100. }
  101. }
  102. public bool AlertVisible => !String.IsNullOrWhiteSpace(Alert);
  103. public event ModuleMenuItemTapped Tapped;
  104. public void Tap() => Tapped?.Invoke(this, new ModuleMenuItemTappedArgs());
  105. }
  106. }