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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0" />
<PackageReference Include="Microsoft.AppCenter" Version="4.1.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
44 changes: 44 additions & 0 deletions TransactionMobile.Maui.BusinessLogic/UIServices/IDialogService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace TransactionMobile.Maui.BusinessLogic.UIServices;

public interface IDialogService
{
#region Methods

Task ShowDialog(String title,
String message,
String acceptString);

Task<Boolean> ShowDialog(String title,
String message,
String acceptString,
String cancelString);

Task ShowErrorToast(String message,
Action? action,
String? actionButtonText,
TimeSpan? duration,
CancellationToken cancellationToken);

Task ShowInformationToast(String message,
Action? action,
String? actionButtonText,
TimeSpan? duration,
CancellationToken cancellationToken);

Task<String> ShowPrompt(String title,
String message,
String acceptString,
String cancelString,
String placeHolder = "",
Int32 maxLength = -1,
Keyboard keyboard = null,
String initialValue = "");

Task ShowWarningToast(String message,
Action? action,
String? actionButtonText,
TimeSpan? duration,
CancellationToken cancellationToken);

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
namespace TransactionMobile.Maui.BusinessLogic.ViewModels;

using Microsoft.AppCenter;
using Microsoft.AppCenter.Distribute;
using Models;
using MvvmHelpers;
using Services;
using UIServices;

public class HomePageViewModel : BaseViewModel
{
#region Fields

private readonly IDialogService DialogService;

private readonly IMemoryCacheService MemoryCacheService;

#endregion

#region Constructors

public HomePageViewModel(IMemoryCacheService memoryCacheService,
IDialogService dialogService) {
this.MemoryCacheService = memoryCacheService;
this.DialogService = dialogService;
}

#endregion

#region Methods

public async Task Initialise(CancellationToken cancellationToken) {
this.MemoryCacheService.TryGetValue("Configuration", out Configuration configuration);

if (configuration.EnableAutoUpdates) {
await Distribute.SetEnabledAsync(true);
Distribute.CheckForUpdate();
Distribute.ReleaseAvailable = this.OnReleaseAvailable;
Distribute.UpdateTrack = UpdateTrack.Public;
}
else {
Distribute.DisableAutomaticCheckForUpdate();
}

if (this.IsIOS() == false) {
// TODO: Move the keys to config service
AppCenter.Configure("android=f920cc96-de56-42fe-87d4-b49105761205;" + "ios=dd940171-ca8c-4219-9851-f83769464f37;" +
"uwp=3ad27ea3-3f24-4579-a88a-530025bd00d4;" + "macos=244fdee2-f897-431a-8bab-5081fc90b329;");
AppCenter.Start(typeof(Distribute));
}
}

private Boolean IsIOS() => DeviceInfo.Current.Platform == DevicePlatform.iOS;

private Boolean OnReleaseAvailable(ReleaseDetails releaseDetails) {
// Look at releaseDetails public properties to get version information, release notes text or release notes URL
String versionName = releaseDetails.ShortVersion;
String versionCodeOrBuildNumber = releaseDetails.Version;
String releaseNotes = releaseDetails.ReleaseNotes;
Uri releaseNotesUrl = releaseDetails.ReleaseNotesUrl;

// custom dialog
String title = "Version " + versionName + " available!";
Task answer;

// On mandatory update, user can't postpone
if (releaseDetails.MandatoryUpdate) {
answer = this.DialogService.ShowDialog(title, releaseNotes, "Download and Install");
}
else {
answer = this.DialogService.ShowDialog(title, releaseNotes, "Download and Install", "Later");
}

answer.ContinueWith(task => {
// If mandatory or if answer was positive
if (releaseDetails.MandatoryUpdate || (task as Task<Boolean>).Result) {
// Notify SDK that user selected update
Distribute.NotifyUpdateAction(UpdateAction.Update);
}
else {
// Notify SDK that user selected postpone (for 1 day)
// This method call is ignored by the SDK if the update is mandatory
Distribute.NotifyUpdateAction(UpdateAction.Postpone);
}
});

// Return true if you're using your own dialog, false otherwise
return true;
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private async Task LoginCommandExecute()
this.MemoryCacheService.Set("IsLoggedIn", true);

await this.NavigationService.GoToHome();

}

private async void AccessTokenExpired(Object key,
Expand Down
22 changes: 11 additions & 11 deletions TransactionMobile.Maui.UiTests/Features/Login.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using TransactionMobile.Maui.Pages.Support;
using System;
using BusinessLogic.ViewModels.MyAccount;
using Pages.AppHome;
using Pages.MyAccount;

public static class MauiAppBuilderExtensions
Expand Down Expand Up @@ -182,7 +183,7 @@ public static MauiAppBuilder ConfigureTrainingServices(this MauiAppBuilder build

public static MauiAppBuilder ConfigureUIServices(this MauiAppBuilder builder)
{
// builder.Services.AddSingleton<IDialogService, DialogService>();
builder.Services.AddSingleton<IDialogService, DialogService>();
builder.Services.AddSingleton<INavigationService, ShellNavigationService>();
builder.Services.AddSingleton<IApplicationInfoService, ApplicationInfoService>();
return builder;
Expand Down Expand Up @@ -232,6 +233,8 @@ public static MauiAppBuilder ConfigureViewModels(this MauiAppBuilder builder)

builder.Services.AddTransient<MyAccountPageViewModel>();

builder.Services.AddTransient<HomePageViewModel>();

return builder;
}

Expand All @@ -258,6 +261,8 @@ public static MauiAppBuilder ConfigurePages(this MauiAppBuilder builder)

builder.Services.AddTransient<MyAccountPage>();

builder.Services.AddTransient<HomePage>();

return builder;
}

Expand Down
27 changes: 22 additions & 5 deletions TransactionMobile.Maui/Pages/AppHome/HomePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
namespace TransactionMobile.Maui.Pages.AppHome;

using BusinessLogic.ViewModels;

public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
}
#region Constructors

public HomePage(HomePageViewModel vm) {
this.InitializeComponent();
this.BindingContext = vm;
}

#endregion

#region Properties

protected override void OnAppearing() {
private HomePageViewModel viewModel => this.BindingContext as HomePageViewModel;

#endregion

#region Methods

protected override async void OnAppearing() {
base.OnAppearing();
await this.viewModel.Initialise(CancellationToken.None);
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,51 @@ namespace TransactionMobile.Maui.Pages.Transactions.MobileTopup;

public partial class MobileTopupSelectProductPage : ContentPage
{
private MobileTopupSelectProductPageViewModel viewModel => BindingContext as MobileTopupSelectProductPageViewModel;
#region Constructors

public MobileTopupSelectProductPage(MobileTopupSelectProductPageViewModel vm)
{
InitializeComponent();
BindingContext = vm;
public MobileTopupSelectProductPage(MobileTopupSelectProductPageViewModel vm) {
this.InitializeComponent();
this.BindingContext = vm;
}

protected override async void OnAppearing()
{
#endregion

#region Properties

private MobileTopupSelectProductPageViewModel viewModel => this.BindingContext as MobileTopupSelectProductPageViewModel;

#endregion

#region Methods

protected override async void OnAppearing() {
base.OnAppearing();
await viewModel.Initialise(CancellationToken.None);
this.LoadProducts(viewModel);
await this.viewModel.Initialise(CancellationToken.None);
this.LoadProducts(this.viewModel);
}

private void LoadProducts(MobileTopupSelectProductPageViewModel viewModel)
{
private void LoadProducts(MobileTopupSelectProductPageViewModel viewModel) {
this.ProductsList.Clear();

Int32 rowCount = 0;
foreach (ContractProductModel modelProduct in viewModel.Products)
{
Button button = new Button
{
Text = modelProduct.ProductDisplayText,
HorizontalOptions = LayoutOptions.FillAndExpand,
AutomationId = modelProduct.ProductDisplayText,
};
foreach (ContractProductModel modelProduct in viewModel.Products) {
Button button = new Button {
Text = modelProduct.ProductDisplayText,
HorizontalOptions = LayoutOptions.FillAndExpand,
AutomationId = modelProduct.ProductDisplayText,
};
button.SetDynamicResource(VisualElement.StyleProperty, "MobileTopupButtonStyle");

Binding commandParameter = new Binding()
{
Source = new ItemSelected<ContractProductModel>
{
SelectedItem = modelProduct,
SelectedItemIndex = rowCount
}
};
Binding commandParameter = new Binding {
Source = new ItemSelected<ContractProductModel> {
SelectedItem = modelProduct,
SelectedItemIndex = rowCount
}
};

Binding command = new Binding
{
Source = viewModel.ProductSelectedCommand
};
Binding command = new Binding {
Source = viewModel.ProductSelectedCommand
};

button.SetBinding(Button.CommandProperty, command);
button.SetBinding(Button.CommandParameterProperty, commandParameter);
Expand All @@ -58,4 +60,6 @@ private void LoadProducts(MobileTopupSelectProductPageViewModel viewModel)
rowCount++;
}
}

#endregion
}
Loading