Finished Settings page
This commit is contained in:
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