feat(settings): add the settings page and speaking reminders
The main window shows a dialog, optionally with a bing sound, shortly before a news or moderator item goes on air. The settings page sits in the footer of the navigation; the empty home page is gone and the app starts on the schedule. Pages switch off the navigation view's outer scrolling so their lists stay virtualized. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
80292ac90b
commit
54b02c3fd6
6 files changed
+279
-28
No files matched your search
@@ -17,21 +17,26 @@
|
||||
|
||||
<ui:TitleBar Grid.Row="0" Title="Radiosender" />
|
||||
|
||||
<!-- The navigation view wraps pages in its own scroll viewer, which gives a list unlimited height:
|
||||
it then creates every row at once and each update takes seconds. The pages therefore set
|
||||
ScrollViewer.CanContentScroll="False" and let their lists scroll themselves. -->
|
||||
<ui:NavigationView x:Name="RootNavigation" Grid.Row="1" IsBackButtonVisible="Collapsed">
|
||||
<ui:NavigationView.MenuItems>
|
||||
<ui:NavigationViewItem Content="Home"
|
||||
Icon="{ui:SymbolIcon Home24}"
|
||||
TargetPageType="{x:Type pages:HomePage}" />
|
||||
<ui:NavigationViewItem Content="Schedule"
|
||||
<ui:NavigationViewItem Content="Sendeplan"
|
||||
Icon="{ui:SymbolIcon CalendarLtr24}"
|
||||
TargetPageType="{x:Type pages:SchedulePage}" />
|
||||
<ui:NavigationViewItem Content="Library"
|
||||
<ui:NavigationViewItem Content="Bibliothek"
|
||||
Icon="{ui:SymbolIcon MusicNote224}"
|
||||
TargetPageType="{x:Type pages:LibraryPage}" />
|
||||
<ui:NavigationViewItem Content="Import"
|
||||
Icon="{ui:SymbolIcon ArrowDownload24}"
|
||||
TargetPageType="{x:Type pages:ImportPage}" />
|
||||
</ui:NavigationView.MenuItems>
|
||||
<ui:NavigationView.FooterMenuItems>
|
||||
<ui:NavigationViewItem Content="Einstellungen"
|
||||
Icon="{ui:SymbolIcon Settings24}"
|
||||
TargetPageType="{x:Type pages:SettingsPage}" />
|
||||
</ui:NavigationView.FooterMenuItems>
|
||||
</ui:NavigationView>
|
||||
</Grid>
|
||||
</ui:FluentWindow>
|
||||
@@ -1,3 +1,7 @@
|
||||
using System.Windows.Threading;
|
||||
using NAudio.Wave;
|
||||
using NAudio.Wave.SampleProviders;
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Views.Pages;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
@@ -5,9 +9,58 @@ namespace Radiosender.Views;
|
||||
|
||||
public partial class MainWindow : FluentWindow
|
||||
{
|
||||
private readonly DispatcherTimer _reminderTimer = new() { Interval = TimeSpan.FromSeconds(1) };
|
||||
private DateTime _remindedFor;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += (_, _) => RootNavigation.Navigate(typeof(HomePage));
|
||||
// Re-themes the app when the user switches the Windows theme while it runs.
|
||||
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this);
|
||||
Loaded += (_, _) => RootNavigation.Navigate(typeof(SchedulePage));
|
||||
_reminderTimer.Tick += (_, _) => RemindSpeaker();
|
||||
_reminderTimer.Start();
|
||||
}
|
||||
|
||||
// Shortly before news or moderator talk goes on air, the person at the microphone gets a heads-up.
|
||||
private void RemindSpeaker()
|
||||
{
|
||||
var settings = App.Settings;
|
||||
TimeSpan? newsLead = settings.NewsAlert ? TimeSpan.FromSeconds(settings.NewsAlertSeconds) : null;
|
||||
TimeSpan? moderatorLead = settings.ModeratorAlert ? TimeSpan.FromSeconds(settings.ModeratorAlertSeconds) : null;
|
||||
if (App.Schedule.UpcomingSpeech(newsLead, moderatorLead) is not { } item || item.Start == _remindedFor)
|
||||
return;
|
||||
_remindedFor = item.Start; // once per item
|
||||
var isNews = item.Kind == ScheduleItemKind.News;
|
||||
var what = item.KindName;
|
||||
if (isNews ? settings.NewsAlertSound : settings.ModeratorAlertSound)
|
||||
PlayBing();
|
||||
// A dialog in the middle of the screen that stays until OK is clicked; the broadcast keeps running behind it.
|
||||
_ = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = "Gleich bist du dran.",
|
||||
Content = item.Title.Length > 0 ? $"{what} um {item.Start:HH:mm:ss}: {item.Title}" : $"{what} um {item.Start:HH:mm:ss}",
|
||||
CloseButtonText = "OK",
|
||||
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen,
|
||||
Topmost = true,
|
||||
}.ShowDialogAsync();
|
||||
}
|
||||
|
||||
// A short generated tone on its own output, so it sounds over the running broadcast.
|
||||
private static void PlayBing()
|
||||
{
|
||||
try
|
||||
{
|
||||
var tone = new SignalGenerator(44100, 1) { Type = SignalGeneratorType.Sin, Frequency = 880, Gain = 0.25 }
|
||||
.Take(TimeSpan.FromMilliseconds(350));
|
||||
var output = new WaveOut();
|
||||
output.PlaybackStopped += (_, _) => output.Dispose();
|
||||
output.Init(tone);
|
||||
output.Play();
|
||||
}
|
||||
catch (Exception ex) when (ex is NAudio.MmException or InvalidOperationException)
|
||||
{
|
||||
// No audio device: the dialog still reminds the speaker.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<Page x:Class="Radiosender.Views.Pages.HomePage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Home">
|
||||
<StackPanel Margin="24">
|
||||
<ui:TextBlock FontTypography="Title" Text="Radiosender" />
|
||||
<ui:TextBlock Margin="0,8,0,0" TextWrapping="Wrap"
|
||||
Text="Add music on the Import page, then plan and start a broadcast on the Schedule page." />
|
||||
</StackPanel>
|
||||
</Page>
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Radiosender.Views.Pages;
|
||||
|
||||
public partial class HomePage : Page
|
||||
{
|
||||
public HomePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<Page x:Class="Radiosender.Views.Pages.SettingsPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Einstellungen"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
Loaded="OnLoaded">
|
||||
<Page.Resources>
|
||||
<Style x:Key="Card" TargetType="Border">
|
||||
<Setter Property="Margin" Value="0,0,0,12" />
|
||||
<Setter Property="Padding" Value="16" />
|
||||
<Setter Property="CornerRadius" Value="8" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource CardBackgroundFillColorDefaultBrush}" />
|
||||
</Style>
|
||||
<Style x:Key="Seconds" TargetType="ui:NumberBox" BasedOn="{StaticResource {x:Type ui:NumberBox}}">
|
||||
<Setter Property="Width" Value="130" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="Minimum" Value="5" />
|
||||
<Setter Property="Maximum" Value="300" />
|
||||
<Setter Property="SmallChange" Value="5" />
|
||||
<Setter Property="MaxDecimalPlaces" Value="0" />
|
||||
<Setter Property="ClearButtonEnabled" Value="False" />
|
||||
</Style>
|
||||
<Style x:Key="Minutes" TargetType="ui:NumberBox" BasedOn="{StaticResource {x:Type ui:NumberBox}}">
|
||||
<Setter Property="Width" Value="130" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="Minimum" Value="0" />
|
||||
<Setter Property="Maximum" Value="60" />
|
||||
<Setter Property="SmallChange" Value="1" />
|
||||
<Setter Property="MaxDecimalPlaces" Value="0" />
|
||||
<Setter Property="ClearButtonEnabled" Value="False" />
|
||||
</Style>
|
||||
</Page.Resources>
|
||||
|
||||
<StackPanel MaxWidth="640" Margin="24" HorizontalAlignment="Left">
|
||||
<ui:InfoBar x:Name="Message" Margin="0,0,0,12" IsClosable="True" IsOpen="False" />
|
||||
|
||||
<!-- Speaking alerts: one block per kind -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:ToggleSwitch x:Name="NewsAlertSwitch" Grid.ColumnSpan="2" Content="Hinweis vor Nachrichten" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sekunden vor dem Start"
|
||||
Target="{Binding ElementName=NewsSecondsBox}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
<ui:NumberBox x:Name="NewsSecondsBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Seconds}"
|
||||
AutomationProperties.Name="Sekunden vor Nachrichten"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
<CheckBox x:Name="NewsSoundBox" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,8,0,0"
|
||||
Content="Bing-Ton abspielen"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border Style="{StaticResource Card}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:ToggleSwitch x:Name="ModeratorAlertSwitch" Grid.ColumnSpan="2" Content="Hinweis vor Moderation" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sekunden vor dem Start"
|
||||
Target="{Binding ElementName=ModeratorSecondsBox}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
<ui:NumberBox x:Name="ModeratorSecondsBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Seconds}"
|
||||
AutomationProperties.Name="Sekunden vor Moderation"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
<CheckBox x:Name="ModeratorSoundBox" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,8,0,0"
|
||||
Content="Bing-Ton abspielen"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- Minutes per hour -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Minuten pro Stunde" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Nachrichten" Target="{Binding ElementName=NewsMinutesBox}" />
|
||||
<ui:NumberBox x:Name="NewsMinutesBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Minutes}" Minimum="2"
|
||||
AutomationProperties.Name="Nachrichten-Minuten pro Stunde" />
|
||||
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Moderation" Target="{Binding ElementName=ModeratorMinutesBox}" />
|
||||
<ui:NumberBox x:Name="ModeratorMinutesBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
|
||||
Style="{StaticResource Minutes}"
|
||||
AutomationProperties.Name="Moderations-Minuten pro Stunde" />
|
||||
<Label Grid.Row="3" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Werbung" Target="{Binding ElementName=AdMinutesBox}" />
|
||||
<ui:NumberBox x:Name="AdMinutesBox" Grid.Row="3" Grid.Column="1" Margin="0,8,0,0"
|
||||
Style="{StaticResource Minutes}"
|
||||
AutomationProperties.Name="Werbe-Minuten pro Stunde" />
|
||||
<ui:TextBlock Grid.Row="4" Grid.ColumnSpan="2" Margin="0,12,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Sollwerte, zusammen höchstens 60 Minuten. Gilt für den nächsten Plan." />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<StackPanel Margin="0,4,0,0" Orientation="Horizontal">
|
||||
<ui:Button Appearance="Primary" MinWidth="110" Content="Speichern" Icon="{ui:SymbolIcon Save24}" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" MinWidth="110" Content="Zurücksetzen" Icon="{ui:SymbolIcon ArrowReset24}"
|
||||
ToolTip="Setzt die Standardwerte ins Formular. Mit Speichern übernehmen."
|
||||
Click="OnReset" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Page>
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Radiosender.Services;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
namespace Radiosender.Views.Pages;
|
||||
|
||||
/// <summary>Edits <see cref="AppSettings"/>. Nothing changes until Save.</summary>
|
||||
public partial class SettingsPage : Page
|
||||
{
|
||||
public SettingsPage() => 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 Show(AppSettings settings)
|
||||
{
|
||||
NewsAlertSwitch.IsChecked = settings.NewsAlert;
|
||||
NewsSecondsBox.Value = settings.NewsAlertSeconds;
|
||||
NewsSoundBox.IsChecked = settings.NewsAlertSound;
|
||||
ModeratorAlertSwitch.IsChecked = settings.ModeratorAlert;
|
||||
ModeratorSecondsBox.Value = settings.ModeratorAlertSeconds;
|
||||
ModeratorSoundBox.IsChecked = settings.ModeratorAlertSound;
|
||||
NewsMinutesBox.Value = settings.NewsMinutesPerHour;
|
||||
ModeratorMinutesBox.Value = settings.ModeratorMinutesPerHour;
|
||||
AdMinutesBox.Value = settings.AdMinutesPerHour;
|
||||
}
|
||||
|
||||
// An emptied number box counts as its default.
|
||||
private static AppSettings Defaults { get; } = new();
|
||||
|
||||
private AppSettings Read() => new()
|
||||
{
|
||||
NewsAlert = NewsAlertSwitch.IsChecked == true,
|
||||
NewsAlertSeconds = (int)(NewsSecondsBox.Value ?? Defaults.NewsAlertSeconds),
|
||||
NewsAlertSound = NewsSoundBox.IsChecked == true,
|
||||
ModeratorAlert = ModeratorAlertSwitch.IsChecked == true,
|
||||
ModeratorAlertSeconds = (int)(ModeratorSecondsBox.Value ?? Defaults.ModeratorAlertSeconds),
|
||||
ModeratorAlertSound = ModeratorSoundBox.IsChecked == true,
|
||||
NewsMinutesPerHour = (int)(NewsMinutesBox.Value ?? Defaults.NewsMinutesPerHour),
|
||||
ModeratorMinutesPerHour = (int)(ModeratorMinutesBox.Value ?? Defaults.ModeratorMinutesPerHour),
|
||||
AdMinutesPerHour = (int)(AdMinutesBox.Value ?? Defaults.AdMinutesPerHour),
|
||||
};
|
||||
|
||||
private void OnSave(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var settings = Read();
|
||||
if (settings.Validate() is { } problem)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", problem);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
App.SaveSettings(settings);
|
||||
ShowMessage(InfoBarSeverity.Success, "Gespeichert", "Minuten pro Stunde gelten für den nächsten Plan.");
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReset(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Show(Defaults);
|
||||
ShowMessage(InfoBarSeverity.Informational, "Standardwerte eingesetzt", "Mit Speichern übernehmen.");
|
||||
}
|
||||
|
||||
private void ShowMessage(InfoBarSeverity severity, string title, string text)
|
||||
{
|
||||
Message.Severity = severity;
|
||||
Message.Title = title;
|
||||
Message.Message = text;
|
||||
Message.IsOpen = true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user