Skip to content

Commit

Permalink
hook up basic tap to play/addqueue in all tableviews
Browse files Browse the repository at this point in the history
Disable multiselect for now
  • Loading branch information
Difegue committed Sep 14, 2023
1 parent 54fa67f commit 92bdecc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Sources/Stylophone.iOS/Helpers/TrackTableViewDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class TrackTableViewDataSource : UITableViewDelegate, IUITableViewDataSou
private Func<NSIndexPath, UIMenu> _menuFactory;
private Func<NSIndexPath, bool, UISwipeActionsConfiguration> _swipeFactory;
private Action<UIScrollView> _scrollHandler;
private Action<NSIndexPath> _tapHandler;
private ObservableCollection<TrackViewModel> _sourceCollection;

public TrackTableViewDataSource(IntPtr handle) : base(handle)
Expand All @@ -38,13 +39,14 @@ public TrackTableViewDataSource(IntPtr handle) : base(handle)
/// <param name="scrollHandler">Optional scrollHandler</param>
public TrackTableViewDataSource(UITableView tableView, ObservableCollection<TrackViewModel> source,
Func<NSIndexPath, UIMenu> contextMenuFactory, Func<NSIndexPath,bool, UISwipeActionsConfiguration> swipeActionFactory,
bool canSelectRows = false, Action<UIScrollView> scrollHandler = null)
bool canSelectRows = false, Action<UIScrollView> scrollHandler = null, Action<NSIndexPath> tapHandler = null)
{
_tableView = tableView;
_sourceCollection = source;
_menuFactory = contextMenuFactory;
_swipeFactory = swipeActionFactory;
_scrollHandler = scrollHandler;
_tapHandler = tapHandler;

_sourceCollection.CollectionChanged += (s,e) => UIApplication.SharedApplication.InvokeOnMainThread(
() => UpdateUITableView(s,e));
Expand Down Expand Up @@ -128,6 +130,8 @@ public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
if (tableView.AllowsMultipleSelection)
tableView.CellAt(indexPath).Accessory = UITableViewCellAccessory.Checkmark;
else
_tapHandler?.Invoke(indexPath);
}

public override void RowDeselected(UITableView tableView, NSIndexPath indexPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public override void AwakeFromNib()
TraitCollectionDidChange(null);
NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Never;

var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source, GetRowContextMenu, GetRowSwipeActions, true, OnScroll);
var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source,
GetRowContextMenu, GetRowSwipeActions, false, OnScroll, OnTap);
TableView.DataSource = trackDataSource;
TableView.Delegate = trackDataSource;
TableView.SelfSizingInvalidation = UITableViewSelfSizingInvalidation.EnabledIncludingConstraints;
Expand All @@ -44,7 +45,10 @@ public override void AwakeFromNib()
Binder.Bind<string>(AlbumTrackInfo, "text", nameof(ViewModel.PlaylistInfo));
}

private void OnScroll(UIScrollView scrollView)
private void OnTap(NSIndexPath indexPath) =>
ViewModel.AddToQueueCommand.Execute(new List<object> { ViewModel?.Source[indexPath.Row] });

private void OnScroll(UIScrollView scrollView)
{
if (scrollView.ContentOffset.Y > 192)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public override void AwakeFromNib()

_settingsBtn = CreateSettingsButton();

var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source, GetRowContextMenu, GetRowSwipeActions, true, OnScroll);
var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source,
GetRowContextMenu, GetRowSwipeActions, false, OnScroll, OnTap);
TableView.DataSource = trackDataSource;
TableView.Delegate = trackDataSource;

Expand Down Expand Up @@ -103,6 +104,9 @@ public override void ViewWillDisappear(bool animated)
ViewModel.Dispose();
}

private void OnTap(NSIndexPath indexPath) =>
ViewModel.AddToQueueCommand.Execute(new List<object> { ViewModel?.Source[indexPath.Row] });

private void OnScroll(UIScrollView scrollView)
{
if (scrollView.ContentOffset.Y > 192)
Expand Down
9 changes: 7 additions & 2 deletions Sources/Stylophone.iOS/ViewControllers/QueueViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Collections;

namespace Stylophone.iOS.ViewControllers
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public override void AwakeFromNib()
private void OnLeavingBackground(object sender, EventArgs e)
{
if (_mpdService.IsConnected)
Task.Run(async () => await ViewModel.LoadInitialDataAsync());
Task.Run(ViewModel.LoadInitialDataAsync);
}

public override void ViewDidLoad()
Expand All @@ -54,14 +55,18 @@ public override void ViewDidLoad()

NavigationItem.RightBarButtonItem = CreateSettingsButton();

var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source, GetRowContextMenu, GetRowSwipeActions);
var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source,
GetRowContextMenu, GetRowSwipeActions, tapHandler:OnTap);
TableView.DataSource = trackDataSource;
TableView.Delegate = trackDataSource;
TableView.SelfSizingInvalidation = UITableViewSelfSizingInvalidation.EnabledIncludingConstraints;

_mpdService.SongChanged += ScrollToPlayingSong;
}

private void OnTap(NSIndexPath indexPath) =>
ViewModel.PlayTrackCommand.Execute(new List<object> { ViewModel?.Source[indexPath.Row] });

private void UpdateListOnPlaylistVersionChange(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ViewModel.PlaylistVersion))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public override void ViewDidLoad()
valueTransformer: negateBoolTransformer);


var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source, GetRowContextMenu, GetRowSwipeActions);
var trackDataSource = new TrackTableViewDataSource(TableView, ViewModel.Source,
GetRowContextMenu, GetRowSwipeActions, tapHandler:OnTap);
TableView.DataSource = trackDataSource;
TableView.Delegate = trackDataSource;

Expand All @@ -58,6 +59,9 @@ public override void ViewDidLoad()
SearchSegmentedControl.PrimaryActionTriggered += SearchSegmentedControl_PrimaryActionTriggered;
}

private void OnTap(NSIndexPath indexPath) =>
ViewModel.AddToQueueCommand.Execute(new List<object> { ViewModel?.Source[indexPath.Row] });

private void SearchSegmentedControl_PrimaryActionTriggered(object sender, EventArgs e)
{
switch (SearchSegmentedControl.SelectedSegment)
Expand Down

0 comments on commit 92bdecc

Please sign in to comment.