diff --git a/Jugenddienst Stunden/AppShell.xaml b/Jugenddienst Stunden/AppShell.xaml index 2e2c661..bf1a733 100644 --- a/Jugenddienst Stunden/AppShell.xaml +++ b/Jugenddienst Stunden/AppShell.xaml @@ -19,7 +19,7 @@ diff --git a/Jugenddienst Stunden/Jugenddienst Stunden.csproj b/Jugenddienst Stunden/Jugenddienst Stunden.csproj index 7d97631..fb0a0de 100644 --- a/Jugenddienst Stunden/Jugenddienst Stunden.csproj +++ b/Jugenddienst Stunden/Jugenddienst Stunden.csproj @@ -41,6 +41,10 @@ $(TargetFrameworks);net8.0-windows10.0.26100.0 + + False + + @@ -72,13 +76,13 @@ - - AboutPage.xaml + + LoginPage.xaml - + MSBuild:Compile diff --git a/Jugenddienst Stunden/ViewModels/AboutViewModel.cs b/Jugenddienst Stunden/ViewModels/AboutViewModel.cs deleted file mode 100644 index 6cb585d..0000000 --- a/Jugenddienst Stunden/ViewModels/AboutViewModel.cs +++ /dev/null @@ -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"); - // } - //} - - - - } -} diff --git a/Jugenddienst Stunden/ViewModels/LoginViewModel.cs b/Jugenddienst Stunden/ViewModels/LoginViewModel.cs new file mode 100644 index 0000000..12eb08f --- /dev/null +++ b/Jugenddienst Stunden/ViewModels/LoginViewModel.cs @@ -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", ""); + + + } +} diff --git a/Jugenddienst Stunden/Views/AboutPage.xaml b/Jugenddienst Stunden/Views/LoginPage.xaml similarity index 92% rename from Jugenddienst Stunden/Views/AboutPage.xaml rename to Jugenddienst Stunden/Views/LoginPage.xaml index b76a615..35c575b 100644 --- a/Jugenddienst Stunden/Views/AboutPage.xaml +++ b/Jugenddienst Stunden/Views/LoginPage.xaml @@ -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}"> - + diff --git a/Jugenddienst Stunden/Views/AboutPage.xaml.cs b/Jugenddienst Stunden/Views/LoginPage.xaml.cs similarity index 66% rename from Jugenddienst Stunden/Views/AboutPage.xaml.cs rename to Jugenddienst Stunden/Views/LoginPage.xaml.cs index 98f8ee1..69f84e9 100644 --- a/Jugenddienst Stunden/Views/AboutPage.xaml.cs +++ b/Jugenddienst Stunden/Views/LoginPage.xaml.cs @@ -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 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 {