51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
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();
|
|
}
|
|
|
|
}
|