From a47da65f3d687dddf5e771a3641751afc0247002 Mon Sep 17 00:00:00 2001 From: Julian Lechner Date: Fri, 27 Nov 2026 08:15:14 +0100 Subject: [PATCH] feat(schedule): add a button to stop the current item "Aktuelles Element stoppen" in the now-playing card sets the length of the item on air to the time from its start until now, so the next item starts at once. Brings back ScheduleController.EndCurrentNow and its tests; the separate start/stop button stays removed. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- .../Controllers/ScheduleController.cs | 16 ++++++++++++ .../Services/Localization/Strings.en.resx | 4 +++ .../Services/Localization/Strings.resx | 4 +++ src/Radiosender/Views/Pages/SchedulePage.xaml | 7 +++++ .../Views/Pages/SchedulePage.xaml.cs | 15 +++++++++++ .../ScheduleControllerTests.cs | 26 +++++++++++++++++++ 7 files changed, 73 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7d1e15..98dd0c0 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The interface is in German. This section names the controls as they appear on sc - **Jetzt starten** starts the plan you created. A **Jetzt** plan moves to the moment you press it, so nothing is skipped while you looked it over. It stays disabled until a plan exists. While laut.fm is switched on the button reads **Live starten** and also starts the live stream; if laut.fm cannot be reached, the music still plays and a warning says why. While on air the button turns red and reads **Sendung beenden**, which stops playback and the live stream together. 2. The timeline shows every item with start time, type (song, news, ad, moderator), title and duration. 3. The now-playing card shows the current item and its progress. Before the planned start it shows when the broadcast begins; if the plan has already begun, playback joins at the next item. - 4. **Edit the timeline**: select an upcoming row and use the buttons above the list to move it up or down, edit it, or remove it (trash icon), or drag it to a new place with the mouse: a label with type and title follows the cursor, a line shows where it lands, and the row fades in at its new place. The grip on the left of a row shows it can be dragged. **Hinzufügen** inserts a song (the one chosen under **Songwunsch**), news, an ad or moderator talk as the item after next: two places after the item on air, or at position 3 of the list when nothing is on air; for everything but songs you set title and length first. News, ad and moderator items have no title until you give them one; news and moderator items can also change their length. A double-click opens the editor too. Every item after a change follows on without a gap. The item on air can be edited too, but not moved or removed. + 4. **Edit the timeline**: select an upcoming row and use the buttons above the list to move it up or down, edit it, or remove it (trash icon), or drag it to a new place with the mouse: a label with type and title follows the cursor, a line shows where it lands, and the row fades in at its new place. The grip on the left of a row shows it can be dragged. **Hinzufügen** inserts a song (the one chosen under **Songwunsch**), news, an ad or moderator talk as the item after next: two places after the item on air, or at position 3 of the list when nothing is on air; for everything but songs you set title and length first. News, ad and moderator items have no title until you give them one; news and moderator items can also change their length. A double-click opens the editor too. Every item after a change follows on without a gap. The item on air can be edited too, but not moved or removed; **Aktuelles Element stoppen** in the now-playing card ends it at once: its length becomes the time from its start until now, and the next item starts. 5. **Speaking reminder**: 30 seconds before a news or moderator item goes on air, a dialog in the middle of the screen reminds you on any page and stays until you click **OK**. 6. **Microphone**: **Mikro ein** in the now-playing card puts the default microphone on air, also over running music; the button turns red and reads **Mikro aus**. It works with or without a broadcast and stays on while you visit other pages. 7. **Mix levels**, below the now-playing row: under **Was die Hörer hören**, **Musik** and **Mikrofon** set how loud the music and the microphone are for the listeners. Under **Was du hörst**, **Musik** sets how loud the music is on your own device; you never hear your own microphone there, because the delay is distracting. **Genau wie die Hörer** lets you hear exactly what the listeners hear, microphone included. diff --git a/src/Radiosender/Controllers/ScheduleController.cs b/src/Radiosender/Controllers/ScheduleController.cs index 5f5b8fe..15fc7d5 100644 --- a/src/Radiosender/Controllers/ScheduleController.cs +++ b/src/Radiosender/Controllers/ScheduleController.cs @@ -190,6 +190,22 @@ public class ScheduleController /// Item on air or over. public IReadOnlyList Remove(int index) => Change(index, change: items => items.RemoveAt(index)); + /// Nothing on air. + public IReadOnlyList EndCurrentNow() + { + var index = CurrentIndex; + if (CurrentItem is null) + throw new ScheduleException(Loc.T("Schedule_NothingOnAirError")); + var now = _now(); + // Whole seconds: next start not in the future. + var end = new DateTime(now.Ticks - now.Ticks % TimeSpan.TicksPerSecond, now.Kind); + return Change(index, currentAllowed: true, change: items => + { + var item = items[index]; + items[index] = item with { Duration = end > item.Start ? end - item.Start : TimeSpan.Zero }; + }); + } + /// Edit not allowed for item, or item over. public IReadOnlyList EditItem(int index, string title, TimeSpan duration) => Change(index, currentAllowed: true, change: items => { diff --git a/src/Radiosender/Services/Localization/Strings.en.resx b/src/Radiosender/Services/Localization/Strings.en.resx index 81ebca1..286cb78 100644 --- a/src/Radiosender/Services/Localization/Strings.en.resx +++ b/src/Radiosender/Services/Localization/Strings.en.resx @@ -120,6 +120,9 @@ No schedule yet. Choose the hours and create a schedule. End broadcast The broadcast could not be ended + The item could not be ended + Stop current item + Ends the current item right away; the next one starts. The schedule could not be extended: {0} Broadcast ended The whole schedule has been played. @@ -156,6 +159,7 @@ No song selected First choose a song under “Song request”. Nothing on air + Nothing is on air. Now On air now This item is on air. It can be edited or ended, but not moved or removed. diff --git a/src/Radiosender/Services/Localization/Strings.resx b/src/Radiosender/Services/Localization/Strings.resx index b9973ec..6a918a5 100644 --- a/src/Radiosender/Services/Localization/Strings.resx +++ b/src/Radiosender/Services/Localization/Strings.resx @@ -120,6 +120,9 @@ Noch kein Plan. Stunden wählen und Plan erstellen. Sendung beenden Die Sendung konnte nicht beendet werden + Das Element konnte nicht beendet werden + Aktuelles Element stoppen + Beendet das laufende Element sofort; das nächste startet. Der Plan konnte nicht verlängert werden: {0} Sendung beendet Der ganze Plan wurde gespielt. @@ -156,6 +159,7 @@ Kein Song gewählt Wähle zuerst unter „Songwunsch“ einen Song. Nichts auf Sendung + Es ist nichts auf Sendung. Jetzt Läuft gerade Dieses Element ist auf Sendung. Es kann bearbeitet oder beendet, aber nicht verschoben oder entfernt werden. diff --git a/src/Radiosender/Views/Pages/SchedulePage.xaml b/src/Radiosender/Views/Pages/SchedulePage.xaml index 2bd7026..fb3bbb2 100644 --- a/src/Radiosender/Views/Pages/SchedulePage.xaml +++ b/src/Radiosender/Views/Pages/SchedulePage.xaml @@ -134,10 +134,17 @@ + diff --git a/src/Radiosender/Views/Pages/SchedulePage.xaml.cs b/src/Radiosender/Views/Pages/SchedulePage.xaml.cs index 2f0e54f..4ec418a 100644 --- a/src/Radiosender/Views/Pages/SchedulePage.xaml.cs +++ b/src/Radiosender/Views/Pages/SchedulePage.xaml.cs @@ -311,6 +311,20 @@ public partial class SchedulePage : Page System.Windows.Automation.AutomationProperties.SetName(StartNowButton, (string)StartNowButton.Content); } + private void OnEndNow(object sender, RoutedEventArgs e) + { + try + { + _controller.EndCurrentNow(); + Message.IsOpen = false; + } + catch (ScheduleException ex) + { + ShowMessage(InfoBarSeverity.Error, Loc.T("Schedule_EndItemFailed"), ex.Message); + } + ShowCurrent(); + } + private void OnRemove(object sender, RoutedEventArgs e) => ChangeSelected(row => _controller.Remove(row.Index)); private void OnAddItem(object sender, RoutedEventArgs e) @@ -600,6 +614,7 @@ public partial class SchedulePage : Page RemoveButton.IsEnabled = Editable(index); var onAir = !_working && playing && index >= 0 && index == current; EditItemButton.IsEnabled = (Editable(index) || onAir) && row!.Item.Kind != ScheduleItemKind.Song; + EndNowButton.IsEnabled = !_working && _expectPlaying != false && _controller.CurrentItem is not null; var blocker = row switch { diff --git a/tests/Radiosender.Tests/ScheduleControllerTests.cs b/tests/Radiosender.Tests/ScheduleControllerTests.cs index 5430f0d..ff3eb80 100644 --- a/tests/Radiosender.Tests/ScheduleControllerTests.cs +++ b/tests/Radiosender.Tests/ScheduleControllerTests.cs @@ -265,6 +265,32 @@ public sealed class ScheduleControllerTests : IDisposable return (controller, started); } + [Fact] + public async Task EndCurrentNow_EndsTheItemOnAirAndStartsTheNext() + { + var (controller, started) = await OnAirWithTheFirstNewsAsync(); + _now = _now.AddMinutes(2); + + var plan = controller.EndCurrentNow(); + + Assert.Equal(TimeSpan.FromMinutes(2), plan[0].Duration); + AssertContiguousFrom(plan, plan[0].Start); + Assert.Equal(_now, plan[1].Start); + Assert.True(await started.WaitAsync(TimeSpan.FromSeconds(5))); + Assert.Equal(1, controller.CurrentIndex); + controller.Stop(); + } + + [Fact] + public void EndCurrentNow_WithNothingOnAirThrows() + { + AddSongs(); + var controller = Create(); + controller.CreatePlan(1); + + Assert.Throws(() => controller.EndCurrentNow()); + } + [Fact] public async Task EditItem_ChangesTheItemOnAirButItCannotBeRemoved() {