Add app rating and sharing functionality to MoreView and MoreWalkerView

This commit is contained in:
Max Mannstein 2025-07-22 17:43:19 +02:00
parent 0ee468ef8c
commit 421672e8cb
6 changed files with 230 additions and 12 deletions

View File

@ -1,4 +1,5 @@
using CommunityToolkit.Maui; using Plugin.Maui.AppRating;
using CommunityToolkit.Maui;
using gehGassi.LocalNotifications; using gehGassi.LocalNotifications;
using gehGassiApp.Constants; using gehGassiApp.Constants;
using gehGassiApp.Core.Data; using gehGassiApp.Core.Data;
@ -484,7 +485,8 @@ public static class MauiProgram
SetHandler(); SetHandler();
return builder.Build(); builder.Services.AddSingleton<IAppRating>(AppRating.Default);
return builder.Build();
} }
#region Handler #region Handler

View File

@ -1,4 +1,5 @@
using System.Text.Json; using Plugin.Maui.AppRating;
using System.Text.Json;
using CommunityToolkit.Maui.Core; using CommunityToolkit.Maui.Core;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
@ -30,7 +31,8 @@ namespace gehGassiApp.ViewModels.More
private readonly IDialogService _dialogService; private readonly IDialogService _dialogService;
private readonly ISystemMessageService _systemMessageService; private readonly ISystemMessageService _systemMessageService;
private readonly IDispatcher _dispatcher; private readonly IDispatcher _dispatcher;
private readonly IPushnotificationService _pushnotificationService; private readonly IPushnotificationService _pushnotificationService;
private readonly IAppRating _appRating;
/// <summary> /// <summary>
/// Erstellt eine Instanz /// Erstellt eine Instanz
@ -40,8 +42,8 @@ namespace gehGassiApp.ViewModels.More
/// <param name="systemMessageService">Instanz eines ISystemMessageService</param> /// <param name="systemMessageService">Instanz eines ISystemMessageService</param>
/// <param name="dispatcher">Instanz eines IDispatcher</param> /// <param name="dispatcher">Instanz eines IDispatcher</param>
/// <param name="pushnotificationService">Instanz eines IPushnotificationService</param> /// <param name="pushnotificationService">Instanz eines IPushnotificationService</param>
public MoreViewModel(IAccountService accountService, IDialogService dialogService, ISystemMessageService systemMessageService, IDispatcher dispatcher, public MoreViewModel(IAccountService accountService, IDialogService dialogService, ISystemMessageService systemMessageService, IDispatcher dispatcher,
IPushnotificationService pushnotificationService) IPushnotificationService pushnotificationService, IAppRating appRating)
{ {
_accountService = accountService; _accountService = accountService;
_dialogService = dialogService; _dialogService = dialogService;
@ -50,6 +52,43 @@ namespace gehGassiApp.ViewModels.More
_pushnotificationService = pushnotificationService; _pushnotificationService = pushnotificationService;
Title = Text.View_Title_More; Title = Text.View_Title_More;
SelectedMenu = MenuSelected.More; SelectedMenu = MenuSelected.More;
_appRating = appRating;
}
/// <summary>
/// Command für die Store-Bewertung
/// </summary>
[RelayCommand]
public async Task RateApp()
{
try
{
await _appRating.PerformRatingOnStoreAsync(
packageName: "com.gehgassi.gehgassi",
applicationId: "id1662116305"
);
}
catch (Exception ex)
{
await TrackErrorAsync(ex, true);
}
}
/// <summary>
/// Command für das Teilen der App
/// </summary>
[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"
});
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using System.Text.Json; using Plugin.Maui.AppRating;
using System.Text.Json;
using CommunityToolkit.Maui.Core; using CommunityToolkit.Maui.Core;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
@ -30,7 +31,8 @@ namespace gehGassiApp.ViewModels.More
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly ISystemMessageService _systemMessageService; private readonly ISystemMessageService _systemMessageService;
private readonly IDispatcher _dispatcher; private readonly IDispatcher _dispatcher;
private readonly IPushnotificationService _pushnotificationService; private readonly IPushnotificationService _pushnotificationService;
private readonly IAppRating _appRating;
/// <summary> /// <summary>
/// Erstellt eine Instanz /// Erstellt eine Instanz
@ -41,8 +43,8 @@ namespace gehGassiApp.ViewModels.More
/// <param name="systemMessageService">Instanz eines ISystemMessageService</param> /// <param name="systemMessageService">Instanz eines ISystemMessageService</param>
/// <param name="dispatcher">Instanz eines IDispatcher</param> /// <param name="dispatcher">Instanz eines IDispatcher</param>
/// <param name="pushnotificationService">Instanz eines IPushnotificationService</param> /// <param name="pushnotificationService">Instanz eines IPushnotificationService</param>
public MoreWalkerViewModel(IAccountService accountService, IDialogService dialogService, IUserService userService, ISystemMessageService systemMessageService, IDispatcher dispatcher, public MoreWalkerViewModel(IAccountService accountService, IDialogService dialogService, IUserService userService, ISystemMessageService systemMessageService, IDispatcher dispatcher,
IPushnotificationService pushnotificationService) IPushnotificationService pushnotificationService, IAppRating appRating)
{ {
_accountService = accountService; _accountService = accountService;
_dialogService = dialogService; _dialogService = dialogService;
@ -52,8 +54,43 @@ namespace gehGassiApp.ViewModels.More
_pushnotificationService = pushnotificationService; _pushnotificationService = pushnotificationService;
Title = Text.View_Title_More; Title = Text.View_Title_More;
SelectedMenu = MenuSelected.More; SelectedMenu = MenuSelected.More;
_appRating = appRating;
} }
/// <summary>
/// Command für die Store-Bewertung
/// </summary>
[RelayCommand]
public async Task RateApp()
{
try
{
await _appRating.PerformRatingOnStoreAsync(
packageName: "com.gehgassi.gehgassi",
applicationId: "id1662116305"
);
}
catch (Exception ex)
{
await TrackErrorAsync(ex, true);
}
}
/// <summary>
/// Command für das Teilen der App
/// </summary>
[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"
});
}
/// <summary> /// <summary>
/// Gibt an ob Switch verfügbar ist /// Gibt an ob Switch verfügbar ist
/// </summary> /// </summary>

View File

@ -398,6 +398,76 @@
<Border Style="{StaticResource Separator}" /> <Border Style="{StaticResource Separator}" />
<Grid
ColumnDefinitions="24,*,24"
ColumnSpacing="12"
HorizontalOptions="FillAndExpand"
VerticalOptions="StartAndExpand">
<Image Grid.Column="0" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="MaterialIconsRegular"
Glyph="thumb_up"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Label
Grid.Column="1"
HorizontalOptions="StartAndExpand"
LineBreakMode="TailTruncation"
Style="{StaticResource H5_Blue}"
Text="App bewerten"
VerticalOptions="Center" />
<Image Grid.Column="2" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="IconMoon"
Glyph="{x:Static i:IconsMoon.Icon_Chevron_Right}"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding RateAppCommand}" />
</Grid.GestureRecognizers>
</Grid>
<Border Style="{StaticResource Separator}" />
<Grid
ColumnDefinitions="24,*,24"
ColumnSpacing="12"
HorizontalOptions="FillAndExpand"
VerticalOptions="StartAndExpand">
<Image Grid.Column="0" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="MaterialIconsRegular"
Glyph="share"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Label
Grid.Column="1"
HorizontalOptions="StartAndExpand"
LineBreakMode="TailTruncation"
Style="{StaticResource H5_Blue}"
Text="App teilen"
VerticalOptions="Center" />
<Image Grid.Column="2" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="IconMoon"
Glyph="{x:Static i:IconsMoon.Icon_Chevron_Right}"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ShareAppCommand}" />
</Grid.GestureRecognizers>
</Grid>
<Border Style="{StaticResource Separator}" />
<Grid <Grid
ColumnDefinitions="24,*,24" ColumnDefinitions="24,*,24"
ColumnSpacing="12" ColumnSpacing="12"

View File

@ -221,8 +221,8 @@
</Grid.GestureRecognizers> </Grid.GestureRecognizers>
</Grid> </Grid>
<Border Style="{StaticResource Separator}" />
<Border Style="{StaticResource Separator}" />
<Grid <Grid
ColumnDefinitions="24,*,24" ColumnDefinitions="24,*,24"
ColumnSpacing="12" ColumnSpacing="12"
@ -256,8 +256,9 @@
</Grid.GestureRecognizers> </Grid.GestureRecognizers>
</Grid> </Grid>
<Border Style="{StaticResource Separator}" />
<Border Style="{StaticResource Separator}" />
<Grid <Grid
ColumnDefinitions="24,*,24" ColumnDefinitions="24,*,24"
ColumnSpacing="12" ColumnSpacing="12"
@ -360,6 +361,74 @@
<TapGestureRecognizer Command="{Binding FeedbackCommand}" /> <TapGestureRecognizer Command="{Binding FeedbackCommand}" />
</Grid.GestureRecognizers> </Grid.GestureRecognizers>
</Grid> </Grid>
<Border Style="{StaticResource Separator}" />
<Grid
ColumnDefinitions="24,*,24"
ColumnSpacing="12"
HorizontalOptions="FillAndExpand"
VerticalOptions="StartAndExpand">
<Image Grid.Column="0" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="MaterialIconsRegular"
Glyph="thumb_up"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Label
Grid.Column="1"
HorizontalOptions="StartAndExpand"
LineBreakMode="TailTruncation"
Style="{StaticResource H5_Blue}"
Text="App bewerten"
VerticalOptions="Center" />
<Image Grid.Column="2" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="IconMoon"
Glyph="{x:Static i:IconsMoon.Icon_Chevron_Right}"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding RateAppCommand}" />
</Grid.GestureRecognizers>
</Grid>
<Border Style="{StaticResource Separator}" />
<Grid
ColumnDefinitions="24,*,24"
ColumnSpacing="12"
HorizontalOptions="FillAndExpand"
VerticalOptions="StartAndExpand">
<Image Grid.Column="0" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="MaterialIconsRegular"
Glyph="share"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Label
Grid.Column="1"
HorizontalOptions="StartAndExpand"
LineBreakMode="TailTruncation"
Style="{StaticResource H5_Blue}"
Text="App teilen"
VerticalOptions="Center" />
<Image Grid.Column="2" HeightRequest="24">
<Image.Source>
<FontImageSource
FontFamily="IconMoon"
Glyph="{x:Static i:IconsMoon.Icon_Chevron_Right}"
Color="{StaticResource Primary_DarkBlue}" />
</Image.Source>
</Image>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ShareAppCommand}" />
</Grid.GestureRecognizers>
</Grid>
<Border Style="{StaticResource Separator}" /> <Border Style="{StaticResource Separator}" />

View File

@ -205,6 +205,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.12" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.12" />
<PackageReference Include="Microsoft.Maui.Graphics.Skia" Version="8.0.100" /> <PackageReference Include="Microsoft.Maui.Graphics.Skia" Version="8.0.100" />
<PackageReference Include="Plugin.InAppBilling" Version="8.0.5" /> <PackageReference Include="Plugin.InAppBilling" Version="8.0.5" />
<PackageReference Include="Plugin.Maui.AppRating" Version="1.2.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.100" /> <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.100" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.100" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.100" />