Vorbereitungen für 1.0.6

Beachte die Einstellung ob Projekte und Gemeinden aktiv sind.
Verbiete Änderungen an der Freistellung, wenn sie genehmigt wurde.
Vereinfache das Speichern der Einstellungen
Bessere Fehlerbehandlung, einheitlichere API
This commit is contained in:
2024-10-22 17:42:35 +02:00
parent ff145b2c7f
commit 45c53c85ce
11 changed files with 350 additions and 293 deletions

View File

@@ -1,5 +1,6 @@
using Jugenddienst_Stunden.Models;
using ZXing.Net.Maui;
using Jugenddienst_Stunden.Types;
namespace Jugenddienst_Stunden.Views;
@@ -8,145 +9,142 @@ namespace Jugenddienst_Stunden.Views;
/// </summary>
public partial class LoginPage : ContentPage {
private DateTime _lastDetectionTime;
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
private DateTime _lastDetectionTime;
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
internal HoursBase HoursBase = new HoursBase();
/// <summary>
/// CTOR
/// </summary>
public LoginPage() {
InitializeComponent();
InitializeComponent();
//if (BindingContext is LoginViewModel vm) {
// vm.AlertEvent += Vm_AlertEvent;
// vm.InfoEvent += Vm_InfoEvent;
// vm.MsgEvent += Vm_MsgEvent;
//}
barcodeScannerView.Options = new BarcodeReaderOptions {
Formats = BarcodeFormat.QrCode,
AutoRotate = true,
Multiple = false
};
barcodeScannerView.Options = new BarcodeReaderOptions {
Formats = BarcodeFormat.QrCode,
AutoRotate = true,
Multiple = false
};
}
//if (BindingContext is LoginViewModel vm) {
// vm.AlertEvent += Vm_AlertEvent;
// vm.InfoEvent += Vm_InfoEvent;
// vm.MsgEvent += Vm_MsgEvent;
//}
}
private void BarcodesDetected(object sender, BarcodeDetectionEventArgs e) {
private void BarcodesDetected(object sender, BarcodeDetectionEventArgs e) {
var currentTime = DateTime.Now;
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
_lastDetectionTime = currentTime;
foreach (var barcode in e.Results) {
if (HoursBase.apiKey != barcode.Value) {
_ = MainThread.InvokeOnMainThreadAsync(async () => {
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
var currentTime = DateTime.Now;
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
_lastDetectionTime = currentTime;
foreach (var barcode in e.Results) {
if (GlobalVar.ApiKey != barcode.Value) {
_ = MainThread.InvokeOnMainThreadAsync(async () => {
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
try {
var tokendata = new TokenData(barcode.Value);
HoursBase.tokendata = tokendata;
try {
var tokendata = new TokenData(barcode.Value);
GlobalVar.ApiUrl = tokendata.Url;
User user = await HoursBase.LoadUser(barcode.Value);
var op = await HoursBase.LoadOperator(barcode.Value);
HoursBase.apiKey = barcode.Value;
HoursBase.name = op.name;
HoursBase.surname = op.surname;
HoursBase.EmployeeId = int.Parse(op.id);
Title = op.name + " " + op.surname;
ServerLabel.Text = "Server: " + tokendata.Url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
GlobalVar.ApiKey = barcode.Value;
GlobalVar.Name = user.Name;
GlobalVar.Surname = user.Surname;
GlobalVar.EmployeeId = user.Id;
Title = user.Name + " " + user.Surname;
ServerLabel.Text = "Server: " + tokendata.Url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
Preferences.Default.Set("apiKey", barcode.Value);
Preferences.Default.Set("name", op.name);
Preferences.Default.Set("surname", op.surname);
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
//Preferences.Default.Set("apiKey", barcode.Value);
//Preferences.Default.Set("name", op.name);
//Preferences.Default.Set("surname", op.surname);
//Preferences.Default.Set("EmployeeId", int.Parse(op.id));
await DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
if (Navigation.NavigationStack.Count > 1)
await Navigation.PopAsync();
} catch (Exception e) {
await DisplayAlert("Fehler", e.Message, "OK");
}
await DisplayAlert("Login erfolgreich", user.Name + " " + user.Surname, "OK");
if (Navigation.NavigationStack.Count > 1)
await Navigation.PopAsync();
});
} else {
MainThread.InvokeOnMainThreadAsync(() => {
DisplayAlert("Bereits eingeloggt",
Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", ""),
"OK");
});
}
}
}
} catch (Exception e) {
await DisplayAlert("Fehler", e.Message, "OK");
}
}
});
} else {
MainThread.InvokeOnMainThreadAsync(() => {
DisplayAlert("Bereits eingeloggt",
Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", ""),
"OK");
});
}
}
}
protected override void OnDisappearing() {
base.OnDisappearing();
}
barcodeScannerView.CameraLocation = CameraLocation.Front;
barcodeScannerView.IsDetecting = false;
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;
protected override void OnAppearing() {
base.OnAppearing();
}
barcodeScannerView.IsDetecting = true;
barcodeScannerView.CameraLocation = CameraLocation.Rear;
public bool IsCameraAvailable() {
var status = Permissions.CheckStatusAsync<Permissions.Camera>().Result;
if (status != PermissionStatus.Granted) {
status = Permissions.RequestAsync<Permissions.Camera>().Result;
}
return status != PermissionStatus.Granted;
}
}
private async void OnLoginButtonClicked(object sender, EventArgs e) {
var username = UsernameEntry.Text;
var password = PasswordEntry.Text;
var server = ServerEntry.Text;
public bool IsCameraAvailable() {
var status = Permissions.CheckStatusAsync<Permissions.Camera>().Result;
if (status != PermissionStatus.Granted) {
status = Permissions.RequestAsync<Permissions.Camera>().Result;
}
return status != PermissionStatus.Granted;
}
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(server)) {
await DisplayAlert("Fehler", "Bitte alle Felder ausf<73>llen", "OK");
return;
}
try {
Types.User response = await BaseFunc.AuthUserPass(username, password, server);
private async void OnLoginButtonClicked(object sender, EventArgs e) {
var username = UsernameEntry.Text;
var password = PasswordEntry.Text;
var server = ServerEntry.Text;
var tokendata = new TokenData(response.Token);
var op = await HoursBase.LoadOperator(response.Token);
HoursBase.apiKey = response.Token;
HoursBase.name = op.name;
HoursBase.surname = op.surname;
HoursBase.EmployeeId = int.Parse(op.id);
Title = op.name + " " + op.surname;
ServerLabel.Text = "Server: " + tokendata.Url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(server)) {
await DisplayAlert("Fehler", "Bitte alle Felder ausf<73>llen", "OK");
return;
}
try {
Types.User response = await BaseFunc.AuthUserPass(username, password, server);
Preferences.Default.Set("apiKey", response.Token);
Preferences.Default.Set("name", op.name);
Preferences.Default.Set("surname", op.surname);
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
GlobalVar.ApiKey = response.Token;
GlobalVar.Name = response.Name;
GlobalVar.Surname = response.Surname;
GlobalVar.EmployeeId = response.Id;
GlobalVar.ApiUrl = server;
Title = response.Name + " " + response.Surname;
ServerLabel.Text = "Server: " + server.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
await DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
if (Navigation.NavigationStack.Count > 1)
await Navigation.PopAsync();
} catch (Exception ex) {
await DisplayAlert("Fehler", ex.Message, "OK");
}
}
await DisplayAlert("Login erfolgreich", response.Name + " " + response.Surname, "OK");
if (Navigation.NavigationStack.Count > 1)
await Navigation.PopAsync();
} catch (Exception ex) {
await DisplayAlert("Fehler", ex.Message, "OK");
}
}
//private void Vm_AlertEvent(object? sender, string e) {
// DisplayAlert("Fehler:", e, "OK");
//}
//private void Vm_InfoEvent(object? sender, string e) {
// DisplayAlert("Information:", e, "OK");
//}
//private async Task Vm_MsgEvent(string title, string message) {
// await DisplayAlert(title, message, "OK");
//}
//private void Vm_AlertEvent(object? sender, string e) {
// DisplayAlert("Fehler:", e, "OK");
//}
//private void Vm_InfoEvent(object? sender, string e) {
// DisplayAlert("Information:", e, "OK");
//}
//private async Task Vm_MsgEvent(string title, string message) {
// await DisplayAlert(title, message, "OK");
//}
}

View File

@@ -17,9 +17,10 @@ public partial class StundePage : ContentPage {
vm.ConfirmEvent += ShowConfirm;
}
}
private void Vm_AlertEvent(object? sender, string e) {
private void Vm_AlertEvent(object? sender, string e) {
DisplayAlert("Fehler:", e, "OK");
}

View File

@@ -1,4 +1,5 @@
using Jugenddienst_Stunden.ViewModels;
using Jugenddienst_Stunden.Models;
namespace Jugenddienst_Stunden.Views;
@@ -9,11 +10,14 @@ public partial class StundenPage : ContentPage {
private int heightValue;
/// <summary>
/// CTOR
/// </summary>
public StundenPage() {
InitializeComponent();
if (BindingContext is StundenViewModel vm) {
vm.AlertEvent += Vm_AlertEvent;
vm.InfoEvent += Vm_InfoEvent;
@@ -21,26 +25,22 @@ public partial class StundenPage : ContentPage {
if (!CheckLogin()) {
NavigateToTargetPage();
}
//// Bildschirmh<6D>he abrufen
//var screenHeight = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
//// Berechnen der gew<65>nschten H<>he
//var desiredHeight = screenHeight - 450; // Abz<62>glich der Stunden<65>bersicht
//stundeItems.HeightRequest = desiredHeight;
#if ANDROID
heightValue = 280;
#elif IOS
heightValue = 280;
heightValue = 280;
#elif WINDOWS
heightValue = 320;
heightValue = 320;
#else
heightValue = 300;
heightValue = 300;
#endif
SizeChanged += OnPageSizeChanged;
}
private void Vm_AlertEvent(object? sender, string e) {
MainThread.BeginInvokeOnMainThread(async () => {
await DisplayAlert("Fehler:", e, "OK");
@@ -64,6 +64,8 @@ public partial class StundenPage : ContentPage {
return Preferences.Default.Get("apiKey", "") != "";
}
private async void NavigateToTargetPage() {
await Navigation.PushAsync(new LoginPage());
}