Skip to content

Commit d0d6cf3

Browse files
committed
Refactor queue actions and cleanup SongAdapter UI
- Replace queue-specific MaterialButton actions with a persistent ImageView "Insert After" button, styled and tinted by theme. - Remove insertBeforeBtn and playNextBtn, updating SongViewHolder accordingly. - Improve insertAfterBtn tooltip and Toast message to include current song title. - Explicitly set action button text color based on theme. - Add early return after playlist creation in BaseViewModel to prevent further execution. - Null-check realm.Dispose() in BaseViewModel.Dispose to avoid exceptions.
1 parent 3954b13 commit d0d6cf3

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

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

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -297,32 +297,41 @@ public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int
297297
expandRow.AddView(infoBtn);
298298
expandRow.AddView(LyricsBtn);
299299

300-
// Add queue-specific buttons only in queue mode
301-
MaterialButton? insertBeforeBtn = null;
302-
MaterialButton? insertAfterBtn = null;
303-
if (_mode == "queue")
304-
{
305-
insertAfterBtn = CreateActionButton(string.Empty, Resource.Drawable.media3_icon_queue_next);
306-
insertAfterBtn.TooltipText = "Insert Song After This";
300+
//if (_mode == "queue")
301+
//{
302+
303+
var insertAfterBtn = new ImageView(ctx, null, Resource.Attribute.materialButtonOutlinedStyle);
304+
insertAfterBtn.SetImageResource(Resource.Drawable.media3_icon_queue_next);
305+
insertAfterBtn.ImageTintList = Android.Content.Res.ColorStateList.ValueOf(UiBuilder.IsDark(this.ParentFragement.Resources.Configuration) ? Color.Gray : Color.ParseColor("#294159"));
306+
307+
insertAfterBtn.SetPadding(30, 0, 30, 0);
308+
var insertAfterBtnlp = new LinearLayout.LayoutParams(-2, -2);
309+
insertAfterBtnlp.RightMargin = 10;
310+
insertAfterBtn.LayoutParameters = insertAfterBtnlp;
311+
insertAfterBtn.Clickable = true;
312+
313+
314+
insertAfterBtn.TooltipText = $"Insert this song after {MyViewModel.CurrentPlayingSongView.Title}";
307315
//expandRow.AddView(insertBeforeBtn);
308316
expandRow.AddView(insertAfterBtn);
309-
}
317+
310318

311319
// Assemble
312320
mainContainer.AddView(topRow);
313321
mainContainer.AddView(expandRow);
314322

315323
card.AddView(mainContainer);
316324

317-
return new SongViewHolder(MyViewModel, ParentFragement, card, imgView, title, artist, moreBtn, durationView,expandRow, (Button)playBtn, (Button)favBtn, (Button)infoBtn,
318-
LyricsBtn, insertBeforeBtn, insertAfterBtn);
325+
return new SongViewHolder(MyViewModel, ParentFragement, card, imgView, title, artist, moreBtn, durationView,expandRow, (Button)favBtn, (Button)infoBtn,
326+
LyricsBtn, insertAfterBtn);
319327
}
320328

321329

322330
private MaterialButton CreateActionButton(string text, int iconId)
323331
{
324332
var btn = new MaterialButton(ctx, null, Resource.Attribute.materialButtonOutlinedStyle);
325333
btn.Text = text;
334+
326335
btn.SetTextColor(UiBuilder.IsDark(this.ParentFragement.Resources.Configuration) ? Color.Gray : Color.ParseColor("#294159"));
327336
btn.SetIconResource(iconId);
328337

@@ -351,17 +360,15 @@ class SongViewHolder : AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder
351360
private readonly MaterialCardView _container;
352361
public View ContainerView => base.ItemView;
353362

354-
private readonly Button _playNextBtn;
355363
private readonly Button _favBtn;
356364
private readonly Button _infoBtn;
357365
private readonly Button lyricsBtn;
358-
private readonly Button? _insertBeforeBtn;
359-
private readonly Button? _insertAfterBtn;
366+
private readonly ImageView? _insertAfterBtn;
360367
private SongModelView? _currentSongContext;
361368
private Action<int>? _expandAction;
362369

363370
public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView container, ImageView img, TextView title, TextView artist, MaterialButton moreBtn, TextView durationView,
364-
View expandRow, Button playBtn, Button favBtn, Button infoBtn, Button lyrBtn, Button? insertBeforeBtn = null, Button? insertAfterBtn = null)
371+
View expandRow,Button favBtn, Button infoBtn, Button lyrBtn, ImageView? insertAfterBtn = null)
365372
: base(container)
366373
{
367374
_viewModel = vm;
@@ -373,11 +380,9 @@ public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView
373380
_moreBtn = moreBtn;
374381
_durationView= durationView;
375382
_expandRow = expandRow;
376-
_playNextBtn = playBtn;
377383
_favBtn = favBtn;
378384
_infoBtn = infoBtn;
379385
lyricsBtn = lyrBtn;
380-
_insertBeforeBtn = insertBeforeBtn;
381386
_insertAfterBtn = insertAfterBtn;
382387

383388
_moreBtn.Click += (s, e) =>
@@ -405,7 +410,7 @@ public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView
405410

406411
var param = new List<SongModelView>() { _currentSongContext };
407412
_viewModel.InsertSongsAfterInQueueCommand.Execute(param);
408-
Toast.MakeText(_parentFrag.Context, $"Inserted {_currentSongContext.Title} after", ToastLength.Short)?.Show();
413+
Toast.MakeText(_parentFrag.Context, $"Inserted {_currentSongContext.Title} after {_viewModel.CurrentPlayingSongView.Title}", ToastLength.Short)?.Show();
409414

410415
}
411416
};
@@ -437,17 +442,7 @@ public SongViewHolder(BaseViewModelAnd vm, Fragment parentFrag, MaterialCardView
437442
};
438443

439444

440-
// 3. Play Button
441-
_playNextBtn.Click += async (s, e) =>
442-
{
443-
if (_currentSongContext != null)
444-
{
445-
_viewModel.SetAsNextToPlayInQueue(_currentSongContext);
446-
447-
}
448-
449-
};
450-
445+
451446
lyrBtn.Click += async (s, e) =>
452447
{
453448
if (_currentSongContext != null)

Dimmer/Dimmer/ViewModel/BaseViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5070,13 +5070,12 @@ public void AddToPlaylist(string playlistName, IEnumerable<SongModelView> songsT
50705070
newPlaylistModel.LastPlayedDate = DateTimeOffset.UtcNow;
50715071
newPlaylistModel.QueryText = PlQuery;
50725072
newPlaylistModel.SongsIdsInPlaylist.AddRange(songsToAdd.Select(s => s.Id).Distinct());
5073-
5073+
50745074
//newPlaylistModel.SongsInPlaylist.AddRange(songsToAdd.Select(s => s.ToModel()).Distinct());
50755075

50765076
realm.Add(newPlaylistModel, true);
50775077
});
5078-
5079-
//targetPlaylist = _playlistRepo.Create(newPlaylistModel);
5078+
return;
50805079
}
50815080

50825081

@@ -5126,7 +5125,7 @@ protected virtual void Dispose(bool disposing)
51265125
{
51275126
_realmSubscription?.Dispose();
51285127
_playEventSource.Dispose();
5129-
realm.Dispose();
5128+
realm?.Dispose();
51305129
_subsManager.Dispose();
51315130
CompositeDisposables.Dispose();
51325131

0 commit comments

Comments
 (0)