using Jugenddienst_Stunden.ViewModels; using Jugenddienst_Stunden.Models; using CommunityToolkit.Maui.Core; using CommunityToolkit.Maui.Alerts; namespace Jugenddienst_Stunden.Views; /// /// Code-Behind für die Stunden-Übersicht /// public partial class StundenPage : ContentPage { /// /// CTOR /// public StundenPage() { InitializeComponent(); if (BindingContext is StundenViewModel vm) { vm.AlertEvent += Vm_AlertEvent; vm.InfoEvent += Vm_InfoEvent; } if (!CheckLogin()) { NavigateToTargetPage(); } } 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); }); } /// /// Beim Laden der Seite den Titel setzen /// 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()); } }