Implementation of Booking Details Page and its View Model
This commit is contained in:
parent
54f6600e69
commit
ec7b76ef4b
@ -0,0 +1,326 @@
|
||||
using GMCabsDriverAssistant.Enums;
|
||||
using GMCabsDriverAssistant.Models;
|
||||
using GMCabsDriverAssistant.Services;
|
||||
using GMCabsDriverAssistantSolution.Models.Rydo;
|
||||
using GMCabsDriverAssistantSolution.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GMCabsDriverAssistantSolution.ViewModels
|
||||
{
|
||||
[QueryProperty(nameof(BookingJson), nameof(BookingJson))]
|
||||
public class BookingDetailViewModel : BaseViewModel
|
||||
{
|
||||
#region Constants
|
||||
private const int RYDO_METER_FARE_PROVIDER_CHARGE = 10;
|
||||
private const int RYDO_FIXED_PRICE_PROVIDER_CHARGE = 10;
|
||||
private const int RYDO_METER_FARE_PROVIDER_CHARGE_GM_DRIVER = 10;
|
||||
private const int RYDO_FIXED_PRICE_PROVIDER_CHARGE_GM_DRIVER = 5;
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
private string _bookingId;
|
||||
|
||||
private float distance;
|
||||
|
||||
private string formattedDistance;
|
||||
|
||||
private string startAddress;
|
||||
|
||||
private string startSuburb;
|
||||
|
||||
private string endAddress;
|
||||
|
||||
private string endSuburb;
|
||||
|
||||
private string rewardPoints;
|
||||
|
||||
private double bookingFee;
|
||||
|
||||
private bool isCorporateBooking;
|
||||
|
||||
private string fareTypeValue;
|
||||
|
||||
private int? fixedAmount;
|
||||
|
||||
private bool isFutureBooking;
|
||||
|
||||
private int pickUpTime;
|
||||
|
||||
private string formattedPickUpTime;
|
||||
private string formattedPickUpTimeDateOnly;
|
||||
private string formattedPickUpTimeTimeOnly;
|
||||
private string bookingJson;
|
||||
|
||||
private string startStreetName;
|
||||
private string endStreetName;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public string BookingId
|
||||
{
|
||||
get => _bookingId;
|
||||
set
|
||||
{
|
||||
_bookingId = value;
|
||||
// LoadBooking(Guid.Parse(value));
|
||||
}
|
||||
}
|
||||
|
||||
public float Distance
|
||||
{
|
||||
get => distance;
|
||||
set => SetProperty(ref distance, value);
|
||||
}
|
||||
|
||||
public string FormattedDistance
|
||||
{
|
||||
get => (distance >= 1000) ? $"{distance / 1000:0.##}k" : $"{(int)distance}m";
|
||||
set => SetProperty(ref formattedDistance, value);
|
||||
}
|
||||
|
||||
public string StartAddress
|
||||
{
|
||||
get => startAddress;
|
||||
set => SetProperty(ref startAddress, value);
|
||||
}
|
||||
|
||||
public string StartSuburb
|
||||
{
|
||||
get => startSuburb;
|
||||
set => SetProperty(ref startSuburb, value);
|
||||
}
|
||||
|
||||
public string EndAddress
|
||||
{
|
||||
get => endAddress;
|
||||
set => SetProperty(ref endAddress, value);
|
||||
}
|
||||
|
||||
public string EndSuburb
|
||||
{
|
||||
get => endSuburb;
|
||||
set => SetProperty(ref endSuburb, value);
|
||||
}
|
||||
|
||||
public string RewardPoints
|
||||
{
|
||||
get => rewardPoints;
|
||||
set => SetProperty(ref rewardPoints, value);
|
||||
}
|
||||
|
||||
public double BookingFee
|
||||
{
|
||||
get => bookingFee;
|
||||
set => SetProperty(ref bookingFee, value);
|
||||
}
|
||||
|
||||
public bool IsCorporateBooking
|
||||
{
|
||||
get => isCorporateBooking;
|
||||
set => SetProperty(ref isCorporateBooking, value);
|
||||
}
|
||||
|
||||
public string FareTypeValue
|
||||
{
|
||||
get => fareTypeValue;
|
||||
set => SetProperty(ref fareTypeValue, value);
|
||||
}
|
||||
|
||||
public int? FixedAmount
|
||||
{
|
||||
get => fixedAmount;
|
||||
set => SetProperty(ref fixedAmount, value);
|
||||
}
|
||||
public bool IsFutureBooking
|
||||
{
|
||||
get => isFutureBooking;
|
||||
set => SetProperty(ref isFutureBooking, value);
|
||||
}
|
||||
|
||||
public int PickUpTime
|
||||
{
|
||||
get => pickUpTime;
|
||||
set => SetProperty(ref pickUpTime, value);
|
||||
}
|
||||
public string FormattedPickUpTime
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
dateTime = dateTime.AddSeconds(pickUpTime).ToLocalTime();
|
||||
return dateTime.ToString("dd/MM/yyyy hh:mm tt");
|
||||
}
|
||||
set => SetProperty(ref formattedPickUpTime, value);
|
||||
}
|
||||
|
||||
public Command OnAcceptBookingClicked { get; }
|
||||
|
||||
public Command OnDeclineBookingClicked { get; }
|
||||
|
||||
public string BookingJson
|
||||
{
|
||||
get => bookingJson;
|
||||
set
|
||||
{
|
||||
bookingJson = value;
|
||||
LoadBooking(value);
|
||||
}
|
||||
}
|
||||
|
||||
public string StartStreetName
|
||||
{
|
||||
get => startStreetName;
|
||||
set => SetProperty(ref startStreetName, value);
|
||||
}
|
||||
|
||||
public string EndStreetName
|
||||
{
|
||||
get => endStreetName;
|
||||
set => SetProperty(ref endStreetName, value);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public BookingDetailViewModel()
|
||||
{
|
||||
Title = "Booking Details";
|
||||
OnAcceptBookingClicked = new Command(async () => { await AcceptBooking(); });
|
||||
OnDeclineBookingClicked = new Command(async () => { await DeclineBooking(Id.ToString()); });
|
||||
}
|
||||
public BookingDetailViewModel(Guid bookingId)
|
||||
{
|
||||
BookingId = bookingId.ToString();
|
||||
Title = "Booking Details";
|
||||
OnAcceptBookingClicked = new Command(async () => { await AcceptBooking(); });
|
||||
OnDeclineBookingClicked = new Command(async () => { await DeclineBooking(Id.ToString()); });
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Method
|
||||
private async void LoadBooking(string bookingJson)
|
||||
{
|
||||
/* string rydoAccessToken = Preferences.Get(EftposLoginResponse.RYDO_ACCESS_TOKEN,"");
|
||||
GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
|
||||
var booking = await gmCabsDriverService.GetBookingDetails(rydoAccessToken, bookingId);*/
|
||||
BookingDto booking = JsonSerializer.Deserialize<BookingDto>(bookingJson);
|
||||
if (booking.BookingId == Guid.Empty)
|
||||
{
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
|
||||
Id = booking.BookingId;
|
||||
Distance = booking.Distance;
|
||||
FormattedDistance = booking.Distance.ToString();
|
||||
StartAddress = booking.StartAddress;
|
||||
StartSuburb = booking.StartSuburb;
|
||||
EndAddress = booking.EndAddress;
|
||||
EndSuburb = booking.EndSuburb;
|
||||
IsCorporateBooking = booking.IsCorporate;
|
||||
FixedAmount = booking.FixedAmount;
|
||||
IsFutureBooking = booking.FutureBooking;
|
||||
PickUpTime = booking.PickupTime;
|
||||
FormattedPickUpTime = booking.PickupTime.ToString();
|
||||
BookingFee = 0;
|
||||
|
||||
if (FixedAmount != null)
|
||||
{
|
||||
decimal amount = (decimal)(FixedAmount / 100.0);
|
||||
FareTypeValue = "$" + amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
FareTypeValue = "METER";
|
||||
}
|
||||
RewardPoints = booking.RydoStars > 0 ? string.Format($"+{booking.RydoStars}") : booking.RydoStars.ToString();
|
||||
var preferredDriver = booking.PriorityDriver;
|
||||
if (preferredDriver)
|
||||
{
|
||||
if (booking.FareType == FareType.Fixed)
|
||||
{
|
||||
if (booking.FixedAmount > booking.MinFareAmount)
|
||||
{
|
||||
BookingFee = booking.ProviderChargeFixedFarePreferred.Value;
|
||||
}
|
||||
}
|
||||
else if (booking.FareType == FareType.Meter)
|
||||
{
|
||||
BookingFee = booking.ProviderChargeMeterFarePreferred.Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (booking.FareType == FareType.Fixed)
|
||||
{
|
||||
if (booking.FixedAmount > booking.MinFareAmount)
|
||||
{
|
||||
BookingFee = booking.ProviderChargeFixedFare.Value;
|
||||
}
|
||||
}
|
||||
else if (booking.FareType == FareType.Meter)
|
||||
{
|
||||
BookingFee = booking.ProviderChargeMeterFare.Value;
|
||||
}
|
||||
}
|
||||
|
||||
string[] splitStartAddresses = StartAddress.Split(' ');
|
||||
bool isStartAddressNumberOccurance = splitStartAddresses[0].Any(letter => char.IsDigit(letter));
|
||||
|
||||
string[] splitEndAddresses = EndAddress.Split(' ');
|
||||
bool isEndAddressNumberOccurance = splitEndAddresses[0].Any(letter => char.IsDigit(letter));
|
||||
|
||||
if (isEndAddressNumberOccurance)
|
||||
{
|
||||
StartStreetName = StartAddress.Substring(StartAddress.IndexOf(' ') + 1);
|
||||
StartStreetName = StartStreetName + $", {StartSuburb}";
|
||||
}
|
||||
else
|
||||
{
|
||||
StartStreetName = StartSuburb;
|
||||
}
|
||||
|
||||
if (isEndAddressNumberOccurance)
|
||||
{
|
||||
EndStreetName = EndAddress.Substring(EndAddress.IndexOf(' ') + 1);
|
||||
EndStreetName = EndStreetName + $", {EndSuburb}";
|
||||
}
|
||||
else
|
||||
{
|
||||
EndStreetName = EndSuburb;
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
private async Task AcceptBooking()
|
||||
{
|
||||
await Shell.Current.GoToAsync($"{nameof(AcceptBookingPage)}?{nameof(AcceptBookingViewModel.BookingId)}={Id}&{nameof(AcceptBookingViewModel.PickUpAddress)}={StartAddress}&{nameof(AcceptBookingViewModel.DropUpAddress)}={EndAddress}&{nameof(AcceptBookingViewModel.IsFutureBooking)}={IsFutureBooking}");
|
||||
}
|
||||
|
||||
private async Task DeclineBooking(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();
|
||||
acceptBookingRequest.DriverId = driverId;
|
||||
|
||||
var res = await gmCabsDriverService.DeclineBooking(acceptBookingRequest, rydoAccessToken, booking_Id);
|
||||
if (res.StatusCode == 200)
|
||||
{
|
||||
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
165
GMCabsDriverAssistantSolution/Views/BookingDetailsPage.xaml
Normal file
165
GMCabsDriverAssistantSolution/Views/BookingDetailsPage.xaml
Normal file
@ -0,0 +1,165 @@
|
||||
<?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.BookingDetailsPage"
|
||||
xmlns:vm="clr-namespace:GMCabsDriverAssistantSolution.ViewModels" x:DataType="vm:BookingDetailViewModel"
|
||||
xmlns:models="clr-namespace:GMCabsDriverAssistant.Models"
|
||||
Title="{Binding Title}">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style x:Key="InnerFrameLabel" TargetType="Label">
|
||||
<Setter Property="HorizontalTextAlignment" Value="Center"/>
|
||||
<Setter Property="FontAttributes" Value="Bold"/>
|
||||
<Setter Property="TextColor" Value="Black"/>
|
||||
<Setter Property="FontSize" Value="25"/>
|
||||
</Style>
|
||||
<Style x:Key="OuterFrameLabel" TargetType="Label">
|
||||
<Setter Property="HorizontalTextAlignment" Value="Center"/>
|
||||
<Setter Property="FontAttributes" Value="Bold"/>
|
||||
<Setter Property="TextColor" Value="Black"/>
|
||||
<Setter Property="FontSize" Value="25"/>
|
||||
</Style>
|
||||
<Style x:Key="BelowFrameStyle" TargetType="Frame">
|
||||
<Setter Property="BackgroundColor" Value="#C4C4C4"/>
|
||||
<Setter Property="WidthRequest" Value="70"/>
|
||||
</Style>
|
||||
<Color x:Key="Accent">#96d1ff</Color>
|
||||
</ResourceDictionary>
|
||||
</ContentPage.Resources>
|
||||
<ContentPage.Content>
|
||||
<StackLayout Orientation="Vertical"
|
||||
Padding="20,5,20,5"
|
||||
BackgroundColor="#DCDCDC">
|
||||
<Label
|
||||
TextColor="Black"
|
||||
HorizontalTextAlignment="Center"
|
||||
FontSize="25">
|
||||
<Label.Triggers>
|
||||
<DataTrigger TargetType="Label" Binding="{Binding IsFutureBooking}" Value="True">
|
||||
<Setter Property="Text" Value=""/>
|
||||
</DataTrigger>
|
||||
<DataTrigger TargetType="Label" Binding="{Binding IsFutureBooking}" Value="False">
|
||||
<Setter Property="Text" Value="{Binding FormattedDistance}" />
|
||||
</DataTrigger>
|
||||
</Label.Triggers>
|
||||
</Label>
|
||||
<StackLayout Orientation="Horizontal">
|
||||
<Image Source="green_pin.png"
|
||||
HeightRequest="40"/>
|
||||
<Label TextColor="Black"
|
||||
HorizontalTextAlignment="Start"
|
||||
FontSize="20"
|
||||
Margin="10,10,0,0"
|
||||
Text="{Binding StartStreetName}">
|
||||
</Label>
|
||||
</StackLayout>
|
||||
<StackLayout Orientation="Horizontal">
|
||||
<Image Source="red_pin.png"
|
||||
HeightRequest="40"/>
|
||||
<Label TextColor="Black"
|
||||
HorizontalTextAlignment="Start"
|
||||
FontSize="20"
|
||||
Margin="10,10,0,0"
|
||||
Text="{Binding EndStreetName}">
|
||||
</Label>
|
||||
</StackLayout>
|
||||
<Frame CornerRadius="25"
|
||||
Padding="0"
|
||||
Margin="0,15,0,0"
|
||||
BackgroundColor="#BCA70F0F">
|
||||
<StackLayout>
|
||||
<Frame BackgroundColor="#C4C4C4"
|
||||
HeightRequest="28"
|
||||
Padding="0,5,0,5"
|
||||
CornerRadius="25">
|
||||
<StackLayout Orientation="Horizontal"
|
||||
HorizontalOptions="CenterAndExpand">
|
||||
<Image Source="clock.png"
|
||||
Margin="0,0,10,0"/>
|
||||
<Label
|
||||
TextColor="Black"
|
||||
FontAttributes="Bold"
|
||||
VerticalTextAlignment="Center"
|
||||
HorizontalTextAlignment="Center"
|
||||
FontSize="20">
|
||||
<Label.Triggers>
|
||||
<DataTrigger TargetType="Label" Binding="{Binding IsFutureBooking}" Value="True">
|
||||
<Setter Property="Text" Value="{Binding FormattedPickUpTime}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger TargetType="Label" Binding="{Binding IsFutureBooking}" Value="False">
|
||||
<Setter Property="Text" Value="READY NOW" />
|
||||
</DataTrigger>
|
||||
</Label.Triggers>
|
||||
</Label>
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
<Frame x:Name="corporateVIPFrame" BackgroundColor="Transparent"
|
||||
Padding="5">
|
||||
<Label Text="Corporate VIP Booking"
|
||||
TextColor="White"
|
||||
FontAttributes="Bold"
|
||||
VerticalTextAlignment="Start"
|
||||
HorizontalTextAlignment="Center"
|
||||
FontSize="20"/>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
<StackLayout Orientation="Horizontal"
|
||||
Margin="0,5,0,0">
|
||||
<StackLayout HorizontalOptions="StartAndExpand">
|
||||
<Label Text="PAYMENT"
|
||||
HorizontalTextAlignment="Center"
|
||||
TextColor="Black"
|
||||
FontSize="15"/>
|
||||
<Frame Padding="4,12"
|
||||
WidthRequest="100"
|
||||
CornerRadius="24"
|
||||
Style="{StaticResource BelowFrameStyle}">
|
||||
<Label Text="{Binding FareTypeValue}"
|
||||
FontSize="20"
|
||||
Style="{StaticResource InnerFrameLabel}"/>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
<StackLayout HorizontalOptions="CenterAndExpand">
|
||||
<Label Text="POINTS"
|
||||
HorizontalTextAlignment="Center"
|
||||
TextColor="Black"
|
||||
FontSize="15"/>
|
||||
<Frame Style="{StaticResource BelowFrameStyle}"
|
||||
Padding="4,12"
|
||||
CornerRadius="24">
|
||||
<Label Text="{Binding RewardPoints}" FontSize="20"
|
||||
Style="{StaticResource InnerFrameLabel}"/>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
<StackLayout HorizontalOptions="EndAndExpand">
|
||||
<Label Text="FEE"
|
||||
HorizontalTextAlignment="Center"
|
||||
TextColor="Black"
|
||||
FontSize="15"/>
|
||||
<Frame Style="{StaticResource BelowFrameStyle}"
|
||||
Padding="4,12"
|
||||
CornerRadius="24">
|
||||
<Label Text="{Binding BookingFee, StringFormat='{0}%'}" FontSize="20"
|
||||
TextColor="#B44444"
|
||||
Style="{StaticResource InnerFrameLabel}"/>
|
||||
</Frame>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
<StackLayout VerticalOptions="EndAndExpand"
|
||||
Margin="0,5,0,0">
|
||||
<Button
|
||||
Margin="20,0,20,0"
|
||||
Text="Accept Booking"
|
||||
FontSize="20"
|
||||
Command="{Binding OnAcceptBookingClicked}"/>
|
||||
<Button
|
||||
Margin="20,0,20,15"
|
||||
Text="Decline Booking"
|
||||
FontSize="20"
|
||||
TextTransform="Uppercase"
|
||||
Command="{Binding OnDeclineBookingClicked}"/>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
@ -0,0 +1,40 @@
|
||||
using GMCabsDriverAssistantSolution.ViewModels;
|
||||
|
||||
namespace GMCabsDriverAssistantSolution.Views;
|
||||
|
||||
public partial class BookingDetailsPage : ContentPage
|
||||
{
|
||||
|
||||
#region Fields
|
||||
private readonly BookingDetailViewModel _viewModel;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public BookingDetailsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = _viewModel = new BookingDetailViewModel();
|
||||
}
|
||||
public BookingDetailsPage(Guid bookingid)
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = _viewModel = new BookingDetailViewModel(bookingid);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
corporateVIPFrame.IsVisible = _viewModel.IsCorporateBooking;
|
||||
}
|
||||
private async void AcceptBooking(object sender, EventArgs e)
|
||||
{
|
||||
// TODO
|
||||
await Navigation.PushAsync(new AcceptBookingProcessPage(), true);
|
||||
}
|
||||
#endregion
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user