Browse Source

Implementation of Notifications page and its View Model

master
Kaustav Chaudhuri 1 year ago
parent
commit
8d3ffa99b2
3 changed files with 185 additions and 0 deletions
  1. +85
    -0
      GMCabsDriverAssistantSolution/ViewModels/NotificationsViewModel.cs
  2. +80
    -0
      GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml
  3. +20
    -0
      GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml.cs

+ 85
- 0
GMCabsDriverAssistantSolution/ViewModels/NotificationsViewModel.cs View File

@ -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<NotificationDto> 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<NotificationDto>();
MarkNotificationAsViewedCommand = new Command(OnMarkNotificationAsViewedClicked);
GetNotifications();
}
#endregion
#region Methods
private async void GetNotifications()
{
string appToken = Preferences.Get(SecureStorageData.Token, "");
gmCabsDriverService = new GMCabsDriverService();
Notifications.Clear();
List<NotificationDto> 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
}
}

+ 80
- 0
GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GMCabsDriverAssistantSolution.Views.NotificationsPage"
xmlns:vm="clr-namespace:GMCabsDriverAssistantSolution.ViewModels"
Title="{Binding Title}">
<ContentPage.BindingContext>
<vm:NotificationsViewModel />
</ContentPage.BindingContext>
<ContentPage.Resources>
<ResourceDictionary>
<Color x:Key="Accent">#96d1ff</Color>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Orientation="Vertical"
BackgroundColor="#DCDCDC">
<Frame Margin="16"
CornerRadius="8"
VerticalOptions="FillAndExpand"
Padding="8">
<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal"
HorizontalOptions="StartAndExpand"
Margin="8">
<StackLayout Orientation="Vertical" >
<Image Source="message.png" HeightRequest="50"/>
<Image Source="ImportantIconSmall.png"
HeightRequest="40"
VerticalOptions="CenterAndExpand"/>
</StackLayout>
<StackLayout Orientation="Vertical"
HorizontalOptions="FillAndExpand">
<Label Text="{Binding SelectedNotification.Subject}"
TextColor="Black"
FontSize="28"/>
<Grid HorizontalOptions="StartAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label Text="FROM"
FontSize="15"
Grid.Row="0"
Grid.Column="0"/>
<Label Text="{Binding SelectedNotification.FromName}"
TextColor="Black"
FontSize="16"
Grid.Row="0"
Grid.Column="1"/>
<Label Text="SENT"
FontSize="15"
Grid.Row="1"
Grid.Column="0"/>
<Label Text="{Binding SelectedNotification.SentDate, StringFormat='{0:dd/MM/yyyy hh:mm tt}'}"
FontSize="15"
Grid.Row="1"
Grid.Column="1"/>
</Grid>
</StackLayout>
</StackLayout>
<ScrollView VerticalOptions="StartAndExpand" Padding="16, 0">
<Label Text="{Binding SelectedNotification.Body}"
FontSize="20"
TextColor="Black" />
</ScrollView>
<Button Margin="8,0,8,0"
FontSize="20"
Text="Ok"
Command="{Binding MarkNotificationAsViewedCommand}"/>
</StackLayout>
</Frame>
</StackLayout>
</ContentPage.Content>
</ContentPage>

+ 20
- 0
GMCabsDriverAssistantSolution/Views/NotificationsPage.xaml.cs View File

@ -0,0 +1,20 @@
namespace GMCabsDriverAssistantSolution.Views;
public partial class NotificationsPage : ContentPage
{
#region Fields
#endregion
#region Properties
#endregion
#region Constructor
public NotificationsPage()
{
InitializeComponent();
}
#endregion
#region Methods
#endregion
}

Loading…
Cancel
Save