From f20ed535bbfab78284aa988418b25b0eb2fc2084 Mon Sep 17 00:00:00 2001 From: David Seto <67933197+dtseto@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:05:34 -0700 Subject: [PATCH] Rebuild station list from fetched data --- Libs/PandoraSharp/Pandora.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Libs/PandoraSharp/Pandora.cs b/Libs/PandoraSharp/Pandora.cs index 301591e..cccc5c7 100644 --- a/Libs/PandoraSharp/Pandora.cs +++ b/Libs/PandoraSharp/Pandora.cs @@ -349,8 +349,7 @@ public async Task> RefreshStationsAsync() JObject req = new JObject(); req["includeStationArtUrl"] = true; var stationList = await CallRPC("user.getStationList", req); - // Use this local variable throughout the method. - List localStations = new List(); + List combinedStations; // Lock all modifications to the station lists lock (_stationListLock) @@ -358,26 +357,28 @@ public async Task> RefreshStationsAsync() QuickMixStationIDs.Clear(); - Stations = new List(); + var fetchedStations = new List(); var stations = stationList.Result["stations"]; foreach (JToken d in stations) { - Stations.Add(new Station(this, d)); + fetchedStations.Add(new Station(this, d)); } //foreach (PDict s in stationList) // Stations.Add(new Station(this, s)); if (QuickMixStationIDs.Count > 0) { - foreach (Station s in Stations) + foreach (Station s in fetchedStations) { if (QuickMixStationIDs.Contains(s.ID)) s.UseQuickMix = true; } } - List quickMixes = Stations.FindAll(x => x.IsQuickMix); - Stations = Stations.FindAll(x => !x.IsQuickMix); + var quickMixes = fetchedStations.Where(x => x.IsQuickMix).ToList(); + var regularStations = fetchedStations.Where(x => !x.IsQuickMix).ToList(); + + Stations = regularStations; switch (StationSortOrder) { @@ -406,14 +407,17 @@ public async Task> RefreshStationsAsync() } - localStations.InsertRange(0, quickMixes); + var sortedStations = Stations; + combinedStations = new List(quickMixes.Count + sortedStations.Count); + combinedStations.AddRange(quickMixes); + combinedStations.AddRange(sortedStations); // Also update the public property for other parts of your app - this.Stations = localStations; + this.Stations = combinedStations; } // end of lock if (StationUpdateEvent != null) StationUpdateEvent(this); - return localStations; + return combinedStations; } //private string getSyncKey()