From 8d3ffa99b2e8f1cc94e5726f14a40dc1e595c991 Mon Sep 17 00:00:00 2001 From: Kaustav Chaudhuri Date: Mon, 8 May 2023 11:00:36 +0530 Subject: [PATCH] Implementation of Notifications page and its View Model --- .../ViewModels/NotificationsViewModel.cs | 85 +++++++++++++++++++ .../Views/NotificationsPage.xaml | 80 +++++++++++++++++ .../Views/NotificationsPage.xaml.cs | 20 +++++ 3 files changed, 185 insertions(+) create mode 100644 GMCabsDriverAssistantSolution/ViewModels/NotificationsViewModel.cs create mode 100644 GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml create mode 100644 GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml.cs diff --git a/GMCabsDriverAssistantSolution/ViewModels/NotificationsViewModel.cs b/GMCabsDriverAssistantSolution/ViewModels/NotificationsViewModel.cs new file mode 100644 index 0000000..4e9a117 --- /dev/null +++ b/GMCabsDriverAssistantSolution/ViewModels/NotificationsViewModel.cs @@ -0,0 +1,85 @@ +using GMCabsDriverAssistant.Models; +using GMCabsDriverAssistant.Services; +using GMCabsDriverAssistant.Utils; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GMCabsDriverAssistantSolution.ViewModels +{ + class NotificationsViewModel : BaseViewModel + { + #region Fields + private GMCabsDriverService gmCabsDriverService; + private NotificationDto _selectedNotification; + #endregion + + #region Properties + public ObservableCollection Notifications { get; set; } + public Command MarkNotificationAsViewedCommand { get; } + + public NotificationDto SelectedNotification + { + get => _selectedNotification; + set => SetProperty(ref _selectedNotification, value); + } + #endregion + + #region Constructor + public NotificationsViewModel() + { + Title = "Notifications"; + Notifications = new ObservableCollection(); + MarkNotificationAsViewedCommand = new Command(OnMarkNotificationAsViewedClicked); + GetNotifications(); + } + #endregion + + #region Methods + private async void GetNotifications() + { + string appToken = Preferences.Get(SecureStorageData.Token, ""); + gmCabsDriverService = new GMCabsDriverService(); + Notifications.Clear(); + List notifications = await gmCabsDriverService.GetNotifications(appToken); + if (notifications.Count > 0) + { + foreach (NotificationDto notification in notifications) + { + Notifications.Add(notification); + } + SelectedNotification = Notifications[0]; + } + else + { + await Shell.Current.GoToAsync(".."); + } + } + + private async void OnMarkNotificationAsViewedClicked(object obj) + { + string appToken = Preferences.Get(SecureStorageData.Token, ""); + gmCabsDriverService = new GMCabsDriverService(); + + bool isSuccess = await gmCabsDriverService.MarkNotificationAsViewed(appToken, SelectedNotification.Id); + if (isSuccess) + { + Notifications.Remove(SelectedNotification); + if (Notifications.Count > 0) + { + SelectedNotification = Notifications[0]; + } + else + { + await Shell.Current.GoToAsync(".."); + } + } + } + #endregion + + + } +} diff --git a/GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml b/GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml new file mode 100644 index 0000000..9588973 --- /dev/null +++ b/GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml @@ -0,0 +1,80 @@ + + + + + + + + #96d1ff + + + + + + + + + + + + + + + + +