refactor: build services with dependency injection
App registers the services, controllers, the main window and the pages in a container, and the navigation view asks it for each page. Pages get their controllers through the constructor instead of reading statics from App. SettingsStore takes over the current settings from App. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
65743279b1
commit
c6e9bf4e82
9 files changed
+112
-35
No files matched your search
@@ -9,9 +9,13 @@ namespace Radiosender.Views.Pages;
|
||||
|
||||
public partial class LibraryPage : Page
|
||||
{
|
||||
private readonly LibraryController _controller = new(App.Songs);
|
||||
private readonly LibraryController _controller;
|
||||
|
||||
public LibraryPage() => InitializeComponent();
|
||||
public LibraryPage(LibraryController controller)
|
||||
{
|
||||
_controller = controller;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private Song? Selected => SongList.SelectedItem as Song;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Radiosender.Views.Pages;
|
||||
|
||||
public partial class SchedulePage : Page
|
||||
{
|
||||
private readonly ScheduleController _controller = App.Schedule;
|
||||
private readonly ScheduleController _controller;
|
||||
private readonly DispatcherTimer _progressTimer = new() { Interval = TimeSpan.FromMilliseconds(250) };
|
||||
private bool _loading;
|
||||
private int _scrolledTo = -1;
|
||||
@@ -29,8 +29,9 @@ public partial class SchedulePage : Page
|
||||
// Optimistic state: what the user just asked for, shown before the engine has caught up.
|
||||
private bool? _expectPlaying;
|
||||
|
||||
public SchedulePage()
|
||||
public SchedulePage(ScheduleController controller)
|
||||
{
|
||||
_controller = controller;
|
||||
InitializeComponent();
|
||||
Timeline.ItemsSource = _rows;
|
||||
// Also refreshes the buttons: Finished can arrive just before the engine reports it stopped.
|
||||
|
||||
@@ -9,10 +9,16 @@ namespace Radiosender.Views.Pages;
|
||||
/// <summary>Edits <see cref="AppSettings"/>. Nothing changes until Save.</summary>
|
||||
public partial class SettingsPage : Page
|
||||
{
|
||||
public SettingsPage() => InitializeComponent();
|
||||
private readonly SettingsStore _store;
|
||||
|
||||
public SettingsPage(SettingsStore store)
|
||||
{
|
||||
_store = store;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
// Loaded fires on every navigation to the page, so unsaved edits from an earlier visit are dropped.
|
||||
private void OnLoaded(object sender, RoutedEventArgs e) => Show(App.Settings);
|
||||
private void OnLoaded(object sender, RoutedEventArgs e) => Show(_store.Current);
|
||||
|
||||
private void Show(AppSettings settings)
|
||||
{
|
||||
@@ -54,7 +60,7 @@ public partial class SettingsPage : Page
|
||||
|
||||
try
|
||||
{
|
||||
App.SaveSettings(settings);
|
||||
_store.Save(settings);
|
||||
ShowMessage(InfoBarSeverity.Success, "Gespeichert", "Minuten pro Stunde gelten für den nächsten Plan.");
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
|
||||
Reference in new issue
Block a user