Finished Settings page
This commit is contained in:
9
WorkTime.Mobile/Pages/AnalysisPage.xaml
Normal file
9
WorkTime.Mobile/Pages/AnalysisPage.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="WorkTime.Mobile.Pages.AnalysisPage">
|
||||
<ContentPage.Content>
|
||||
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
13
WorkTime.Mobile/Pages/AnalysisPage.xaml.cs
Normal file
13
WorkTime.Mobile/Pages/AnalysisPage.xaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WorkTime.Mobile.Pages;
|
||||
|
||||
public partial class AnalysisPage : ContentPage {
|
||||
public AnalysisPage() {
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
9
WorkTime.Mobile/Pages/CapturePage.xaml
Normal file
9
WorkTime.Mobile/Pages/CapturePage.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="WorkTime.Mobile.Pages.CapturePage">
|
||||
<ContentPage.Content>
|
||||
<Label Text="Hello from Capture Page" />
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
13
WorkTime.Mobile/Pages/CapturePage.xaml.cs
Normal file
13
WorkTime.Mobile/Pages/CapturePage.xaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WorkTime.Mobile.Pages;
|
||||
|
||||
public partial class CapturePage : ContentPage {
|
||||
public CapturePage() {
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
24
WorkTime.Mobile/Pages/Components/SettingComponent.xaml
Normal file
24
WorkTime.Mobile/Pages/Components/SettingComponent.xaml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:components="clr-namespace:WorkTime.Mobile.Pages.Components"
|
||||
x:Class="WorkTime.Mobile.Pages.Components.SettingComponent"
|
||||
x:DataType="components:SettingComponent"
|
||||
x:Name="Component">
|
||||
<Grid ColumnDefinitions="*,Auto,80" ColumnSpacing="5">
|
||||
<Label Text="{Binding Title, Source={x:Reference Component}}"
|
||||
VerticalTextAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
|
||||
<Entry Placeholder="{Binding Placeholder, Source={x:Reference Component}}"
|
||||
Keyboard="Numeric"
|
||||
Grid.Column="1"
|
||||
TextChanged="OnValueChanged"
|
||||
x:Name="EntryField"/>
|
||||
|
||||
<Label Text="{Binding Unit, Source={x:Reference Component}}"
|
||||
VerticalTextAlignment="Center"
|
||||
Grid.Column="2"/>
|
||||
</Grid>
|
||||
</ContentView>
|
||||
59
WorkTime.Mobile/Pages/Components/SettingComponent.xaml.cs
Normal file
59
WorkTime.Mobile/Pages/Components/SettingComponent.xaml.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace WorkTime.Mobile.Pages.Components;
|
||||
|
||||
public partial class SettingComponent : ContentView {
|
||||
public static readonly BindableProperty TitleProperty =
|
||||
BindableProperty.Create(nameof(Title), typeof(string), typeof(SettingComponent), string.Empty);
|
||||
|
||||
public static readonly BindableProperty UnitProperty =
|
||||
BindableProperty.Create(nameof(Unit), typeof(string), typeof(SettingComponent), string.Empty);
|
||||
|
||||
public static readonly BindableProperty PlaceholderProperty =
|
||||
BindableProperty.Create(nameof(Placeholder), typeof(string), typeof(SettingComponent), string.Empty);
|
||||
|
||||
public static readonly BindableProperty ValueProperty =
|
||||
BindableProperty.Create(nameof(Value), typeof(TimeSpan), typeof(SettingComponent), TimeSpan.Zero,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
public string Title {
|
||||
get => (string)GetValue(TitleProperty);
|
||||
set => SetValue(TitleProperty, value);
|
||||
}
|
||||
|
||||
public string Unit {
|
||||
get => (string)GetValue(UnitProperty);
|
||||
set => SetValue(UnitProperty, value);
|
||||
}
|
||||
|
||||
public string Placeholder {
|
||||
get => (string)GetValue(PlaceholderProperty);
|
||||
set => SetValue(PlaceholderProperty, value);
|
||||
}
|
||||
|
||||
public TimeSpan Value {
|
||||
get => (TimeSpan)GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
public SettingComponent() {
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnValueChanged(object? sender, TextChangedEventArgs e) {
|
||||
if (!int.TryParse(e.NewTextValue, out var number)) return;
|
||||
|
||||
switch (Unit) {
|
||||
case "Stunden":
|
||||
case "Uhr":
|
||||
Value = TimeSpan.FromHours(number);
|
||||
break;
|
||||
|
||||
case "Minuten":
|
||||
Value = TimeSpan.FromMinutes(number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearInput() {
|
||||
Content.FindByName<Entry>(nameof(EntryField)).Text = string.Empty;
|
||||
}
|
||||
}
|
||||
97
WorkTime.Mobile/Pages/SettingsPage.xaml
Normal file
97
WorkTime.Mobile/Pages/SettingsPage.xaml
Normal file
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:components="clr-namespace:WorkTime.Mobile.Pages.Components"
|
||||
xmlns:pages="clr-namespace:WorkTime.Mobile.Pages"
|
||||
xmlns:icons="http://www.aathifmahir.com/dotnet/2022/maui/icons"
|
||||
x:Class="WorkTime.Mobile.Pages.SettingsPage"
|
||||
x:DataType="pages:SettingsPageModel">
|
||||
|
||||
<ContentPage.Content>
|
||||
<Grid Margin="20,10" RowDefinitions="*,Auto">
|
||||
<VerticalStackLayout Grid.Row="0" x:Name="SettingsStack">
|
||||
<HorizontalStackLayout Margin="0, 0, 0, 5" Spacing="15">
|
||||
<icons:MauiIcon Icon="{icons:Material Work}"
|
||||
IconSize="30"
|
||||
IconColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
|
||||
|
||||
<Label Text="Zeiten"
|
||||
FontSize="20"
|
||||
HorizontalTextAlignment="Center"/>
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<components:SettingComponent
|
||||
Title="Arbeitszeit"
|
||||
Unit="Stunden"
|
||||
Placeholder="{Binding Settings.WorkTime.TotalHours}"
|
||||
Value="{Binding Settings.WorkTime, Mode=OneWayToSource}"/>
|
||||
|
||||
|
||||
|
||||
<HorizontalStackLayout Margin="0, 10, 0, 5" Spacing="15">
|
||||
<icons:MauiIcon Icon="{icons:Material LocalPizza}"
|
||||
IconSize="30"
|
||||
IconColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
|
||||
|
||||
<Label Text="Pause"
|
||||
FontSize="20"
|
||||
HorizontalTextAlignment="Center"/>
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<components:SettingComponent
|
||||
Title="Nach 0 Stunden"
|
||||
Unit="Minuten"
|
||||
Placeholder="{Binding Settings.BreakAfter0.TotalMinutes}"
|
||||
Value="{Binding Settings.BreakAfter0, Mode=OneWayToSource}"/>
|
||||
|
||||
<components:SettingComponent
|
||||
Title="Nach 6 Stunden"
|
||||
Unit="Minuten"
|
||||
Placeholder="{Binding Settings.BreakAfter6.TotalMinutes}"
|
||||
Value="{Binding Settings.BreakAfter6, Mode=OneWayToSource}"/>
|
||||
|
||||
<components:SettingComponent
|
||||
Title="Nach 9 Stunden"
|
||||
Unit="Minuten"
|
||||
Placeholder="{Binding Settings.BreakAfter9.TotalMinutes}"
|
||||
Value="{Binding Settings.BreakAfter9, Mode=OneWayToSource}"/>
|
||||
|
||||
<components:SettingComponent
|
||||
Title="Nicht tracken nach"
|
||||
Unit="Uhr"
|
||||
Placeholder="{Binding Settings.DontTrackBreakAfter.TotalHours}"
|
||||
Value="{Binding Settings.DontTrackBreakAfter, Mode=OneWayToSource}"/>
|
||||
|
||||
|
||||
|
||||
<HorizontalStackLayout Margin="0, 10, 0, 5" Spacing="15">
|
||||
<icons:MauiIcon Icon="{icons:Material CreditCard}"
|
||||
IconSize="30"
|
||||
IconColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
|
||||
|
||||
<Label Text="Überstunden"
|
||||
FontSize="20"
|
||||
HorizontalTextAlignment="Center"/>
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<components:SettingComponent
|
||||
Title="Optimal"
|
||||
Unit="Minuten"
|
||||
Placeholder="{Binding Settings.IdealOvertime.TotalMinutes}"
|
||||
Value="{Binding Settings.IdealOvertime, Mode=OneWayToSource}"/>
|
||||
|
||||
<components:SettingComponent
|
||||
Title="Maximal"
|
||||
Unit="Minuten"
|
||||
Placeholder="{Binding Settings.MaxOvertime.TotalMinutes}"
|
||||
Value="{Binding Settings.MaxOvertime, Mode=OneWayToSource}"/>
|
||||
</VerticalStackLayout>
|
||||
|
||||
<Button Grid.Row="1"
|
||||
Text="Speichern"
|
||||
HorizontalOptions="Center"
|
||||
Command="{Binding SaveSettingsCommand}"/>
|
||||
</Grid>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
50
WorkTime.Mobile/Pages/SettingsPage.xaml.cs
Normal file
50
WorkTime.Mobile/Pages/SettingsPage.xaml.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using CommunityToolkit.Maui.Alerts;
|
||||
using CommunityToolkit.Maui.Core;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using WorkTime.Mobile.Pages.Components;
|
||||
using WorkTime.Models;
|
||||
using WorkTime.Models.Repositories;
|
||||
|
||||
namespace WorkTime.Mobile.Pages;
|
||||
|
||||
public partial class SettingsPage : ContentPage {
|
||||
private readonly SettingsPageModel _model;
|
||||
|
||||
public SettingsPage(SettingsPageModel model) {
|
||||
InitializeComponent();
|
||||
BindingContext = model;
|
||||
_model = model;
|
||||
}
|
||||
|
||||
protected override void OnAppearing() {
|
||||
base.OnAppearing();
|
||||
|
||||
if (_model.LoadSettingsCommand.CanExecute(null))
|
||||
_model.LoadSettingsCommand.Execute(null);
|
||||
|
||||
foreach (var child in Content.FindByName<VerticalStackLayout>(nameof(SettingsStack)).Children) {
|
||||
if (child is SettingComponent component)
|
||||
component.ClearInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SettingsPageModel(ISettingsRepository settingsRepository) : ObservableObject {
|
||||
|
||||
[ObservableProperty]
|
||||
public partial Settings Settings { get; set; }
|
||||
|
||||
[RelayCommand]
|
||||
public async Task LoadSettings() {
|
||||
Settings = await settingsRepository.LoadSettings();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task SaveSettings() {
|
||||
await settingsRepository.SaveSettings(Settings);
|
||||
|
||||
await Toast.Make("Einstellungen gespeichert!").Show();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user