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.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using Jugenddienst_Stunden.Types; using Jugenddienst_Stunden.Types;
using Newtonsoft.Json.Linq;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -20,11 +21,23 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
public ICommand NewEntryCommand { get; } public ICommand NewEntryCommand { get; }
public ICommand SelectEntryCommand { get; } public ICommand SelectEntryCommand { get; }
public ICommand LoadDataCommand { get; private set; } public ICommand LoadDataCommand { get; private set; }
public ICommand LoadDayCommand { get; private set; }
public ICommand RefreshListCommand { get; } public ICommand RefreshListCommand { get; }
public ICommand RefreshCommand { get; }
public event EventHandler<string> AlertEvent; public event EventHandler<string> AlertEvent;
public event EventHandler<string> InfoEvent; 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 { public string Title {
@@ -76,11 +89,12 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
dateToday = value; dateToday = value;
//GetDay = value; //GetDay = value;
//OnPropertyChanged(); //OnPropertyChanged();
_ = LoadDay(value); Task.Run(() => LoadDay(value));
} }
} }
} }
/// <summary> /// <summary>
/// Monatsübersicht: Geleistete Stunden /// Monatsübersicht: Geleistete Stunden
/// </summary> /// </summary>
@@ -137,6 +151,8 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
Task task = LoadDay(DateTime.Today); Task task = LoadDay(DateTime.Today);
RefreshCommand = new Command(async () => await RefreshItemsAsync());
} }
@@ -219,6 +235,17 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
} }
} }
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> /// <summary>
/// Refreshes all properties /// Refreshes all properties
/// </summary> /// </summary>

View File

@@ -22,7 +22,7 @@
</ContentPage.ToolbarItems> </ContentPage.ToolbarItems>
<RefreshView x:Name="MyRefreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}" Margin="10" Padding="10">
<VerticalStackLayout Spacing="10" Margin="10"> <VerticalStackLayout Spacing="10" Margin="10">
<Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*" HeightRequest="50"> <Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*" HeightRequest="50">
@@ -113,4 +113,5 @@
</VerticalStackLayout> </VerticalStackLayout>
</RefreshView>
</ContentPage> </ContentPage>