Refactor About->Login
This commit is contained in:
@@ -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">
|
||||
@@ -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 {
|
||||
Reference in New Issue
Block a user