Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions TransactionMobile.Maui/Extensions/MauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public static MauiAppBuilder ConfigureAppServices(this MauiAppBuilder builder)
return builder;
}

//public static MauiAppBuilder ConfigureUIServices(this MauiAppBuilder builder)
//{
public static MauiAppBuilder ConfigureUIServices(this MauiAppBuilder builder)
{
// builder.Services.AddSingleton<IDialogService, DialogService>();

// return builder;
//}
builder.Services.AddSingleton<INavigationService, ShellNavigationService>();
return builder;
}

public static MauiAppBuilder ConfigureRequestHandlers(this MauiAppBuilder builder)
{
Expand Down
2 changes: 1 addition & 1 deletion TransactionMobile.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static MauiApp CreateMauiApp()
.ConfigureRequestHandlers()
.ConfigureViewModels()
.ConfigureAppServices()
//.ConfigureUIServices()
.ConfigureUIServices()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
Expand Down
21 changes: 21 additions & 0 deletions TransactionMobile.Maui/UIServices/INavigationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace TransactionMobile.Maui.UIServices;

public interface INavigationService
{
Task GoToHome();

Task GoToMobileTopupSuccessPage();

Task GoToMobileTopupFailedPage();

Task GoToMobileTopupSelectProductPage(String operatorIdentifier);

Task GoToMobileTopupSelectOperatorPage();

Task GoToMobileTopupPerformTopupPage(String operatorIdentifier,
Guid contractId,
Guid productId,
Decimal topupAmount);

Task PopToRoot();
}
47 changes: 47 additions & 0 deletions TransactionMobile.Maui/UIServices/ShellNavigationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace TransactionMobile.Maui.UIServices;

public class ShellNavigationService : INavigationService
{
#region Methods

public async Task GoToHome()
{
await Shell.Current.GoToAsync("//home");
}

public async Task GoToMobileTopupFailedPage()
{
await Shell.Current.GoToAsync($"{nameof(MobileTopupFailedPage)}");
}

public async Task GoToMobileTopupPerformTopupPage(String operatorIdentifier,
Guid contractId,
Guid productId,
Decimal topupAmount)
{
await
Shell.Current.GoToAsync($"{nameof(MobileTopupPerformTopupPage)}?OperatorIdentifier={operatorIdentifier}&ContractId={contractId}&ProductId={productId}&TopupAmount={topupAmount}");
}

public async Task GoToMobileTopupSelectOperatorPage()
{
await Shell.Current.GoToAsync(nameof(MobileTopupSelectOperatorPage));
}

public async Task GoToMobileTopupSelectProductPage(String operatorIdentifier)
{
await Shell.Current.GoToAsync($"{nameof(MobileTopupSelectProductPage)}?OperatorIdentifier={operatorIdentifier}");
}

public async Task GoToMobileTopupSuccessPage()
{
await Shell.Current.GoToAsync($"{nameof(MobileTopupSuccessPage)}");
}

public async Task PopToRoot()
{
await Shell.Current.Navigation.PopToRootAsync();
}

#endregion
}
8 changes: 6 additions & 2 deletions TransactionMobile.Maui/ViewModels/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
using MediatR;
using MvvmHelpers;
using MvvmHelpers.Commands;
using UIServices;

public class LoginPageViewModel : BaseViewModel
{
private readonly INavigationService NavigationService;

#region Constructors

//public String Username { get; set; }
//public String Password { get; set; }
public LoginPageViewModel(IMediator mediator)
public LoginPageViewModel(IMediator mediator, INavigationService navigationService)
{
this.NavigationService = navigationService;
this.LoginCommand = new AsyncCommand(this.LoginCommandExecute);
this.Mediator = mediator;
}
Expand Down Expand Up @@ -63,7 +67,7 @@ private async Task LoginCommandExecute()
var merchantBalance = await this.Mediator.Send(getMerchantBalanceRequest);

// TODO: Cache the token as will be needed later
await Shell.Current.GoToAsync("//home");
await this.NavigationService.GoToHome();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
using System.Windows.Input;
using MvvmHelpers;
using MvvmHelpers.Commands;
using UIServices;

public class MobileTopupFailedPageViewModel : BaseViewModel
{
private readonly INavigationService NavigationService;

#region Constructors

public MobileTopupFailedPageViewModel()
public MobileTopupFailedPageViewModel(INavigationService navigationService)
{
this.NavigationService = navigationService;
this.CancelledCommand = new AsyncCommand(this.CancelledCommandExecute);
}

Expand All @@ -25,7 +29,7 @@ public MobileTopupFailedPageViewModel()

private async Task CancelledCommandExecute()
{
await Shell.Current.Navigation.PopToRootAsync();
await this.NavigationService.PopToRoot();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MediatR;
using MvvmHelpers;
using MvvmHelpers.Commands;
using UIServices;

[QueryProperty(nameof(MobileTopupPerformTopupPageViewModel.ContractId), nameof(MobileTopupPerformTopupPageViewModel.ContractId))]
[QueryProperty(nameof(MobileTopupPerformTopupPageViewModel.ProductId), nameof(MobileTopupPerformTopupPageViewModel.ProductId))]
Expand All @@ -20,15 +21,18 @@ public class MobileTopupPerformTopupPageViewModel : BaseViewModel

private readonly IMediator Mediator;

private readonly INavigationService NavigationService;

private Decimal topupAmount;

#endregion

#region Constructors

public MobileTopupPerformTopupPageViewModel(IMediator mediator)
public MobileTopupPerformTopupPageViewModel(IMediator mediator, INavigationService navigationService)
{
this.Mediator = mediator;
this.NavigationService = navigationService;
this.PerformTopupCommand = new AsyncCommand(this.PerformTopupCommandExecute);
this.CustomerMobileNumberEntryCompletedCommand = new Command(this.CustomerMobileNumberEntryCompletedCommandExecute);
this.TopupAmountEntryCompletedCommand = new Command(this.TopupAmountEntryCompletedCommandExecute);
Expand Down Expand Up @@ -110,11 +114,12 @@ private async Task PerformTopupCommandExecute()

if (response)
{
await Shell.Current.GoToAsync($"{nameof(MobileTopupSuccessPage)}");
await this.NavigationService.GoToMobileTopupSuccessPage();

}
else
{
await Shell.Current.GoToAsync($"{nameof(MobileTopupFailedPage)}");
await this.NavigationService.GoToMobileTopupFailedPage();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@
using MediatR;
using MvvmHelpers;
using MvvmHelpers.Commands;
using UIServices;

public class MobileTopupSelectOperatorPageViewModel : BaseViewModel
{
#region Fields

private readonly IMediator Mediator;

private readonly INavigationService NavigationService;

#endregion

#region Constructors

public MobileTopupSelectOperatorPageViewModel(IMediator mediator)
public MobileTopupSelectOperatorPageViewModel(IMediator mediator, INavigationService navigationService)
{
this.Mediator = mediator;
this.NavigationService = navigationService;
this.OperatorSelectedCommand = new AsyncCommand<SelectedItemChangedEventArgs>(this.OperatorSelectedCommandExecute);
this.Title = "Select an Operator";
}
Expand Down Expand Up @@ -61,7 +65,8 @@ public async Task Initialise(CancellationToken cancellationToken)
private async Task OperatorSelectedCommandExecute(SelectedItemChangedEventArgs e)
{
ContractOperatorModel operatorModel = e.SelectedItem as ContractOperatorModel;
await Shell.Current.GoToAsync($"{nameof(MobileTopupSelectProductPage)}?OperatorIdentifier={operatorModel.OperatorIdentfier}");
await this.NavigationService.GoToMobileTopupSelectProductPage(operatorModel.OperatorIdentfier);

}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MediatR;
using MvvmHelpers;
using MvvmHelpers.Commands;
using UIServices;

[QueryProperty(nameof(MobileTopupSelectProductPageViewModel.OperatorIdentifier), nameof(MobileTopupSelectProductPageViewModel.OperatorIdentifier))]
public class MobileTopupSelectProductPageViewModel : BaseViewModel
Expand All @@ -14,13 +15,16 @@ public class MobileTopupSelectProductPageViewModel : BaseViewModel

private readonly IMediator Mediator;

private readonly INavigationService NavigationService;

#endregion

#region Constructors

public MobileTopupSelectProductPageViewModel(IMediator mediator)
public MobileTopupSelectProductPageViewModel(IMediator mediator, INavigationService navigationService)
{
this.Mediator = mediator;
this.NavigationService = navigationService;
this.ProductSelectedCommand = new AsyncCommand<SelectedItemChangedEventArgs>(this.ProductSelectedCommandExecute);
this.Title = "Select a Product";
}
Expand Down Expand Up @@ -53,8 +57,7 @@ public async Task Initialise(CancellationToken cancellationToken)
private async Task ProductSelectedCommandExecute(SelectedItemChangedEventArgs e)
{
ContractProductModel productModel = e.SelectedItem as ContractProductModel;
await
Shell.Current.GoToAsync($"{nameof(MobileTopupPerformTopupPage)}?OperatorIdentifier={productModel.OperatorIdentfier}&ContractId={productModel.ContractId}&ProductId={productModel.ProductId}&TopupAmount={productModel.Value}");
await this.NavigationService.GoToMobileTopupPerformTopupPage(productModel.OperatorIdentfier, productModel.ContractId, productModel.ProductId, productModel.Value);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
using System.Windows.Input;
using MvvmHelpers;
using MvvmHelpers.Commands;
using UIServices;

public class MobileTopupSuccessPageViewModel : BaseViewModel
{
private readonly INavigationService NavigationService;

#region Constructors

public MobileTopupSuccessPageViewModel()
public MobileTopupSuccessPageViewModel(INavigationService navigationService)
{
this.NavigationService = navigationService;
this.CompletedCommand = new AsyncCommand(this.CompletedCommandExecute);
this.Title = "Mobile Topup Successful";
}
Expand All @@ -26,7 +30,7 @@ public MobileTopupSuccessPageViewModel()

private async Task CompletedCommandExecute()
{
await Shell.Current.Navigation.PopToRootAsync();
await this.NavigationService.PopToRoot();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
using System.Windows.Input;
using MvvmHelpers;
using MvvmHelpers.Commands;
using UIServices;

public class TransactionsPageViewModel : BaseViewModel
{
private readonly INavigationService NavigationService;

#region Constructors

public TransactionsPageViewModel()
public TransactionsPageViewModel(INavigationService navigationService)
{
this.NavigationService = navigationService;
this.MobileTopupCommand = new AsyncCommand(this.MobileTopupCommandExecute);
this.MobileWalletCommand = new AsyncCommand(this.MobileWalletCommandExecute);
this.BillPaymentCommand = new AsyncCommand(this.BillPaymentCommandExecute);
Expand Down Expand Up @@ -46,7 +50,7 @@ private async Task BillPaymentCommandExecute()

private async Task MobileTopupCommandExecute()
{
await Shell.Current.GoToAsync(nameof(MobileTopupSelectOperatorPage));
await this.NavigationService.GoToMobileTopupSelectOperatorPage();
}

private async Task MobileWalletCommandExecute()
Expand Down