81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using Jugenddienst_Stunden.Models;
|
|
using Microsoft.Maui.Controls;
|
|
using System.Collections.Generic;
|
|
using ZXing.Net.Maui;
|
|
|
|
namespace Jugenddienst_Stunden.Views;
|
|
|
|
public partial class AboutPage : ContentPage {
|
|
|
|
private DateTime _lastDetectionTime;
|
|
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(3);
|
|
|
|
public AboutPage() {
|
|
InitializeComponent();
|
|
|
|
barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions {
|
|
Formats = ZXing.Net.Maui.BarcodeFormat.QrCode,
|
|
AutoRotate = true,
|
|
Multiple = false
|
|
};
|
|
}
|
|
|
|
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) {
|
|
MainThread.InvokeOnMainThreadAsync(async () => {
|
|
//DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
|
Preferences.Default.Set("apiKey", barcode.Value);
|
|
|
|
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 {
|
|
MainThread.InvokeOnMainThreadAsync(() => {
|
|
DisplayAlert("Bereits eingeloggt",
|
|
Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", ""),
|
|
"OK");
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
//if (first is null) {
|
|
// return;
|
|
//}
|
|
//Dispatcher.DispatchAsync(async () => {
|
|
// await DisplayAlert("Scan-Ergebnis", $"Barcode: {first.Value}", "OK");
|
|
//});
|
|
//MainThread.InvokeOnMainThreadAsync(() => {
|
|
// DisplayAlert("Barcode erkannt", $"Barcode: {first.Format} - {first.Value}", "OK");
|
|
// Models.Stunde.apiKey = first.Value;
|
|
//});
|
|
|
|
}
|
|
|
|
protected override void OnDisappearing() {
|
|
base.OnDisappearing();
|
|
barcodeScannerView.CameraLocation = CameraLocation.Front;
|
|
barcodeScannerView.IsDetecting = false;
|
|
|
|
}
|
|
|
|
protected override void OnAppearing() {
|
|
base.OnAppearing();
|
|
|
|
barcodeScannerView.IsDetecting = true;
|
|
barcodeScannerView.CameraLocation = CameraLocation.Rear;
|
|
}
|
|
|
|
|
|
} |