Skip to content

Commit e689a05

Browse files
CopilotYBTopaz8
andcommitted
Fix code review issues: improve efficiency and null safety
Co-authored-by: YBTopaz8 <41630728+YBTopaz8@users.noreply.github.com>
1 parent d6283e0 commit e689a05

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Dimmer/Dimmer.WinUI/Views/WinuiPages/AllSongsListPage.xaml.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,6 @@ private void SelectedSongImg_Loaded(object sender, RoutedEventArgs e)
13991399
private void ShowNotification(string message, Microsoft.UI.Xaml.Controls.InfoBarSeverity severity)
14001400
{
14011401
// Use a TeachingTip or create a temporary InfoBar for notifications
1402-
// For now, we'll use a simple ContentDialog approach or you can add an InfoBar to the XAML
14031402
DispatcherQueue.TryEnqueue(() =>
14041403
{
14051404
var infoBar = new Microsoft.UI.Xaml.Controls.InfoBar
@@ -1417,15 +1416,17 @@ private void ShowNotification(string message, Microsoft.UI.Xaml.Controls.InfoBar
14171416
infoBar.IsOpen = false;
14181417
timer.Stop();
14191418
// Remove from visual tree after closing animation
1420-
var parentPanel = infoBar.Parent as Panel;
1421-
parentPanel?.Children.Remove(infoBar);
1419+
if (infoBar.Parent is Panel parentPanel)
1420+
{
1421+
parentPanel.Children.Remove(infoBar);
1422+
}
14221423
};
14231424

1424-
// Add to the page's main grid (assuming there's a Grid named MyPageGrid)
1425-
if (MyPageGrid is Grid grid && grid.Children.Count > 0)
1425+
// Add to the page's main grid
1426+
if (MyPageGrid != null)
14261427
{
14271428
// Insert at the top of the grid
1428-
grid.Children.Insert(0, infoBar);
1429+
MyPageGrid.Children.Insert(0, infoBar);
14291430
timer.Start();
14301431
}
14311432
});

Dimmer/Dimmer/ViewModel/BaseViewModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3846,7 +3846,16 @@ public async Task PlaySongWithActionAsync(
38463846
private async Task PlaySongNextAsync(SongModelView songToPlay)
38473847
{
38483848
// Check if the song is already in the current queue
3849-
int existingIndex = _playbackQueue.ToList().FindIndex(s => s.Id == songToPlay.Id);
3849+
int existingIndex = -1;
3850+
for (int i = 0; i < _playbackQueue.Count; i++)
3851+
{
3852+
if (_playbackQueue[i].Id == songToPlay.Id)
3853+
{
3854+
existingIndex = i;
3855+
break;
3856+
}
3857+
}
3858+
38503859
if (existingIndex != -1 && _playbackQueue.Count > 0)
38513860
{
38523861
// Song is already in queue, jump to it instead of adding again

0 commit comments

Comments
 (0)