Browse Source

Implementation of Accept Booking Page and its View Model

master
Kaustav Chaudhuri 1 year ago
parent
commit
71c2de304f
3 changed files with 354 additions and 0 deletions
  1. +176
    -0
      GMCabsDriverAssistantSolution/ViewModels/AcceptBookingViewModel.cs
  2. +108
    -0
      GMCabsDriverAssistantSolution/Views/AcceptBookingPage.xaml
  3. +70
    -0
      GMCabsDriverAssistantSolution/Views/AcceptBookingPage.xaml.cs

+ 176
- 0
GMCabsDriverAssistantSolution/ViewModels/AcceptBookingViewModel.cs View File

@ -0,0 +1,176 @@
using GMCabsDriverAssistant.Models;
using GMCabsDriverAssistant.Services;
using GMCabsDriverAssistantSolution.Models.Rydo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace GMCabsDriverAssistantSolution.ViewModels
{
[QueryProperty(nameof(BookingId), nameof(BookingId))]
[QueryProperty(nameof(PickUpAddress), nameof(PickUpAddress))]
[QueryProperty(nameof(DropUpAddress), nameof(DropUpAddress))]
[QueryProperty(nameof(IsFutureBooking), nameof(IsFutureBooking))]
[Obsolete]
public class AcceptBookingViewModel : BaseViewModel
{
#region Constants
private const int ASSISTANT_DRIVER_SOURCE = 4;
#endregion Constants
#region Fields
public int seconds = 180;
private string timerSeconds = "3:00";
private string bookingId = "";
public string pickUpAddress = "";
public string dropUpAddress = "";
private string errorMessage = "";
private bool isProcessing = true;
private bool isBookingConfirmed = false;
public bool isBookingUnavailable = false;
public bool isFutureBooking = false;
private bool isBookingConfirmedAndOnDemand = false;
#endregion
#region Properties
public string TimerSeconds
{
get => timerSeconds;
set
{
SetProperty(ref timerSeconds, value);
}
}
public string ErrorMessage
{
get => errorMessage;
set
{
SetProperty(ref errorMessage, value);
}
}
[Obsolete]
public string BookingId
{
get => bookingId;
set
{
SetProperty(ref bookingId, value);
Processing(value);
}
}
public string PickUpAddress
{
get => pickUpAddress;
set
{
SetProperty(ref pickUpAddress, value);
}
}
public string DropUpAddress
{
get => dropUpAddress;
set
{
SetProperty(ref dropUpAddress, value);
}
}
public bool IsProcessing
{
get => isProcessing;
set => SetProperty(ref isProcessing, value);
}
public bool IsBookingConfirmed
{
get => isBookingConfirmed;
set => SetProperty(ref isBookingConfirmed, value);
}
public bool IsBookingUnavailable
{
get => isBookingUnavailable;
set => SetProperty(ref isBookingUnavailable, value);
}
public bool IsFutureBooking
{
get => isFutureBooking;
set => SetProperty(ref isFutureBooking, value);
}
public bool IsBookingConfirmedAndOnDemand
{
get => isBookingConfirmedAndOnDemand;
set => SetProperty(ref isBookingConfirmedAndOnDemand, value);
}
#endregion
#region Constructor
public AcceptBookingViewModel()
{
Title = "Processing";
}
#endregion
#region Methods
[Obsolete]
private async void Processing(string booking_Id)
{
string rydoAccessToken = Preferences.Get(EftposLoginResponse.RYDO_ACCESS_TOKEN, "");
Guid driverId = Guid.Parse(Preferences.Get(LoginResponseDto.USER_CODE, ""));
GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
AcceptDeclineBookingRequest acceptBookingRequest = new AcceptDeclineBookingRequest();
var location = await Geolocation.GetLastKnownLocationAsync();
acceptBookingRequest.DriverId = driverId;
acceptBookingRequest.DriverSource = ASSISTANT_DRIVER_SOURCE;
acceptBookingRequest.DriverLatitude = location.Latitude;
acceptBookingRequest.DriverLongitude = location.Longitude;
var res = await gmCabsDriverService.AcceptBooking(acceptBookingRequest, rydoAccessToken, booking_Id);
if (res.StatusCode == (int)HttpStatusCode.OK)
{
Title = "Booking Confirmed";
IsProcessing = false;
IsBookingConfirmed = true;
if (!IsFutureBooking)
{
IsBookingConfirmedAndOnDemand = true;
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
if (seconds > 0)
{
--seconds;
TimerSeconds = seconds / 60 + ":" + (seconds % 60 <= 9 ? "0" + seconds % 60 : "" + seconds % 60);
return true;
}
else
{
return false;
}
});
}
else
{
IsBookingConfirmedAndOnDemand = false;
}
}
else
{
Title = "Booking Unavailable";
ErrorMessage = res.Message;
IsProcessing = false;
IsBookingConfirmed = false;
IsBookingUnavailable = true;
}
}
#endregion
}
}

+ 108
- 0
GMCabsDriverAssistantSolution/Views/AcceptBookingPage.xaml View File

@ -0,0 +1,108 @@
<?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.AcceptBookingPage"
Title="{Binding Title}">
<ContentPage.Content>
<StackLayout BackgroundColor="#DCDCDC">
<StackLayout
IsVisible="{Binding IsProcessing}"
VerticalOptions="CenterAndExpand">
<Label Text="Processing"
TextColor="Black"
FontSize="25"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand" />
<Label Text="Please Wait"
TextColor="Black"
FontSize="24"
Margin="0,15,0,20"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand" />
<ActivityIndicator IsRunning="true" />
</StackLayout>
<StackLayout
VerticalOptions="Center"
IsVisible="{Binding IsBookingConfirmed}">
<Label
Text="Booking Awarded"
TextColor="Black"
FontSize="26"
Margin="0,40,0,0"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand" />
<Image
Source="righttic.png"
HeightRequest="100"/>
</StackLayout>
<StackLayout
VerticalOptions="Center"
IsVisible="{Binding IsBookingConfirmedAndOnDemand}">
<Label
Text="Head to"
TextColor="Black"
FontSize="20"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand" />
<Label
Text="Please confirm on terminal ASAP to keep this booking"
TextColor="Black"
Margin="40,0,40,0"
FontSize="26"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"/>
<Label
Text="{Binding TimerSeconds}"
TextColor="Black"
FontAttributes="Bold"
Margin="0,20,0,0"
FontSize="30"
HorizontalOptions="CenterAndExpand"/>
<Label
Text="Before Automatic Cancellation"
TextColor="Black"
FontSize="20"
Margin="0,20,0,0"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
<StackLayout VerticalOptions="EndAndExpand"
IsVisible="{Binding IsBookingConfirmed}">
<Button
Margin="40,0,40,15"
Text="OK"
Clicked="OnAcceptOkClicked"
FontSize="20"
/>
</StackLayout>
<StackLayout
IsVisible="{Binding IsBookingUnavailable}">
<Label
Text="{Binding ErrorMessage}"
TextColor="Black"
FontAttributes="Bold"
FontSize="24"
Margin="40,100,40,0"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand" />
<Label
Text="This booking is no longer available"
HorizontalTextAlignment="Center"
TextColor="Black"
Margin="40,60,40,0"
FontSize="25"/>
<Button
VerticalOptions="EndAndExpand"
Margin="40,140,40,0"
Text="OK"
FontSize="20"
Clicked="OnUnavailableOkClicked"/>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>

+ 70
- 0
GMCabsDriverAssistantSolution/Views/AcceptBookingPage.xaml.cs View File

@ -0,0 +1,70 @@
using GMCabsDriverAssistant.Models;
using GMCabsDriverAssistantSolution.ViewModels;
namespace GMCabsDriverAssistantSolution.Views;
public partial class AcceptBookingPage : ContentPage
{
#region Fields
[Obsolete]
private readonly AcceptBookingViewModel _viewModel;
#endregion
[Obsolete]
public AcceptBookingPage()
{
BindingContext = _viewModel = new AcceptBookingViewModel();
InitializeComponent();
}
[Obsolete]
protected override bool OnBackButtonPressed()
{
NavigateToHomePage(false);
base.OnBackButtonPressed();
return true;
}
[Obsolete]
protected override void OnDisappearing()
{
NavigateToHomePage(false);
base.OnDisappearing();
}
[Obsolete]
private void OnAcceptOkClicked(object sender, EventArgs e)
{
NavigateToHomePage(true);
}
[Obsolete]
private async void NavigateToHomePage(bool isOkPressed)
{
AcceptBookingTimerDto acceptBookingTimerDto = new AcceptBookingTimerDto();
if (!_viewModel.isFutureBooking)
{
acceptBookingTimerDto.PendingSeconds = _viewModel.seconds;
acceptBookingTimerDto.PickUPAddress = _viewModel.pickUpAddress;
acceptBookingTimerDto.DropUpAddress = _viewModel.dropUpAddress;
}
else
{
acceptBookingTimerDto.PendingSeconds = 0;
acceptBookingTimerDto.PickUPAddress = string.Empty;
acceptBookingTimerDto.DropUpAddress = string.Empty;
}
if (!_viewModel.isBookingUnavailable && !isOkPressed)
{
MessagingCenter.Send(this, nameof(AcceptBookingPage), acceptBookingTimerDto);
}
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
private async void OnUnavailableOkClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new BookingsPage(null, null));
}
}

Loading…
Cancel
Save