Refactor About->Login
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<ShellContent
|
<ShellContent
|
||||||
Title="Login"
|
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'}" />
|
Icon="{OnPlatform 'icon_about.png', iOS='icon_about_ios.png', MacCatalyst='icon_about_ios.png'}" />
|
||||||
</TabBar>
|
</TabBar>
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,10 @@
|
|||||||
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
|
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
|
||||||
|
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- App Icon -->
|
<!-- App Icon -->
|
||||||
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
|
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
|
||||||
@@ -72,13 +76,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Views\AboutPage.xaml.cs">
|
<Compile Update="Views\LoginPage.xaml.cs">
|
||||||
<DependentUpon>AboutPage.xaml</DependentUpon>
|
<DependentUpon>LoginPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<MauiXaml Update="Views\AboutPage.xaml">
|
<MauiXaml Update="Views\LoginPage.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</MauiXaml>
|
</MauiXaml>
|
||||||
<MauiXaml Update="Views\AllNotesPage.xaml">
|
<MauiXaml Update="Views\AllNotesPage.xaml">
|
||||||
|
|||||||
@@ -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");
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
Jugenddienst Stunden/ViewModels/LoginViewModel.cs
Normal file
17
Jugenddienst Stunden/ViewModels/LoginViewModel.cs
Normal 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", "");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,11 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels"
|
xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels"
|
||||||
xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"
|
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}">
|
Title="{Binding Title}">
|
||||||
|
|
||||||
<ContentPage.BindingContext>
|
<ContentPage.BindingContext>
|
||||||
<models:AboutViewModel />
|
<models:LoginViewModel />
|
||||||
</ContentPage.BindingContext>
|
</ContentPage.BindingContext>
|
||||||
|
|
||||||
<VerticalStackLayout Spacing="10" Margin="15">
|
<VerticalStackLayout Spacing="10" Margin="15">
|
||||||
@@ -5,12 +5,12 @@ using ZXing.Net.Maui;
|
|||||||
|
|
||||||
namespace Jugenddienst_Stunden.Views;
|
namespace Jugenddienst_Stunden.Views;
|
||||||
|
|
||||||
public partial class AboutPage : ContentPage {
|
public partial class LoginPage : ContentPage {
|
||||||
|
|
||||||
private DateTime _lastDetectionTime;
|
private DateTime _lastDetectionTime;
|
||||||
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(3);
|
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
public AboutPage() {
|
public LoginPage() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions {
|
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) {
|
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
|
||||||
//var first = e.Results?.FirstOrDefault();
|
//var first = e.Results?.FirstOrDefault();
|
||||||
var currentTime = DateTime.Now;
|
var currentTime = DateTime.Now;
|
||||||
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
||||||
_lastDetectionTime = currentTime;
|
_lastDetectionTime = currentTime;
|
||||||
foreach (var barcode in e.Results) {
|
foreach (var barcode in e.Results) {
|
||||||
if (Preferences.Default.Get("apiKey", "") != barcode.Value) {
|
if (Stunde.apiKey != barcode.Value) {
|
||||||
MainThread.InvokeOnMainThreadAsync(async () => {
|
MainThread.InvokeOnMainThreadAsync(async () => {
|
||||||
//DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
||||||
Preferences.Default.Set("apiKey", barcode.Value);
|
|
||||||
|
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 {
|
} else {
|
||||||
Reference in New Issue
Block a user