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));

View File

@@ -19,22 +19,22 @@
<ContentPage.ToolbarItems>
<!--<ToolbarItem Text="Lade Liste" Command="{Binding RefreshListCommand}"/>-->
<ToolbarItem Text="Neuer Eintrag" IconImageSource="{StaticResource ToolbarIcon}" Command="{Binding NewEntryCommand}" />
</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">
<DatePicker Grid.Column="0" MinimumDate="{Binding MinimumDate}"
<Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*" HeightRequest="50">
<DatePicker Grid.Column="0" MinimumDate="{Binding MinimumDate}"
MaximumDate="{Binding MaximumDate}"
Date="{Binding DateToday}" Format="dddd, d. MMMM yyyy" />
<Border Grid.Column="1" Margin="15,0,0,0" Padding="15,0,0,0" ToolTipProperties.Text="Tagessumme">
<Label Text="{Binding DayTotal,StringFormat='{}{0:HH:mm}'}" VerticalOptions="Center"></Label>
</Border>
</Grid>
<CollectionView
<Border Grid.Column="1" Margin="15,0,0,0" Padding="15,0,0,0" ToolTipProperties.Text="Tagessumme">
<Label Text="{Binding DayTotal,StringFormat='{}{0:HH:mm}'}" VerticalOptions="Center"></Label>
</Border>
</Grid>
<CollectionView
ItemsSource="{Binding DayTimes}"
x:Name="stundeItems" Margin="0"
HeightRequest="300"
@@ -42,75 +42,76 @@
SelectionChangedCommand="{Binding SelectEntryCommand}"
SelectionChangedCommandParameter="{Binding Source={RelativeSource Self}, Path=SelectedItem}">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="0" />
</CollectionView.ItemsLayout>
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="0" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="5,10,5,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource TransparentColor}}" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource PrimaryDark}}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="5,10,5,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource TransparentColor}}" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource PrimaryDark}}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<HorizontalStackLayout Grid.Row="0" HorizontalOptions="FillAndExpand">
<Label Grid.Column="0" Text="{Binding begin}" />
<Label Text="bis" Padding="5,0,5,0" />
<Label Text="{Binding end}" />
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" />
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" />
<Label Text="{Binding FreistellungAktiv.Id}" Margin="10,0,0,0" />
</HorizontalStackLayout>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</Grid.ColumnDefinitions>
<HorizontalStackLayout Grid.Row="0" HorizontalOptions="FillAndExpand">
<Label Grid.Column="0" Text="{Binding begin}" />
<Label Text="bis" Padding="5,0,5,0" />
<Label Text="{Binding end}" />
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" />
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" />
<Label Text="{Binding FreistellungAktiv.Id}" Margin="10,0,0,0" />
</HorizontalStackLayout>
</CollectionView>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<BoxView HeightRequest="1" />
<Button Text="{Binding LoadOverview}" Command="{Binding LoadDataCommand}" />
<Frame Padding="2" HeightRequest="125">
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,*" ColumnDefinitions="Auto,*" Margin="10,2">
<Label Grid.Row="0" Text="Soll:" />
<Label Grid.Row="1" Text="Summe:" />
<Label Grid.Row="2" Text="Differenz:" Margin="0,0,15,0" />
<BoxView Grid.Row="3" Grid.ColumnSpan="2" HeightRequest="1" Color="LightGrey" Margin="0,5"/>
<Label Grid.Row="4" Text="Restüberstunden:" />
<Label Grid.Row="5" Text="Resturlaub:" />
<Button Text="{Binding LoadOverview}" Command="{Binding LoadDataCommand}" />
<Frame Padding="2" HeightRequest="125">
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,*" ColumnDefinitions="Auto,*" Margin="10,2">
<Label Grid.Row="0" Text="Soll:" />
<Label Grid.Row="1" Text="Summe:" />
<Label Grid.Row="2" Text="Differenz:" Margin="0,0,15,0" />
<BoxView Grid.Row="3" Grid.ColumnSpan="2" HeightRequest="1" Color="LightGrey" Margin="0,5"/>
<Label Grid.Row="4" Text="Restüberstunden:" />
<Label Grid.Row="5" Text="Resturlaub:" />
<Label Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Nominal}" ToolTipProperties.Text="Sollstunden" />
<Label Grid.Row="1" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitCalculated}" ToolTipProperties.Text="Geleistete Stunden" />
<Label Grid.Row="2" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding OvertimeMonth}" />
<Label Grid.Row="4" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Overtime}" />
<Label Grid.Row="5" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Holiday}" />
</Grid>
</Frame>
<Label Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Nominal}" ToolTipProperties.Text="Sollstunden" />
<Label Grid.Row="1" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitCalculated}" ToolTipProperties.Text="Geleistete Stunden" />
<Label Grid.Row="2" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding OvertimeMonth}" />
<Label Grid.Row="4" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Overtime}" />
<Label Grid.Row="5" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Holiday}" />
</Grid>
</Frame>
</VerticalStackLayout>
</RefreshView>
</ContentPage>