Refactor About->Login

This commit is contained in:
2024-09-11 14:28:52 +02:00
parent 94c6acbe14
commit 6cf55aa258
6 changed files with 53 additions and 72 deletions

View File

@@ -19,7 +19,7 @@
<ShellContent
Title="Login"
ContentTemplate="{DataTemplate views:AboutPage}"
ContentTemplate="{DataTemplate views:LoginPage}"
Icon="{OnPlatform 'icon_about.png', iOS='icon_about_ios.png', MacCatalyst='icon_about_ios.png'}" />
</TabBar>

View File

@@ -41,6 +41,10 @@
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
@@ -72,13 +76,13 @@
</ItemGroup>
<ItemGroup>
<Compile Update="Views\AboutPage.xaml.cs">
<DependentUpon>AboutPage.xaml</DependentUpon>
<Compile Update="Views\LoginPage.xaml.cs">
<DependentUpon>LoginPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<MauiXaml Update="Views\AboutPage.xaml">
<MauiXaml Update="Views\LoginPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\AllNotesPage.xaml">

View File

@@ -1,54 +0,0 @@
using CommunityToolkit.Mvvm.Input;
using System.Windows.Input;
using Microsoft.Maui.Dispatching;
//using BarcodeScanning;
namespace Jugenddienst_Stunden.ViewModels {
internal class AboutViewModel {
public string AppTitle => AppInfo.Name;
public string Version => AppInfo.VersionString;
public string Message => "Scanne den QR-Code von deinem Benutzerprofil auf der Stundenseite.";
public string Title { get; set; } = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
//private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
// var first = e.Results?.FirstOrDefault();
// if (first is null) {
// return;
// }
// System.Windows.Application.Current.Dispatcher.DispatchAsync(async () => {
// await DisplayAlert("Scan-Ergebnis", $"Barcode: {first.Value}", "OK");
// });
//}
//private async void SetupBarcodeScanner() {
// try {
// var scanner = new BarcodeScanner();
// var result = await scanner.ScanAsync();
// if (result != null) {
// await DisplayAlert("Scan-Ergebnis", $"Barcode: {result.Barcode}", "OK");
// } else {
// await DisplayAlert("Scan Abgebrochen", "Der Barcode-Scan wurde abgebrochen.", "OK");
// }
// } catch (Exception ex) {
// await DisplayAlert("Fehler", $"Ein Fehler ist aufgetreten: {ex.Message}", "OK");
// }
//}
//private static void BarcodesDetected(object sender, OnDetectionFinishedEventArg e) {
// if (e.BarcodeResults.Length > 0) {
// // Hier verarbeiten Sie den erkannten Barcode
// //Console.WriteLine($"Detected barcode: {e.BarcodeResults.GetType()} {e.BarcodeResults.ToString()}");
// await DisplayAlert("Scan-Ergebnis", $"Barcode: {e.BarcodeResults.GetType()} {e.BarcodeResults.ToString()}", "OK");
// }
//}
}
}

View File

@@ -0,0 +1,17 @@
using CommunityToolkit.Mvvm.Input;
using System.Windows.Input;
using Microsoft.Maui.Dispatching;
//using BarcodeScanning;
namespace Jugenddienst_Stunden.ViewModels {
internal class LoginViewModel {
public string AppTitle => AppInfo.Name;
public string Version => AppInfo.VersionString;
public string Message => "Scanne den QR-Code von deinem Benutzerprofil auf der Stundenseite.";
public string Title { get; set; } = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
}
}

View File

@@ -3,11 +3,11 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels"
xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"
x:Class="Jugenddienst_Stunden.Views.AboutPage"
x:Class="Jugenddienst_Stunden.Views.LoginPage"
Title="{Binding Title}">
<ContentPage.BindingContext>
<models:AboutViewModel />
<models:LoginViewModel />
</ContentPage.BindingContext>
<VerticalStackLayout Spacing="10" Margin="15">

View File

@@ -5,12 +5,12 @@ using ZXing.Net.Maui;
namespace Jugenddienst_Stunden.Views;
public partial class AboutPage : ContentPage {
public partial class LoginPage : ContentPage {
private DateTime _lastDetectionTime;
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(3);
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
public AboutPage() {
public LoginPage() {
InitializeComponent();
barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions {
@@ -20,24 +20,38 @@ public partial class AboutPage : ContentPage {
};
}
//public event EventHandler<string> AlertEvent;
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
//var first = e.Results?.FirstOrDefault();
var currentTime = DateTime.Now;
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
_lastDetectionTime = currentTime;
foreach (var barcode in e.Results) {
if (Preferences.Default.Get("apiKey", "") != barcode.Value) {
if (Stunde.apiKey != barcode.Value) {
MainThread.InvokeOnMainThreadAsync(async () => {
//DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
Preferences.Default.Set("apiKey", barcode.Value);
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
try {
var op = await Models.Operator.LoadData(barcode.Value);
Models.Stunde.apiKey = barcode.Value;
Models.Stunde.name = op.name;
Models.Stunde.surname = op.surname;
Title = op.name + " " + op.surname;
Preferences.Default.Set("apiKey", barcode.Value);
Preferences.Default.Set("name", op.name);
Preferences.Default.Set("surname", op.surname);
await DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
} catch (Exception e) {
//AlertEvent?.Invoke(this, e.Message);
await DisplayAlert("Fehler",
e.Message,
"OK");
}
Models.Stunde.apiKey = barcode.Value;
var op = await Models.Operator.LoadData(barcode.Value);
Preferences.Default.Set("name", op.name);
Preferences.Default.Set("surname", op.surname);
DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
Title = op.name + " " + op.surname;
});
} else {