Swipe down to refresh

This commit is contained in:
2024-10-18 16:23:11 +02:00
parent d33d5da8d9
commit 91377b583b
2 changed files with 107 additions and 79 deletions

View File

@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Jugenddienst_Stunden.Types;
using Newtonsoft.Json.Linq;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
@@ -20,13 +21,25 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
public ICommand NewEntryCommand { get; }
public ICommand SelectEntryCommand { get; }
public ICommand LoadDataCommand { get; private set; }
public ICommand LoadDayCommand { get; private set; }
public ICommand RefreshListCommand { get; }
public ICommand RefreshCommand { get; }
public event EventHandler<string> AlertEvent;
public event EventHandler<string> AlertEvent;
public event EventHandler<string> InfoEvent;
private bool isRefreshing;
public bool IsRefreshing {
get => isRefreshing;
set {
if (isRefreshing != value) {
isRefreshing = value;
OnPropertyChanged();
}
}
}
private string _title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
private string _title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
public string Title {
get => _title;
set => SetProperty(ref _title, value);
@@ -76,11 +89,12 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
dateToday = value;
//GetDay = value;
//OnPropertyChanged();
_ = LoadDay(value);
}
Task.Run(() => LoadDay(value));
}
}
}
/// <summary>
/// Monatsübersicht: Geleistete Stunden
/// </summary>
@@ -137,7 +151,9 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
Task task = LoadDay(DateTime.Today);
}
RefreshCommand = new Command(async () => await RefreshItemsAsync());
}
/// <summary>
@@ -219,10 +235,21 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
}
}
/// <summary>
/// Refreshes all properties
/// </summary>
private void RefreshProperties() {
private async Task RefreshItemsAsync() {
IsRefreshing = true;
// Fügen Sie hier die Logik zum Aktualisieren der Daten hinzu
//await Task.Delay(2000); // Simuliert eine Datenaktualisierung
await LoadDay(DateToday);
IsRefreshing = false;
}
/// <summary>
/// Refreshes all properties
/// </summary>
private void RefreshProperties() {
OnPropertyChanged(nameof(Nominal));
OnPropertyChanged(nameof(Overtime));
OnPropertyChanged(nameof(OvertimeMonth));