From 22283136b54a558c52fe4b78bcd0f16c3d39c767 Mon Sep 17 00:00:00 2001 From: David Seto <67933197+dtseto@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:05:58 -0700 Subject: [PATCH] Rebuild station list during async refresh --- Libs/PandoraSharp/Pandora.cs | 50 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/Libs/PandoraSharp/Pandora.cs b/Libs/PandoraSharp/Pandora.cs index 301591e..876aa7b 100644 --- a/Libs/PandoraSharp/Pandora.cs +++ b/Libs/PandoraSharp/Pandora.cs @@ -348,72 +348,70 @@ 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(); + var stationList = await CallRPC("user.getStationList", req).ConfigureAwait(false); + List refreshedStations; - // Lock all modifications to the station lists lock (_stationListLock) { - 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(); + + // Maintain behaviour expected by downstream helpers that look at the Stations property. + Stations = regularStations; switch (StationSortOrder) { case SortOrder.DateDesc: - //Stations = Stations.OrderByDescending(x => x.ID).ToList(); - Stations = Stations.OrderByDescending(x => Convert.ToInt64(x.ID)).ToList(); + regularStations = regularStations.OrderByDescending(x => Convert.ToInt64(x.ID)).ToList(); break; case SortOrder.DateAsc: - //Stations = Stations.OrderBy(x => x.ID).ToList(); - Stations = Stations.OrderBy(x => Convert.ToInt64(x.ID)).ToList(); + regularStations = regularStations.OrderBy(x => Convert.ToInt64(x.ID)).ToList(); break; case SortOrder.AlphaDesc: - Stations = Stations.OrderByDescending(x => x.Name).ToList(); + regularStations = regularStations.OrderByDescending(x => x.Name).ToList(); break; case SortOrder.AlphaAsc: - Stations = Stations.OrderBy(x => x.Name).ToList(); + regularStations = regularStations.OrderBy(x => x.Name).ToList(); break; case SortOrder.RatingAsc: GetStationMetaData(); - Stations = Stations.OrderBy(x => x.ThumbsUp).ToList(); + regularStations = regularStations.OrderBy(x => x.ThumbsUp).ToList(); break; case SortOrder.RatingDesc: GetStationMetaData(); - Stations = Stations.OrderByDescending(x => x.ThumbsUp).ToList(); + regularStations = regularStations.OrderByDescending(x => x.ThumbsUp).ToList(); break; - } - localStations.InsertRange(0, quickMixes); - // Also update the public property for other parts of your app - this.Stations = localStations; + Stations = regularStations; - } // end of lock + refreshedStations = new List(quickMixes.Count + regularStations.Count); + refreshedStations.AddRange(quickMixes); + refreshedStations.AddRange(regularStations); + + Stations = refreshedStations; + } if (StationUpdateEvent != null) StationUpdateEvent(this); - return localStations; + return refreshedStations; } //private string getSyncKey()