MainPageUtils.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Xamarin.Forms;
  7. using InABox.Core;
  8. using InABox.Clients;
  9. using InABox.Mobile;
  10. using Comal.Classes;
  11. using comal.timesheets.CustomControls;
  12. using PRSSecurity = InABox.Core.Security;
  13. using Plugin.LocalNotification;
  14. namespace comal.timesheets
  15. {
  16. public delegate void MainPageNotificationsChanged();
  17. public delegate void RefreshScreen();
  18. public delegate void RequestUserInputForTask(Guid taskID);
  19. public delegate void TaskTitleChanged(string title);
  20. public static class MainPageUtils
  21. {
  22. public static event MainPageNotificationsChanged OnMainPageNotificationsChanged;
  23. public static event RequestUserInputForTask OnRequestUserInput;
  24. public static event TaskTitleChanged OnTaskTitleChanged;
  25. #region Notifications
  26. // public static Page DetermineCorrectPage(Plugin.LocalNotification.EventArgs.NotificationActionEventArgs e)
  27. // {
  28. // string data = e.Request.ReturningData;
  29. // int index = data.IndexOf("$");
  30. // Guid ID = Guid.Parse(data.Remove(index));
  31. // string type = data.Substring(index + 1);
  32. // if (type == "Comal.Classes.Kanban")
  33. // return new AddEditTask(ID);
  34. // else if (type == "Comal.Classes.Delivery")
  35. // return new DeliveryDetails(ID);
  36. // else
  37. // return null;
  38. // }
  39. //
  40. // private static void CheckNotificationsPushed(CoreTable table)
  41. // {
  42. // try
  43. // {
  44. // if (!Application.Current.Properties.ContainsKey("LastPushedNotifications"))
  45. // {
  46. // Application.Current.Properties.Add("LastPushedNotifications", DateTime.Now);
  47. // }
  48. // DateTime lastPushed = DateTime.Parse(Application.Current.Properties["LastPushedNotifications"].ToString());
  49. // List<NotificationShell> toNotify = new List<NotificationShell>();
  50. // foreach (CoreRow row in table.Rows)
  51. // {
  52. // List<object> list = row.Values;
  53. // DateTime created = DateTime.Parse(list[3].ToString());
  54. // if (created > new DateTime(2022, 8, 22)) // prevent spam from buildup of old notifications before this is released
  55. // {
  56. // if (created > lastPushed)
  57. // {
  58. // if (list[1] == null) list[1] = "";
  59. // if (list[2] == null) list[2] = "";
  60. // if (list[3] == null) list[3] = DateTime.MinValue;
  61. // if (list[4] == null) list[4] = "";
  62. // if (list[5] == null) list[5] = "";
  63. // if (list[6] == null) list[6] = Guid.Empty;
  64. //
  65. // NotificationShell shell = new NotificationShell
  66. // {
  67. // ID = Guid.Parse(list[0].ToString()),
  68. // Sender = list[1].ToString(),
  69. // Title = list[2].ToString(),
  70. // Created = DateTime.Parse(list[3].ToString()),
  71. // EntityType = list[5].ToString(),
  72. // EntityID = Guid.Parse(list[6].ToString())
  73. // };
  74. // toNotify.Add(shell); //add notification to be pushed
  75. // }
  76. // }
  77. // }
  78. // if (toNotify.Count > 0)
  79. // PushNotificationsAsync(toNotify);
  80. // }
  81. // catch { }
  82. // }
  83. //
  84. // private static async Task PushNotificationsAsync(string title, )
  85. // {
  86. // try
  87. // {
  88. // int count = 1;
  89. //
  90. // foreach (NotificationShell shell in shells)
  91. // {
  92. // var notification = new NotificationRequest
  93. // {
  94. // BadgeNumber = 1,
  95. // Description = title,
  96. // Title = "New PRS Notification: ",
  97. // ReturningData = shell.EntityID.ToString() + "$" + shell.EntityType,
  98. // NotificationId = count,
  99. // };
  100. // count++;
  101. // NotificationImage img = new NotificationImage();
  102. // img.ResourceName = "icon16.png";
  103. // notification.Image = img;
  104. //
  105. // await LocalNotificationCenter.Current.Show(notification);
  106. // }
  107. // Application.Current.Properties["LastPushedNotifications"] = DateTime.Now;
  108. // }
  109. // catch { }
  110. // }
  111. #endregion
  112. }
  113. }