6 Commits

14 changed files with 267 additions and 237 deletions

View File

@@ -0,0 +1,22 @@
using System;
using System.Globalization;
using System.Linq;
using Microsoft.Maui.Controls;
namespace Jugenddienst_Stunden.Converter;
public class AnyTrueMultiConverter : IMultiValueConverter {
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
foreach (object value in values) {
if (value is bool b && b) {
return true;
}
}
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) {
throw new NotSupportedException();
}
}

View File

@@ -13,7 +13,7 @@ internal sealed class ApiClient : IApiClient {
private readonly ApiOptions _options; private readonly ApiOptions _options;
private readonly IAppSettings _settings; private readonly IAppSettings _settings;
public ApiClient(HttpClient http, ApiOptions options, ITokenProvider tokenProvider, IAppSettings settings) { public ApiClient(HttpClient http, ApiOptions options, IAppSettings settings) {
_http = http; _http = http;
_options = options; _options = options;
_settings = settings; _settings = settings;

View File

@@ -1,10 +0,0 @@
using Jugenddienst_Stunden.Interfaces;
namespace Jugenddienst_Stunden.Infrastructure;
internal sealed class SettingsTokenProvider : ITokenProvider {
private readonly IAppSettings _settings;
public SettingsTokenProvider(IAppSettings settings) => _settings = settings;
public string GetToken() => _settings.ApiKey;
}

View File

@@ -1,5 +0,0 @@
namespace Jugenddienst_Stunden.Interfaces;
internal interface ITokenProvider {
string? GetToken();
}

View File

@@ -109,8 +109,8 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat> <SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AssemblyVersion>1.0.9</AssemblyVersion> <AssemblyVersion>1.1.0</AssemblyVersion>
<FileVersion>1.0.9</FileVersion> <FileVersion>1.1.0</FileVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
@@ -181,6 +181,26 @@
<!-- <TargetFrameworks>;net9.0-android35.0</TargetFrameworks> --> <!-- <TargetFrameworks>;net9.0-android35.0</TargetFrameworks> -->
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0-android36.0|AnyCPU'">
<ApplicationDisplayVersion>1.1.0</ApplicationDisplayVersion>
<ApplicationVersion>11</ApplicationVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0-windows10.0.26100.0|AnyCPU'">
<ApplicationDisplayVersion>1.1.0</ApplicationDisplayVersion>
<ApplicationVersion>11</ApplicationVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net10.0-android36.0|AnyCPU'">
<ApplicationDisplayVersion>1.1.0</ApplicationDisplayVersion>
<ApplicationVersion>11</ApplicationVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net10.0-windows10.0.26100.0|AnyCPU'">
<ApplicationDisplayVersion>1.1.0</ApplicationDisplayVersion>
<ApplicationVersion>11</ApplicationVersion>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<!-- App Icon --> <!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

View File

@@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
using ZXing.Net.Maui.Controls; using ZXing.Net.Maui.Controls;
using System.Net.Http; using System.Net.Http;
using Jugenddienst_Stunden.ViewModels; using Jugenddienst_Stunden.ViewModels;
using Jugenddienst_Stunden.Views;
using System.Net; using System.Net;
namespace Jugenddienst_Stunden; namespace Jugenddienst_Stunden;
@@ -27,26 +28,8 @@ public static class MauiProgram {
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
}) })
//.UseBarcodeScanning();
.UseBarcodeReader(); .UseBarcodeReader();
//#if DEBUG
// if (string.IsNullOrWhiteSpace(GlobalVar.ApiKey)) {
// GlobalVar.ApiKey = Preferences.Default.Get("apiKey",
// "MTQxfHNkdFptQkNZTXlPT3ZyMHxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
// GlobalVar.Name = Preferences.Default.Get("name", "Testserver: Isabell");
// GlobalVar.Surname = Preferences.Default.Get("surname", "Biasi");
// GlobalVar.EmployeeId = Preferences.Default.Get("EmployeeId", 141);
// GlobalVar.ApiUrl = Preferences.Default.Get("apiUrl", "https://hours.dauni.mine.nu/appapi");
// }
// builder.Logging.AddDebug();
//#endif
// ApiClient registrieren: SocketsHttpHandler als Primary Handler (vermeidet AndroidMessageHandler-Castfehler)
//var apiOptions = new Infrastructure.ApiOptions { BaseUrl = GlobalVar.ApiUrl, Timeout = TimeSpan.FromSeconds(15) };
//builder.Services.AddApiHttpClient(apiOptions);
// DI: AlertService für globale Alerts (z. B. leere ApiUrl) // DI: AlertService für globale Alerts (z. B. leere ApiUrl)
builder.Services.AddSingleton<IAlertService, AlertService>(); builder.Services.AddSingleton<IAlertService, AlertService>();
@@ -59,49 +42,22 @@ public static class MauiProgram {
Timeout = TimeSpan.FromSeconds(15) Timeout = TimeSpan.FromSeconds(15)
}); });
// Token Provider soll ebenfalls aus Settings/Preferences lesen
builder.Services.AddSingleton<ITokenProvider, SettingsTokenProvider>();
// HttpClient + ApiClient // HttpClient + ApiClient Best Practices:
// Configure HttpClient with SocketsHttpHandler (managed) and RequestLoggingHandler // 1. IHttpClientFactory verwenden (vermeidet Socket Exhaustion & DNS Probleme)
// 2. Typed Client für bessere Dependency Injection (AddHttpClient<TInterface, TImplementation>)
// 3. DelegatingHandler für Logging/Infrastruktur einbinden
builder.Services.AddTransient<RequestLoggingHandler>(); builder.Services.AddTransient<RequestLoggingHandler>();
builder.Services.AddSingleton<HttpClient>(sp => {
var nativeHandler = new SocketsHttpHandler { builder.Services.AddHttpClient<IApiClient, ApiClient>()
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler {
AllowAutoRedirect = false, AllowAutoRedirect = false,
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
PooledConnectionLifetime = TimeSpan.FromMinutes(5), PooledConnectionLifetime = TimeSpan.FromMinutes(5),
ConnectTimeout = TimeSpan.FromSeconds(10) ConnectTimeout = TimeSpan.FromSeconds(10)
}; })
var logging = sp.GetRequiredService<RequestLoggingHandler>(); .AddHttpMessageHandler<RequestLoggingHandler>()
logging.InnerHandler = nativeHandler; .SetHandlerLifetime(TimeSpan.FromMinutes(5));
// HttpClient.Timeout will be adjusted by ApiClient if needed
return new HttpClient(logging, disposeHandler: true);
});
builder.Services.AddSingleton<IApiClient>(sp => {
var alert = sp.GetRequiredService<IAlertService>();
try {
return new ApiClient(
sp.GetRequiredService<HttpClient>(),
sp.GetRequiredService<ApiOptions>(),
sp.GetRequiredService<ITokenProvider>(),
sp.GetRequiredService<IAppSettings>());
} catch (Exception e) {
// Alert an UI/VM weiterreichen
alert.Raise(e.Message);
// Fallback: NullApiClient liefert beim Aufruf aussagekräftige Exception
return new NullApiClient(e.Message);
}
});
// DI: Infrastruktur
//builder.Services.AddSingleton(new ApiOptions { BaseUrl = GlobalVar.ApiUrl, Timeout = TimeSpan.FromSeconds(15) });
//builder.Services.AddSingleton<ITokenProvider, GlobalVarTokenProvider>();
//builder.Services.AddSingleton<HttpClient>(_ => new HttpClient());
//builder.Services.AddSingleton<IApiClient>(sp => new ApiClient(
// sp.GetRequiredService<HttpClient>(),
// sp.GetRequiredService<ApiOptions>(),
// sp.GetRequiredService<ITokenProvider>()));
// DI: Validatoren // DI: Validatoren
builder.Services.AddSingleton<IHoursValidator, HoursValidator>(); builder.Services.AddSingleton<IHoursValidator, HoursValidator>();
@@ -112,12 +68,12 @@ public static class MauiProgram {
builder.Services.AddSingleton<IAuthService, AuthService>(); builder.Services.AddSingleton<IAuthService, AuthService>();
// DI: Views/ViewModels // DI: Views/ViewModels
builder.Services.AddTransient<ViewModels.StundenViewModel>(); builder.Services.AddTransient<StundenViewModel>();
builder.Services.AddTransient<Views.StundenPage>(); builder.Services.AddTransient<StundenPage>();
builder.Services.AddTransient<ViewModels.StundeViewModel>(); builder.Services.AddTransient<StundeViewModel>();
builder.Services.AddTransient<Views.StundePage>(); builder.Services.AddTransient<StundePage>();
builder.Services.AddTransient<ViewModels.LoginViewModel>(); builder.Services.AddTransient<LoginViewModel>();
builder.Services.AddTransient<Views.LoginPage>(); builder.Services.AddTransient<LoginPage>();
return builder.Build(); return builder.Build();
} }

View File

@@ -11,6 +11,7 @@ namespace Jugenddienst_Stunden.ViewModels;
public partial class LoginViewModel : ObservableObject { public partial class LoginViewModel : ObservableObject {
private readonly IAuthService _auth; private readonly IAuthService _auth;
private readonly IAlertService? _alerts; private readonly IAlertService? _alerts;
private readonly IAppSettings _settings;
private DateTime _lastDetectionTime = DateTime.MinValue; private DateTime _lastDetectionTime = DateTime.MinValue;
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5); private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
@@ -38,7 +39,7 @@ public partial class LoginViewModel : ObservableObject {
private string? serverLabel; private string? serverLabel;
[ObservableProperty] [ObservableProperty]
private string title = Preferences.Default.Get("name", "Nicht") + " " + Preferences.Default.Get("surname", "eingeloggt"); private string title = "Nicht eingeloggt";
[ObservableProperty] [ObservableProperty]
private string? username; private string? username;
@@ -58,8 +59,9 @@ public partial class LoginViewModel : ObservableObject {
// Explizite Command-Property für den QR-Scanner-Event, damit das Binding in XAML zuverlässig greift // Explizite Command-Property für den QR-Scanner-Event, damit das Binding in XAML zuverlässig greift
public IAsyncRelayCommand<object?> QrDetectedCommand { get; } public IAsyncRelayCommand<object?> QrDetectedCommand { get; }
public LoginViewModel(IAuthService auth) { public LoginViewModel(IAuthService auth, IAppSettings settings) {
_auth = auth; _auth = auth;
_settings = settings;
// gespeicherte Präferenz für Logintyp laden // gespeicherte Präferenz für Logintyp laden
var lt = Preferences.Default.Get("logintype", "qr"); var lt = Preferences.Default.Get("logintype", "qr");
@@ -68,22 +70,36 @@ public partial class LoginViewModel : ObservableObject {
IsDetecting = !isManualMode; IsDetecting = !isManualMode;
// Serveranzeige vorbereiten // Serveranzeige vorbereiten
var apiUrl = Preferences.Default.Get("apiUrl", string.Empty); RefreshSettings();
if (!string.IsNullOrWhiteSpace(apiUrl)) {
Server = apiUrl.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
ServerLabel = "Server: " + Server;
}
// Command initialisieren // Command initialisieren
QrDetectedCommand = new AsyncRelayCommand<object?>(QrDetectedAsync); QrDetectedCommand = new AsyncRelayCommand<object?>(QrDetectedAsync);
} }
// DI-Konstruktor: AlertService anbinden und Alerts an VM-Event weiterreichen (analog StundeViewModel) // DI-Konstruktor: AlertService anbinden und Alerts an VM-Event weiterreichen (analog StundeViewModel)
internal LoginViewModel(IAuthService auth, IAlertService alertService) : this(auth) { internal LoginViewModel(IAuthService auth, IAlertService alertService,IAppSettings settings) : this(auth,settings) {
_alerts = alertService; _alerts = alertService;
_settings = settings;
if (alertService is not null) { if (alertService is not null) {
alertService.AlertRaised += (s, msg) => AlertEvent?.Invoke(this, msg); alertService.AlertRaised += (s, msg) => AlertEvent?.Invoke(this, msg);
} }
RefreshSettings();
}
/// <summary>
/// Aktualisiert die Serveranzeige aus den aktuellen AppSettings.
/// </summary>
public void RefreshSettings() {
var apiUrl = _settings.ApiUrl;
if (!string.IsNullOrWhiteSpace(apiUrl)) {
Server = apiUrl.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
ServerLabel = "Server: " + Server;
} else {
Server = string.Empty;
ServerLabel = "Server: Nicht konfiguriert";
}
Title = $"{_settings.Name} {_settings.Surname}";
} }
partial void OnIsManualModeChanged(bool value) { partial void OnIsManualModeChanged(bool value) {

View File

@@ -74,6 +74,7 @@ public partial class StundeViewModel : ObservableObject, IQueryAttributable {
public ICommand SaveCommand { get; private set; } public ICommand SaveCommand { get; private set; }
public ICommand DeleteCommand { get; private set; } public ICommand DeleteCommand { get; private set; }
public ICommand DeleteConfirmCommand { get; private set; } public ICommand DeleteConfirmCommand { get; private set; }
public ICommand SelectEntryCommand { get; }
//public ICommand LoadDataCommand { get; private set; } //public ICommand LoadDataCommand { get; private set; }
@@ -83,6 +84,7 @@ public partial class StundeViewModel : ObservableObject, IQueryAttributable {
_alertService = alertService; _alertService = alertService;
SaveCommand = new AsyncRelayCommand(Save); SaveCommand = new AsyncRelayCommand(Save);
DeleteConfirmCommand = new Command(async () => await DeleteConfirm()); DeleteConfirmCommand = new Command(async () => await DeleteConfirm());
SelectEntryCommand = new AsyncRelayCommand<DayTime>(SelectEntryAsync);
_alertService.AlertRaised += (s, msg) => AlertEvent?.Invoke(this, msg); _alertService.AlertRaised += (s, msg) => AlertEvent?.Invoke(this, msg);
} }
@@ -136,7 +138,8 @@ public partial class StundeViewModel : ObservableObject, IQueryAttributable {
if (!exceptionOccurred) { if (!exceptionOccurred) {
if (DayTime.Id != null) { if (DayTime.Id != null) {
await Shell.Current.GoToAsync($"..?saved={DayTime.Id}"); //await Shell.Current.GoToAsync($"..?saved={DayTime.Id}");
await Shell.Current.GoToAsync($"//StundenPage?saved={DayTime.Id}");
} else { } else {
await Shell.Current.GoToAsync($"..?date={DayTime.Day.ToString("yyyy-MM-dd")}"); await Shell.Current.GoToAsync($"..?date={DayTime.Day.ToString("yyyy-MM-dd")}");
} }
@@ -173,6 +176,19 @@ public partial class StundeViewModel : ObservableObject, IQueryAttributable {
} }
} }
/// <summary>
/// Öffnet eine bestehende Stundeneingabe
/// </summary>
private async Task SelectEntryAsync(DayTime entry) {
if (entry != null && entry.Id != null) {
//var navigationParameters = new Dictionary<string, object> { { "load", entry.id } };
//await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}", navigationParameters);
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?load={entry.Id}");
} else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
}
/// <summary> /// <summary>
/// Anwenden der Query-Parameter /// Anwenden der Query-Parameter
/// </summary> /// </summary>
@@ -233,6 +249,8 @@ public partial class StundeViewModel : ObservableObject, IQueryAttributable {
//die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht //die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht
//In dem Fall müssen die Settings aber nochmal geholt werden, weil die dann nicht geladen wurden //In dem Fall müssen die Settings aber nochmal geholt werden, weil die dann nicht geladen wurden
// LoadSettingsAsync(); // LoadSettingsAsync();
var settings = await _hoursService.GetSettingsAsync();
UpdateSettings(settings);
} finally { } finally {
DayTime = new DayTime(); DayTime = new DayTime();
DayTime.Day = _date; DayTime.Day = _date;

View File

@@ -51,13 +51,7 @@ public partial class StundenViewModel : ObservableObject, IQueryAttributable, IN
/// </summary> /// </summary>
[ObservableProperty] private List<DayTime> dayTimes = new List<DayTime>(); [ObservableProperty] private List<DayTime> dayTimes = new List<DayTime>();
/// <summary> public string Title => _settings.Name + " " + _settings.Surname;
/// Der Titel der Stundenübersicht ist der aktuelle Benutzername
/// </summary>
public string Title {
get => _settings.Name + " " + _settings.Surname;
set;
}
[ObservableProperty] private Hours hours; [ObservableProperty] private Hours hours;
@@ -178,16 +172,6 @@ public partial class StundenViewModel : ObservableObject, IQueryAttributable, IN
RefreshListCommand = new AsyncRelayCommand(RefreshList); RefreshListCommand = new AsyncRelayCommand(RefreshList);
RefreshCommand = new Command(async () => await RefreshItemsAsync()); RefreshCommand = new Command(async () => await RefreshItemsAsync());
// Task task = LoadDay(DateTime.Today);
// Beim Startup NICHT direkt im CTOR laden (kann Startup/Navigation blockieren)
// Stattdessen via Dispatcher "nach" dem Aufbau starten:
MainThread.BeginInvokeOnMainThread(async () => {
try {
await LoadDay(DateTime.Today);
} catch (Exception ex) {
AlertEvent?.Invoke(this, ex.Message);
}
});
} }
@@ -231,7 +215,6 @@ public partial class StundenViewModel : ObservableObject, IQueryAttributable, IN
" installiert)"); " installiert)");
} }
//_hour = await HoursBase.LoadData();
RefreshProperties(); RefreshProperties();
} catch (Exception e) { } catch (Exception e) {
AlertEvent?.Invoke(this, e.Message); AlertEvent?.Invoke(this, e.Message);
@@ -339,7 +322,7 @@ public partial class StundenViewModel : ObservableObject, IQueryAttributable, IN
/// <summary> /// <summary>
/// Refreshes all properties /// Refreshes all properties
/// </summary> /// </summary>
private void RefreshProperties() { public void RefreshProperties() {
OnPropertyChanged(nameof(Hours)); OnPropertyChanged(nameof(Hours));
OnPropertyChanged(nameof(Title)); OnPropertyChanged(nameof(Title));
OnPropertyChanged(nameof(Nominal)); OnPropertyChanged(nameof(Nominal));

View File

@@ -11,7 +11,7 @@ namespace Jugenddienst_Stunden.Views;
/// Die Loginseite mit dem Barcodescanner /// Die Loginseite mit dem Barcodescanner
/// </summary> /// </summary>
public partial class LoginPage : ContentPage { public partial class LoginPage : ContentPage {
/// <summary> /// <summary>
/// CTOR /// CTOR
/// </summary> /// </summary>
@@ -58,22 +58,30 @@ public partial class LoginPage : ContentPage {
}; };
} }
protected override void OnDisappearing() { protected override void OnDisappearing() {
base.OnDisappearing(); base.OnDisappearing();
barcodeScannerView.CameraLocation = CameraLocation.Front; barcodeScannerView.CameraLocation = CameraLocation.Front;
// IsDetecting wird via Binding vom ViewModel gesteuert // Scanner deaktivieren, wenn Seite verlassen wird
if (BindingContext is LoginViewModel vm) {
vm.IsDetecting = false;
}
} }
protected override void OnAppearing() { protected override void OnAppearing() {
base.OnAppearing(); base.OnAppearing();
if (BindingContext is LoginViewModel vm) {
vm.RefreshSettings();
// Scanner wieder aktivieren, wenn QR-Modus aktiv ist
vm.IsDetecting = !vm.IsManualMode;
}
// IsDetecting wird via Binding vom ViewModel gesteuert
barcodeScannerView.CameraLocation = CameraLocation.Rear; barcodeScannerView.CameraLocation = CameraLocation.Rear;
} }
} }

View File

@@ -21,64 +21,81 @@
StatusBarStyle="LightContent" /> StatusBarStyle="LightContent" />
</ContentPage.Behaviors> </ContentPage.Behaviors>
<VerticalStackLayout Spacing="10" Margin="10"> <Grid Padding="10,0,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="45"/>
<RowDefinition Height="20"/>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Text="{Binding SubTitle}" FontSize="Medium" FontAttributes="Bold" Margin="4,0,0,0" />
<Border>
<Border.Padding>
<OnPlatform x:TypeArguments="Thickness" Default="0,15,10,0">
<On Platform="Android" Value="0,4,10,8" />
<On Platform="WPF" Value="0,15,10,0" />
</OnPlatform>
</Border.Padding>
<FlexLayout Direction="Row" AlignItems="Start" Wrap="Wrap" JustifyContent="SpaceBetween"> <Label Text="{Binding SubTitle}" FontSize="Medium" FontAttributes="Bold" Margin="4,0,0,0" Grid.Row="0" />
<HorizontalStackLayout Spacing="10">
<Label Text="Beginn" VerticalTextAlignment="Center" HorizontalTextAlignment="End" <FlexLayout Direction="Row" AlignItems="Start" Wrap="Wrap" AlignContent="Start" JustifyContent="Start" Grid.Row="1" Margin="0,0,0,10" >
<Border Margin="0,0,0,10" MinimumHeightRequest="72" FlexLayout.Grow="1">
<Border.Padding>
<OnPlatform x:TypeArguments="Thickness" Default="0,15,10,0">
<On Platform="Android" Value="0,4,10,8" />
<On Platform="WPF" Value="0,15,10,0" />
</OnPlatform>
</Border.Padding>
<FlexLayout Direction="Row" AlignItems="Start" Wrap="Wrap" JustifyContent="Start" AlignContent="Start">
<HorizontalStackLayout Spacing="10">
<Label Text="Beginn" VerticalTextAlignment="Center" HorizontalTextAlignment="End"
MinimumWidthRequest="60"> MinimumWidthRequest="60">
</Label> </Label>
<TimePicker x:Name="TimeBegin" HorizontalOptions="Center" Format="HH:mm" MinimumWidthRequest="80" <TimePicker x:Name="TimeBegin" HorizontalOptions="Center" Format="HH:mm" MinimumWidthRequest="80"
Time="{Binding DayTime.TimeSpanVon}" /> Time="{Binding DayTime.TimeSpanVon}" />
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout Spacing="10">
<Label Text="Ende" VerticalTextAlignment="Center" HorizontalTextAlignment="End"
MinimumWidthRequest="60">
</Label>
<TimePicker x:Name="TimeEnd" Format="HH:mm" MinimumWidthRequest="80"
Time="{Binding DayTime.TimeSpanBis}" />
</HorizontalStackLayout>
</FlexLayout>
</Border>
<Border FlexLayout.Grow="1">
<Border.Padding>
<OnPlatform x:TypeArguments="Thickness" Default="5">
<On Platform="Android" Value="5,4,5,8" />
<On Platform="WPF" Value="5" />
</OnPlatform>
</Border.Padding>
<HorizontalStackLayout Spacing="10"> <HorizontalStackLayout Spacing="10">
<Label Text="Ende" VerticalTextAlignment="Center" HorizontalTextAlignment="End" <Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding OptionsGemeinde}"
MinimumWidthRequest="60">
</Label>
<TimePicker x:Name="TimeEnd" Format="HH:mm" MinimumWidthRequest="80"
Time="{Binding DayTime.TimeSpanBis}" />
</HorizontalStackLayout>
</FlexLayout>
</Border>
<Border>
<Border.Padding>
<OnPlatform x:TypeArguments="Thickness" Default="5">
<On Platform="Android" Value="5,4,5,8" />
<On Platform="WPF" Value="5" />
</OnPlatform>
</Border.Padding>
<HorizontalStackLayout>
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding OptionsGemeinde}"
SelectedItem="{Binding DayTime.GemeindeAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" SelectedItem="{Binding DayTime.GemeindeAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}"
IsVisible="{Binding GemeindeAktivSet}"> IsVisible="{Binding GemeindeAktivSet}">
</Picker> </Picker>
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" <Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}"
SelectedItem="{Binding DayTime.ProjektAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" SelectedItem="{Binding DayTime.ProjektAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}"
IsVisible="{Binding ProjektAktivSet}"> IsVisible="{Binding ProjektAktivSet}">
</Picker> </Picker>
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" <Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}"
SelectedItem="{Binding DayTime.FreistellungAktiv, Mode=TwoWay}" SelectedItem="{Binding DayTime.FreistellungAktiv, Mode=TwoWay}"
ItemDisplayBinding="{Binding Name}" IsEnabled="{Binding FreistellungEnabled}"> ItemDisplayBinding="{Binding Name}" IsEnabled="{Binding FreistellungEnabled}">
</Picker> </Picker>
</HorizontalStackLayout> </HorizontalStackLayout>
</Border> </Border>
</FlexLayout>
<Editor Placeholder="Beschreibung" Text="{Binding DayTime.Description}" MinimumHeightRequest="40" <Editor Placeholder="Beschreibung" Text="{Binding DayTime.Description}" MinimumHeightRequest="40"
AutoSize="TextChanges" FontSize="18" /> AutoSize="TextChanges" FontSize="18" Grid.Row="2" Margin="0,0,0,10" />
<Grid ColumnDefinitions="*,*" ColumnSpacing="4"> <Grid ColumnDefinitions="*,*" ColumnSpacing="4" Grid.Row="3">
<Button Grid.Column="1" Text="Speichern" <Button Grid.Column="1" Text="Speichern"
TextColor="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource White}}" TextColor="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource White}}"
Command="{Binding SaveCommand}" /> Command="{Binding SaveCommand}" />
@@ -91,14 +108,14 @@
</Grid> </Grid>
<BoxView HeightRequest="1" Margin="3,10" /> <BoxView HeightRequest="1" Margin="3,10" Grid.Row="4" />
<Label Text="Noch keine Einträge vorhanden" <Label Text="Noch keine Einträge vorhanden"
IsVisible="{Binding DayTimes, Converter={StaticResource CollectionVisibilityConverter}, ConverterParameter=Invert}" IsVisible="{Binding DayTimes, Converter={StaticResource CollectionVisibilityConverter}, ConverterParameter=Invert}"
Margin="6,0,0,0" /> Margin="6,0,0,0" Grid.Row="5" />
<StackLayout Margin="6,0,0,0" <StackLayout Margin="6,0,0,0"
IsVisible="{Binding DayTimes, Converter={StaticResource CollectionVisibilityConverter}}"> IsVisible="{Binding DayTimes, Converter={StaticResource CollectionVisibilityConverter}}" Grid.Row="5">
<Label> <Label>
<Label.FormattedText> <Label.FormattedText>
<FormattedString> <FormattedString>
@@ -109,48 +126,52 @@
</Label> </Label>
</StackLayout> </StackLayout>
<ScrollView IsVisible="{Binding DayTimes, Converter={StaticResource CollectionVisibilityConverter}}">
<CollectionView <CollectionView
ItemsSource="{Binding DayTimes}" ItemsSource="{Binding DayTimes}"
x:Name="stundeItems" Margin="0" x:Name="stundeItems" Margin="0"
HeightRequest="350"
SelectionMode="Single" SelectionMode="Single"
VerticalOptions="Start"
SelectionChangedCommand="{Binding SelectEntryCommand}" SelectionChangedCommand="{Binding SelectEntryCommand}"
SelectionChangedCommandParameter="{Binding Source={RelativeSource Self}, Path=SelectedItem}"> SelectionChangedCommandParameter="{Binding Source={RelativeSource Self}, Path=SelectedItem}"
IsVisible="{Binding DayTimes, Converter={StaticResource CollectionVisibilityConverter}}"
Grid.Row="6">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="0" /> <LinearItemsLayout Orientation="Vertical" ItemSpacing="0" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid Padding="5,10,5,0"> <Grid Padding="5,10,5,0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<HorizontalStackLayout Grid.Row="0" Grid.Column="0"> <HorizontalStackLayout Grid.Row="0" Grid.Column="0">
<Label Grid.Column="0" Text="{Binding Begin}" /> <Label Grid.Column="0" Text="{Binding Begin}" />
<Label Text="bis" Padding="5,0,5,0" /> <Label Text="bis" Padding="5,0,5,0" />
<Label Text="{Binding End}" /> <Label Text="{Binding End}" />
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" <Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0"
IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}" /> IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}" />
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" <Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0"
IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}" /> IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}" />
<Label Text="{Binding FreistellungAktiv.Name}" Margin="10,0,0,0" /> <Label Text="{Binding FreistellungAktiv.Name}" Margin="10,0,0,0" />
</HorizontalStackLayout> </HorizontalStackLayout>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Description}" <Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Description}"
Padding="0,0,0,15" /> Padding="0,0,0,15" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</CollectionView>
</ScrollView>
</VerticalStackLayout>
</ContentPage> </ContentPage>

View File

@@ -40,12 +40,4 @@ public partial class StundePage : ContentPage {
}); });
} }
//private async Task<bool> ShowConfirm(string title, string message, string ok, string not_ok) {
// return await DisplayAlert(title, message, ok, not_ok);
//}
//private async void ShowConfirm(object? sender, ConfirmEventArgs e) {
// bool result = await DisplayAlert(e.Title, e.Message, e.Ok, e.NotOk);
// e.Result = result;
//}
} }

View File

@@ -13,6 +13,7 @@
<ContentPage.Resources> <ContentPage.Resources>
<ResourceDictionary> <ResourceDictionary>
<conv:SecondsTimeConverter x:Key="secToTime" /> <conv:SecondsTimeConverter x:Key="secToTime" />
<conv:AnyTrueMultiConverter x:Key="AnyTrue"/>
<FontImageSource x:Key="ToolbarIcon" <FontImageSource x:Key="ToolbarIcon"
Glyph="+" Glyph="+"
Size="22" Size="22"
@@ -27,7 +28,7 @@
</ContentPage.Behaviors> </ContentPage.Behaviors>
<ContentPage.ToolbarItems> <ContentPage.ToolbarItems>
<!--<ToolbarItem Text="Lade Liste" Command="{Binding RefreshListCommand}"/>-->
<ToolbarItem Text="Neuer Eintrag" IconImageSource="{StaticResource ToolbarIcon}" <ToolbarItem Text="Neuer Eintrag" IconImageSource="{StaticResource ToolbarIcon}"
Command="{Binding NewEntryCommand}" /> Command="{Binding NewEntryCommand}" />
</ContentPage.ToolbarItems> </ContentPage.ToolbarItems>
@@ -35,7 +36,6 @@
<RefreshView x:Name="MyRefreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}" <RefreshView x:Name="MyRefreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}"
Margin="10" Padding="10"> Margin="10" Padding="10">
<Grid RowDefinitions="50,*,Auto,80"> <Grid RowDefinitions="50,*,Auto,80">
<!--<VerticalStackLayout Spacing="10" Margin="10">-->
<Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*" HeightRequest="50" Grid.Row="0"> <Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*" HeightRequest="50" Grid.Row="0">
<DatePicker Grid.Column="0" MinimumDate="{Binding MinimumDate}" <DatePicker Grid.Column="0" MinimumDate="{Binding MinimumDate}"
@@ -53,7 +53,6 @@
<CollectionView <CollectionView
ItemsSource="{Binding DayTimes}" ItemsSource="{Binding DayTimes}"
x:Name="stundeItems" Margin="0,0,0,20" x:Name="stundeItems" Margin="0,0,0,20"
SelectionMode="Single" SelectionMode="Single"
SelectionChangedCommand="{Binding SelectEntryCommand}" SelectionChangedCommand="{Binding SelectEntryCommand}"
SelectionChangedCommandParameter="{Binding Source={RelativeSource Self}, Path=SelectedItem}" SelectionChangedCommandParameter="{Binding Source={RelativeSource Self}, Path=SelectedItem}"
@@ -61,79 +60,83 @@
Grid.Row="1"> Grid.Row="1">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="0" /> <LinearItemsLayout Orientation="Vertical" ItemSpacing="10" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<VerticalStackLayout Padding="5,10,5,0"> <Border Padding="5" StrokeShape="RoundRectangle 0,30,0,30" >
<Border.Triggers>
<DataTrigger TargetType="Border" Binding="{Binding Approved}" Value="True">
<Setter Property="Background" Value="LightCoral"/>
<Setter Property="Padding" Value="4"/>
</DataTrigger>
</Border.Triggers>
<VisualStateManager.VisualStateGroups> <VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates"> <VisualStateGroup Name="CommonStates">
<VisualState Name="Normal"> <VisualState Name="Normal">
<VisualState.Setters> <VisualState.Setters>
<Setter Property="BackgroundColor" <Setter Property="BackgroundColor"
Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource TransparentColor}}" /> Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource TransparentColor}}" />
</VisualState.Setters> </VisualState.Setters>
</VisualState> </VisualState>
<VisualState Name="Selected"> <VisualState Name="Selected">
<VisualState.Setters> <VisualState.Setters>
<Setter Property="BackgroundColor" <Setter Property="BackgroundColor"
Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource PrimaryDark}}" /> Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource PrimaryDark}}" />
</VisualState.Setters> </VisualState.Setters>
</VisualState> </VisualState>
</VisualStateGroup> </VisualStateGroup>
</VisualStateManager.VisualStateGroups> </VisualStateManager.VisualStateGroups>
<Grid RowDefinitions="Auto,Auto,Auto" ColumnDefinitions="*" >
<HorizontalStackLayout> <HorizontalStackLayout Grid.Row="0" >
<HorizontalStackLayout.Triggers> <Label Text="{Binding Day, StringFormat='{0:dddd, dd. MMMM}'}" />
<DataTrigger TargetType="HorizontalStackLayout" Binding="{Binding Approved}" <Label Text="von" Padding="5,0,5,0" />
Value="True"> <Label Text="{Binding Begin}" />
<Setter Property="BackgroundColor" Value="LightCoral" /> <Label Text="bis" Padding="5,0,5,0" />
<Setter Property="Padding" Value="4" /> <Label Text="{Binding End}" />
</DataTrigger> </HorizontalStackLayout>
</HorizontalStackLayout.Triggers>
<Label Text="{Binding Day, StringFormat='{0:dddd, dd. MMMM}'}" />
<Label Text="von" Padding="5,0,5,0" />
<Label Text="{Binding Begin}" />
<Label Text="bis" Padding="5,0,5,0" />
<Label Text="{Binding End}" />
</HorizontalStackLayout>
<HorizontalStackLayout HorizontalOptions="FillAndExpand"> <HorizontalStackLayout Grid.Row="1" >
<HorizontalStackLayout.Triggers> <!--<HorizontalStackLayout.IsVisible>
<DataTrigger TargetType="HorizontalStackLayout" Binding="{Binding Approved}" <MultiBinding Converter="{StaticResource AnyTrue}">
Value="True"> <Binding Path="Approved"/>
<Setter Property="BackgroundColor" Value="LightCoral" /> <Binding Path="BindingContext.GemeindeAktivSet" Source="{RelativeSource AncestorType={x:Type ContentPage}}"/>
<Setter Property="Padding" Value="4" /> <Binding Path="BindingContext.ProjektAktivSet" Source="{RelativeSource AncestorType={x:Type ContentPage}}"/>
</DataTrigger> </MultiBinding>
</HorizontalStackLayout.Triggers> </HorizontalStackLayout.IsVisible>-->
<Label Text="{Binding GemeindeAktiv.Name}" Margin="0,0,10,0" <Label Text="{Binding GemeindeAktiv.Name}" Padding="0,0,10,0"
IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}" /> IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}" />
<Label Text="{Binding ProjektAktiv.Name}" Margin="0,0,10,0" <Label Text="{Binding ProjektAktiv.Name}" Padding="0,0,10,0"
IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}" /> IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}" />
<Label Text="{Binding FreistellungAktiv.Name}" IsVisible="{Binding Approved}" /> <Label Text="{Binding FreistellungAktiv.Name}" IsVisible="{Binding Approved}" />
</HorizontalStackLayout> </HorizontalStackLayout>
<!-- Ensure description row does not paint background -->
<Label Text="{Binding Description}" Grid.Row="2" />
</Grid>
</Border>
<Label Text="{Binding Description}" Padding="0,0,0,15" />
</VerticalStackLayout>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<!--<BoxView HeightRequest="1" Grid.Row="2" Margin="0,5,0,15" />-->
<Button Text="{Binding LoadOverview}" <Button Text="{Binding LoadOverview}"
Grid.Row="2" Grid.Row="2"
Command="{Binding LoadDataCommand}" Command="{Binding LoadDataCommand}"
TextColor="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource White}}" /> TextColor="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource White}}" />
<Border Padding="2" Grid.Row="3" Margin="0,10,0,0"> <Border Padding="2" Grid.Row="3" Margin="0,10,0,0">
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,*" ColumnDefinitions="Auto,Auto,*,Auto" Margin="10,2"> <Grid RowDefinitions="Auto,Auto,Auto" ColumnDefinitions="Auto,Auto,*" Margin="10,2">
<Label Grid.Row="0" Text="Soll:" /> <Label Grid.Row="0" Text="Soll:" />
<Label Grid.Row="1" Text="Summe:" /> <Label Grid.Row="1" Text="Summe:" />
<Label Grid.Row="2" Text="Differenz:" Margin="0,0,15,0" /> <Label Grid.Row="2" Text="Differenz:" Margin="0,0,15,0" />
<!--<BoxView Grid.Row="3" Grid.ColumnSpan="4" HeightRequest="1" Color="LightGrey" Margin="0,5"/>-->
<Label Grid.Row="0" Grid.Column="2" Text="Restüberstunden:" Margin="15,0,0,0" /> <Label Grid.Row="0" Grid.Column="2" Text="Restüberstunden:" Margin="15,0,0,0" />
<Label Grid.Row="1" Grid.Column="2" Text="Zeitausgleich:" Margin="15,0,0,0" /> <Label Grid.Row="1" Grid.Column="2" Text="Zeitausgleich:" Margin="15,0,0,0" />
<Label Grid.Row="2" Grid.Column="2" Text="Resturlaub:" Margin="15,0,0,0" /> <Label Grid.Row="2" Grid.Column="2" Text="Resturlaub:" Margin="15,0,0,0" />
@@ -156,7 +159,7 @@
</Border> </Border>
</Grid> </Grid>
<!--</VerticalStackLayout>-->
</RefreshView> </RefreshView>
</ContentPage> </ContentPage>

View File

@@ -58,6 +58,12 @@ public partial class StundenPage : ContentPage {
} catch (Exception ex) { } catch (Exception ex) {
await DisplayAlert("Fehler:", ex.Message, "OK"); await DisplayAlert("Fehler:", ex.Message, "OK");
} }
} else {
// Wenn eingeloggt, sicherstellen dass die Daten aktuell sind (besonders nach dem Login)
if (BindingContext is StundenViewModel vm) {
vm.RefreshProperties(); // Aktualisiert den Titel (Name/Vorname)
await vm.LoadDay(vm.DateToday);
}
} }
} }