From 421672e8cb3b30cec2bcce28654f75fc3acfbfd3 Mon Sep 17 00:00:00 2001 From: Max Mannstein Date: Tue, 22 Jul 2025 17:43:19 +0200 Subject: [PATCH] Add app rating and sharing functionality to MoreView and MoreWalkerView --- gehGassiApp/gehGassiApp/MauiProgram.cs | 6 +- .../ViewModels/More/MoreViewModel.cs | 47 +++++++++++- .../ViewModels/More/MoreWalkerViewModel.cs | 45 +++++++++++- .../gehGassiApp/Views/More/MoreView.xaml | 70 ++++++++++++++++++ .../Views/More/MoreWalkerView.xaml | 73 ++++++++++++++++++- gehGassiApp/gehGassiApp/gehGassiApp.csproj | 1 + 6 files changed, 230 insertions(+), 12 deletions(-) diff --git a/gehGassiApp/gehGassiApp/MauiProgram.cs b/gehGassiApp/gehGassiApp/MauiProgram.cs index d2c12bf..2b146bb 100644 --- a/gehGassiApp/gehGassiApp/MauiProgram.cs +++ b/gehGassiApp/gehGassiApp/MauiProgram.cs @@ -1,4 +1,5 @@ -using CommunityToolkit.Maui; +using Plugin.Maui.AppRating; +using CommunityToolkit.Maui; using gehGassi.LocalNotifications; using gehGassiApp.Constants; using gehGassiApp.Core.Data; @@ -484,7 +485,8 @@ public static class MauiProgram SetHandler(); - return builder.Build(); + builder.Services.AddSingleton(AppRating.Default); + return builder.Build(); } #region Handler diff --git a/gehGassiApp/gehGassiApp/ViewModels/More/MoreViewModel.cs b/gehGassiApp/gehGassiApp/ViewModels/More/MoreViewModel.cs index c915dda..84cb71d 100644 --- a/gehGassiApp/gehGassiApp/ViewModels/More/MoreViewModel.cs +++ b/gehGassiApp/gehGassiApp/ViewModels/More/MoreViewModel.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using Plugin.Maui.AppRating; +using System.Text.Json; using CommunityToolkit.Maui.Core; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -30,7 +31,8 @@ namespace gehGassiApp.ViewModels.More private readonly IDialogService _dialogService; private readonly ISystemMessageService _systemMessageService; private readonly IDispatcher _dispatcher; - private readonly IPushnotificationService _pushnotificationService; + private readonly IPushnotificationService _pushnotificationService; + private readonly IAppRating _appRating; /// /// Erstellt eine Instanz @@ -40,8 +42,8 @@ namespace gehGassiApp.ViewModels.More /// Instanz eines ISystemMessageService /// Instanz eines IDispatcher /// Instanz eines IPushnotificationService - public MoreViewModel(IAccountService accountService, IDialogService dialogService, ISystemMessageService systemMessageService, IDispatcher dispatcher, - IPushnotificationService pushnotificationService) + public MoreViewModel(IAccountService accountService, IDialogService dialogService, ISystemMessageService systemMessageService, IDispatcher dispatcher, + IPushnotificationService pushnotificationService, IAppRating appRating) { _accountService = accountService; _dialogService = dialogService; @@ -50,6 +52,43 @@ namespace gehGassiApp.ViewModels.More _pushnotificationService = pushnotificationService; Title = Text.View_Title_More; SelectedMenu = MenuSelected.More; + _appRating = appRating; + } + + /// + /// Command für die Store-Bewertung + /// + [RelayCommand] + public async Task RateApp() + { + try + { + await _appRating.PerformRatingOnStoreAsync( + packageName: "com.gehgassi.gehgassi", + applicationId: "id1662116305" + ); + } + catch (Exception ex) + { + await TrackErrorAsync(ex, true); + } + } + + /// + /// Command für das Teilen der App + /// + [RelayCommand] + public async Task ShareApp() + { + string url = DeviceInfo.Platform == DevicePlatform.iOS + ? "https://apps.apple.com/us/app/gehgassi/id1662116305" + : "https://play.google.com/store/apps/details?id=com.gehgassi.gehgassi"; + string text = $"Schau dir die gehgassi App an! {url}"; + await Share.Default.RequestAsync(new ShareTextRequest + { + Text = text, + Title = "App teilen" + }); } /// diff --git a/gehGassiApp/gehGassiApp/ViewModels/More/MoreWalkerViewModel.cs b/gehGassiApp/gehGassiApp/ViewModels/More/MoreWalkerViewModel.cs index f9374a2..dac3623 100644 --- a/gehGassiApp/gehGassiApp/ViewModels/More/MoreWalkerViewModel.cs +++ b/gehGassiApp/gehGassiApp/ViewModels/More/MoreWalkerViewModel.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using Plugin.Maui.AppRating; +using System.Text.Json; using CommunityToolkit.Maui.Core; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -30,7 +31,8 @@ namespace gehGassiApp.ViewModels.More private readonly IUserService _userService; private readonly ISystemMessageService _systemMessageService; private readonly IDispatcher _dispatcher; - private readonly IPushnotificationService _pushnotificationService; + private readonly IPushnotificationService _pushnotificationService; + private readonly IAppRating _appRating; /// /// Erstellt eine Instanz @@ -41,8 +43,8 @@ namespace gehGassiApp.ViewModels.More /// Instanz eines ISystemMessageService /// Instanz eines IDispatcher /// Instanz eines IPushnotificationService - public MoreWalkerViewModel(IAccountService accountService, IDialogService dialogService, IUserService userService, ISystemMessageService systemMessageService, IDispatcher dispatcher, - IPushnotificationService pushnotificationService) + public MoreWalkerViewModel(IAccountService accountService, IDialogService dialogService, IUserService userService, ISystemMessageService systemMessageService, IDispatcher dispatcher, + IPushnotificationService pushnotificationService, IAppRating appRating) { _accountService = accountService; _dialogService = dialogService; @@ -52,8 +54,43 @@ namespace gehGassiApp.ViewModels.More _pushnotificationService = pushnotificationService; Title = Text.View_Title_More; SelectedMenu = MenuSelected.More; + _appRating = appRating; } + /// + /// Command für die Store-Bewertung + /// + [RelayCommand] + public async Task RateApp() + { + try + { + await _appRating.PerformRatingOnStoreAsync( + packageName: "com.gehgassi.gehgassi", + applicationId: "id1662116305" + ); + } + catch (Exception ex) + { + await TrackErrorAsync(ex, true); + } + } + /// + /// Command für das Teilen der App + /// + [RelayCommand] + public async Task ShareApp() + { + string url = DeviceInfo.Platform == DevicePlatform.iOS + ? "https://apps.apple.com/us/app/gehgassi/id1662116305" + : "https://play.google.com/store/apps/details?id=com.gehgassi.gehgassi"; + string text = $"Schau dir die gehgassi App an! {url}"; + await Share.Default.RequestAsync(new ShareTextRequest + { + Text = text, + Title = "App teilen" + }); + } /// /// Gibt an ob Switch verfügbar ist /// diff --git a/gehGassiApp/gehGassiApp/Views/More/MoreView.xaml b/gehGassiApp/gehGassiApp/Views/More/MoreView.xaml index d48dd5c..d8a74f3 100644 --- a/gehGassiApp/gehGassiApp/Views/More/MoreView.xaml +++ b/gehGassiApp/gehGassiApp/Views/More/MoreView.xaml @@ -398,6 +398,76 @@ + + + + + + + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + diff --git a/gehGassiApp/gehGassiApp/gehGassiApp.csproj b/gehGassiApp/gehGassiApp/gehGassiApp.csproj index 1953284..540c331 100644 --- a/gehGassiApp/gehGassiApp/gehGassiApp.csproj +++ b/gehGassiApp/gehGassiApp/gehGassiApp.csproj @@ -205,6 +205,7 @@ +