Barcodes speichern
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Jugenddienst_Stunden.Models;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System.Collections.Generic;
|
||||
using ZXing.Net.Maui;
|
||||
@@ -21,15 +22,31 @@ public partial class AboutPage : ContentPage {
|
||||
|
||||
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) {
|
||||
MainThread.InvokeOnMainThreadAsync(() => {
|
||||
DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
||||
Models.Stunde.apiKey = barcode.Value;
|
||||
});
|
||||
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("Neuer Barcode erkannt", op.name + " " + op.surname, "OK");
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
MainThread.InvokeOnMainThreadAsync(() => {
|
||||
DisplayAlert("Barcode bereits vorhanden",
|
||||
Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", ""),
|
||||
"OK");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,12 +67,12 @@ public partial class AboutPage : ContentPage {
|
||||
base.OnDisappearing();
|
||||
barcodeScannerView.CameraLocation = CameraLocation.Front;
|
||||
barcodeScannerView.IsDetecting = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void OnAppearing() {
|
||||
base.OnAppearing();
|
||||
|
||||
|
||||
barcodeScannerView.IsDetecting = true;
|
||||
barcodeScannerView.CameraLocation = CameraLocation.Rear;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user