89 lines
2.6 KiB
C#
89 lines
2.6 KiB
C#
using Jugenddienst_Stunden.ViewModels;
|
|
using Jugenddienst_Stunden.Models;
|
|
using CommunityToolkit.Maui.Core;
|
|
using CommunityToolkit.Maui.Alerts;
|
|
|
|
namespace Jugenddienst_Stunden.Views;
|
|
|
|
/// <summary>
|
|
/// Code-Behind für die Stunden-Übersicht
|
|
/// </summary>
|
|
public partial class StundenPage : ContentPage {
|
|
|
|
private int heightValue = 300;
|
|
|
|
/// <summary>
|
|
/// CTOR
|
|
/// </summary>
|
|
public StundenPage() {
|
|
InitializeComponent();
|
|
|
|
if (BindingContext is StundenViewModel vm) {
|
|
vm.AlertEvent += Vm_AlertEvent;
|
|
vm.InfoEvent += Vm_InfoEvent;
|
|
}
|
|
if (!CheckLogin()) {
|
|
NavigateToTargetPage();
|
|
}
|
|
#if ANDROID
|
|
heightValue = 280;
|
|
#elif IOS
|
|
heightValue = 280;
|
|
#elif WINDOWS
|
|
heightValue = 320;
|
|
#else
|
|
heightValue = 300;
|
|
#endif
|
|
|
|
SizeChanged += OnPageSizeChanged;
|
|
}
|
|
|
|
private void Vm_AlertEvent(object? sender, string e) {
|
|
MainThread.BeginInvokeOnMainThread(async () => {
|
|
await DisplayAlert("Fehler:", e, "OK");
|
|
});
|
|
}
|
|
//private void Vm_InfoEvent(object? sender, string e) {
|
|
// DisplayAlert("Information:", e, "OK");
|
|
//}
|
|
//private void Vm_InfoEvent(object? sender, string e) {
|
|
// MainThread.BeginInvokeOnMainThread(async () => {
|
|
// await DisplayAlert("Information:", e, "OK");
|
|
// });
|
|
//}
|
|
private void Vm_InfoEvent(object? sender, string e) {
|
|
MainThread.BeginInvokeOnMainThread(async () => {
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
|
ToastDuration duration = ToastDuration.Short;
|
|
double fontSize = 16;
|
|
var toast = Toast.Make(e, duration, fontSize);
|
|
await toast.Show(cts.Token);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Beim Laden der Seite den Titel setzen
|
|
/// </summary>
|
|
protected override void OnAppearing() {
|
|
base.OnAppearing();
|
|
Title = Preferences.Default.Get("name", "Nicht") + " " + Preferences.Default.Get("surname", "eingeloggt");
|
|
}
|
|
|
|
private bool CheckLogin() {
|
|
return Preferences.Default.Get("apiKey", "") != "";
|
|
}
|
|
|
|
private async void NavigateToTargetPage() {
|
|
await Navigation.PushAsync(new LoginPage());
|
|
}
|
|
|
|
private void OnPageSizeChanged(object sender, EventArgs e) {
|
|
double windowHeight = this.Height;
|
|
AdjustLayout(windowHeight);
|
|
}
|
|
|
|
private void AdjustLayout(double height) {
|
|
// Passen Sie Ihre UI-Elemente basierend auf der Fensterhöhe an
|
|
stundeItems.HeightRequest = height - heightValue; //Datepicker Height 50, Monatssummen Height 125, Titel + Navigation Height xyz
|
|
}
|
|
} |