Skip to content

Commit 3954b13

Browse files
committed
Refactor queue UI: only "Insert After", update logic
- Remove/comment out "Play Next" and "Insert Before" buttons from song expand row. - Only show "Insert After" button in queue mode, with updated icon and tooltip. - Refactor SongViewHolder to use _currentSongContext for all song references. - Update "Insert After" handler to pass only the current song to InsertSongsAfterInQueue. - Refactor InsertSongsAfterInQueue to accept only a list of songs and use the current playing song as the insertion point. - Remove all tuple-based queue insertion logic for clarity and consistency. - Ensure all event handlers use _currentSongContext for state management.
1 parent f11c25e commit 3954b13

File tree

2 files changed

+42
-66
lines changed

2 files changed

+42
-66
lines changed

Dimmer/Dimmer.Droid/ViewsAndPages/NativeViews/SongAdapter.cs

Lines changed: 38 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int
285285
expandRow.LayoutParameters = new LinearLayout.LayoutParams(-1, -2);
286286
expandRow.SetPadding(0, 0, 0, 20);
287287

288-
var playBtn = CreateActionButton("Play Next", Resource.Drawable.exo_icon_play);
289-
expandRow.AddView(playBtn);
288+
//var playBtn = CreateActionButton("Play Next", Resource.Drawable.exo_icon_play);
289+
//expandRow.AddView(playBtn);
290290

291291
var favBtn = CreateActionButton("Fav", Resource.Drawable.heart);
292292
expandRow.AddView(favBtn);
@@ -302,9 +302,9 @@ public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int
302302
MaterialButton? insertAfterBtn = null;
303303
if (_mode == "queue")
304304
{
305-
insertBeforeBtn = CreateActionButton("Insert Before", Resource.Drawable.mtrl_dropdown_arrow);
306-
insertAfterBtn = CreateActionButton("Insert After", Resource.Drawable.mtrl_ic_arrow_drop_up);
307-
expandRow.AddView(insertBeforeBtn);
305+
insertAfterBtn = CreateActionButton(string.Empty, Resource.Drawable.media3_icon_queue_next);
306+
insertAfterBtn.TooltipText = "Insert Song After This";
307+
//expandRow.AddView(insertBeforeBtn);
308308
expandRow.AddView(insertAfterBtn);
309309
}
310310

@@ -357,7 +357,7 @@ class SongViewHolder : AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder
357357
private readonly Button lyricsBtn;
358358
private readonly Button? _insertBeforeBtn;
359359
private readonly Button? _insertAfterBtn;
360-
private SongModelView? _currentSong;
360+
private SongModelView? _currentSongContext;
361361
private Action<int>? _expandAction;
362362

363363
public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView container, ImageView img, TextView title, TextView artist, MaterialButton moreBtn, TextView durationView,
@@ -388,95 +388,71 @@ public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView
388388

389389
lyrBtn.Click += (s, e) =>
390390
{
391-
_viewModel._lyricsMgtFlow.LoadLyrics(_currentSong?.SyncLyrics);
392-
_viewModel.SelectedSong = _currentSong;
391+
_viewModel._lyricsMgtFlow.LoadLyrics(_currentSongContext?.SyncLyrics);
392+
_viewModel.SelectedSong = _currentSongContext;
393393
_viewModel.NavigateToAnyPageOfGivenType(this._parentFrag, new LyricsViewFragment(_viewModel), "toLyricsFromNP");
394394

395395
};
396396

397-
// Handle insert before/after for queue mode
398-
if (_insertBeforeBtn != null)
399-
{
400-
_insertBeforeBtn.Click += (s, e) =>
401-
{
402-
if (_currentSong != null)
403-
{
404-
// TODO: Implement proper song picker dialog
405-
// For now, use search results as songs to insert
406-
// This is a placeholder implementation for demonstration purposes
407-
var songsToInsert = _viewModel.SearchResults.Take(3).ToList();
408-
if (songsToInsert.Any())
409-
{
410-
var param = new Tuple<SongModelView, IEnumerable<SongModelView>>(_currentSong, songsToInsert);
411-
_viewModel.InsertSongsBeforeInQueueCommand.Execute(param);
412-
Toast.MakeText(_parentFrag.Context, $"Inserted {songsToInsert.Count} songs before", ToastLength.Short)?.Show();
413-
}
414-
}
415-
};
416-
}
397+
417398

418399
if (_insertAfterBtn != null)
419400
{
420401
_insertAfterBtn.Click += (s, e) =>
421402
{
422-
if (_currentSong != null)
403+
if (_currentSongContext != null)
423404
{
424-
// TODO: Implement proper song picker dialog
425-
// For now, use search results as songs to insert
426-
// This is a placeholder implementation for demonstration purposes
427-
var songsToInsert = _viewModel.SearchResults.Take(3).ToList();
428-
if (songsToInsert.Any())
429-
{
430-
var param = new Tuple<SongModelView, IEnumerable<SongModelView>>(_currentSong, songsToInsert);
405+
406+
var param = new List<SongModelView>() { _currentSongContext };
431407
_viewModel.InsertSongsAfterInQueueCommand.Execute(param);
432-
Toast.MakeText(_parentFrag.Context, $"Inserted {songsToInsert.Count} songs after", ToastLength.Short)?.Show();
433-
}
408+
Toast.MakeText(_parentFrag.Context, $"Inserted {_currentSongContext.Title} after", ToastLength.Short)?.Show();
409+
434410
}
435411
};
436412
}
437413

438414
// 2. Container Click (Play)
439415
_container.Click += async (s, e) =>
440416
{
441-
if (_currentSong != null)
442-
await _viewModel.PlaySongAsync(_currentSong);
417+
if (_currentSongContext != null)
418+
await _viewModel.PlaySongAsync(_currentSongContext);
443419
};
444420

445421
_container.LongClick += (s, e) =>
446422
{
447423
_container.PerformHapticFeedback(FeedbackConstants.LongPress);
448424
// view in playbackQUeue
449-
_viewModel.SelectedSong=_currentSong;
425+
_viewModel.SelectedSong=_currentSongContext;
450426

451427
var queueSheet = new QueueBottomSheetFragment(_viewModel);
452428
queueSheet.Show(parentFrag.ParentFragmentManager, "QueueSheet");
453429

454-
queueSheet.ScrollToSong(_currentSong);
430+
queueSheet.ScrollToSong(_currentSongContext);
455431
};
456432

457433
_infoBtn.Click += (s, e) =>
458434
{
459-
var infoSheet = new SongInfoBottomSheetFragment(_viewModel, _currentSong);
435+
var infoSheet = new SongInfoBottomSheetFragment(_viewModel, _currentSongContext);
460436
infoSheet.Show(_parentFrag.ParentFragmentManager, "SongInfoSheet");
461437
};
462438

463439

464440
// 3. Play Button
465441
_playNextBtn.Click += async (s, e) =>
466442
{
467-
if (_currentSong != null)
443+
if (_currentSongContext != null)
468444
{
469-
_viewModel.SetAsNextToPlayInQueue(_currentSong);
445+
_viewModel.SetAsNextToPlayInQueue(_currentSongContext);
470446

471447
}
472448

473449
};
474450

475451
lyrBtn.Click += async (s, e) =>
476452
{
477-
if (_currentSong != null)
453+
if (_currentSongContext != null)
478454
{
479-
await _viewModel.ShareSongViewClipboard(_currentSong);
455+
await _viewModel.ShareSongViewClipboard(_currentSongContext);
480456
}
481457
};
482458

@@ -486,9 +462,9 @@ public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView
486462
// 4. Image Click (Navigate)
487463
_img.Click += (s, e) =>
488464
{
489-
if (_currentSong != null)
465+
if (_currentSongContext != null)
490466
{
491-
_viewModel.SelectedSong = _currentSong;
467+
_viewModel.SelectedSong = _currentSongContext;
492468
// Note: Transition name must be updated in Bind, but we can read it from the view here
493469
string? tName = ViewCompat.GetTransitionName(_img);
494470
if (tName != null)
@@ -502,37 +478,37 @@ public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView
502478
_artist.LongClickable = true;
503479
_artist.LongClick += (s, e) =>
504480
{
505-
if (_currentSong?.ArtistName != null)
481+
if (_currentSongContext?.ArtistName != null)
506482
{
507-
var query = $"artist:\"{_currentSong.ArtistName}\"";
483+
var query = $"artist:\"{_currentSongContext.ArtistName}\"";
508484
_viewModel.SearchSongForSearchResultHolder(query);
509485
}
510486
};
511487

512488
// 6. Fav Button
513489
_favBtn.Click += async (s, e) =>
514490
{
515-
if (_currentSong != null)
491+
if (_currentSongContext != null)
516492
{
517-
await _viewModel.AddFavoriteRatingToSong(_currentSong);
493+
await _viewModel.AddFavoriteRatingToSong(_currentSongContext);
518494
// Instant visual feedback
519-
_favBtn.Text = !_currentSong.IsFavorite ? "Unfav" : "Fav";
520-
_favBtn.SetIconResource(_currentSong.IsFavorite ? Resource.Drawable.heartlock : Resource.Drawable.heart);
521-
_favBtn.IconTint = _currentSong.IsFavorite ? AppUtil.ToColorStateList(Color.DarkSlateBlue) : AppUtil.ToColorStateList(Color.Gray) ;
495+
_favBtn.Text = !_currentSongContext.IsFavorite ? "Unfav" : "Fav";
496+
_favBtn.SetIconResource(_currentSongContext.IsFavorite ? Resource.Drawable.heartlock : Resource.Drawable.heart);
497+
_favBtn.IconTint = _currentSongContext.IsFavorite ? AppUtil.ToColorStateList(Color.DarkSlateBlue) : AppUtil.ToColorStateList(Color.Gray) ;
522498
}
523499
};
524500
_favBtn.LongClick += async (s, e) =>
525501
{
526-
if (_currentSong != null)
502+
if (_currentSongContext != null)
527503
{
528-
await _viewModel.RemoveSongFromFavorite(_currentSong);
529-
var iconRes = _currentSong.IsFavorite ? Resource.Drawable.heartlock : Resource.Drawable.heart;
504+
await _viewModel.RemoveSongFromFavorite(_currentSongContext);
505+
var iconRes = _currentSongContext.IsFavorite ? Resource.Drawable.heartlock : Resource.Drawable.heart;
530506
// Instant visual feedback
531-
_favBtn.Text = !_currentSong.IsFavorite ? "Unfav" : "Fav";
507+
_favBtn.Text = !_currentSongContext.IsFavorite ? "Unfav" : "Fav";
532508
_favBtn.SetIconResource(iconRes);
533509
UiBuilder.ShowSnackBar(
534510
_favBtn,
535-
_currentSong.IsFavorite ? "Added to Favorites" : "Removed from Favorites",
511+
_currentSongContext.IsFavorite ? "Added to Favorites" : "Removed from Favorites",
536512
textColor: Color.Black,
537513
iconResId: iconRes
538514
);
@@ -542,7 +518,7 @@ public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView
542518

543519
public void Bind(SongModelView song, bool isExpanded, Action<int> onExpandToggle)
544520
{
545-
_currentSong = song;
521+
_currentSongContext = song;
546522
_expandAction = onExpandToggle;
547523
var sessionDisposable = new CompositeDisposable();
548524
_title.Text = song.Title;

Dimmer/Dimmer/ViewModel/BaseViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,13 +3864,13 @@ public void InsertSongsBeforeInQueue(Tuple<SongModelView, IEnumerable<SongModelV
38643864
/// Inserts songs after a specific song in the queue
38653865
/// </summary>
38663866
[RelayCommand]
3867-
public void InsertSongsAfterInQueue(Tuple<SongModelView, IEnumerable<SongModelView>> param)
3867+
public void InsertSongsAfterInQueue(IEnumerable<SongModelView> param)
38683868
{
3869-
if (param == null || param.Item2 == null || !param.Item2.Any())
3869+
if (param == null || !param.Any())
38703870
return;
38713871

3872-
var targetSong = param.Item1;
3873-
var songsToInsert = param.Item2.Distinct().ToList();
3872+
var targetSong = CurrentPlayingSongView;
3873+
var songsToInsert = param.Distinct().ToList();
38743874

38753875
var targetIndex = PlaybackQueue.IndexOf(targetSong);
38763876
if (targetIndex < 0)

0 commit comments

Comments
 (0)