From 92bdeccab798b45495d18a1976a796d1c39bce73 Mon Sep 17 00:00:00 2001 From: Difegue Date: Thu, 14 Sep 2023 22:20:03 +0200 Subject: [PATCH] hook up basic tap to play/addqueue in all tableviews Disable multiselect for now --- .../Stylophone.iOS/Helpers/TrackTableViewDataSource.cs | 6 +++++- .../ViewControllers/AlbumDetailViewController.cs | 8 ++++++-- .../ViewControllers/PlaylistViewController.cs | 6 +++++- .../ViewControllers/QueueViewController.cs | 9 +++++++-- .../ViewControllers/SearchResultsViewController.cs | 6 +++++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Sources/Stylophone.iOS/Helpers/TrackTableViewDataSource.cs b/Sources/Stylophone.iOS/Helpers/TrackTableViewDataSource.cs index 4e631cc..60d7170 100644 --- a/Sources/Stylophone.iOS/Helpers/TrackTableViewDataSource.cs +++ b/Sources/Stylophone.iOS/Helpers/TrackTableViewDataSource.cs @@ -21,6 +21,7 @@ public class TrackTableViewDataSource : UITableViewDelegate, IUITableViewDataSou private Func _menuFactory; private Func _swipeFactory; private Action _scrollHandler; + private Action _tapHandler; private ObservableCollection _sourceCollection; public TrackTableViewDataSource(IntPtr handle) : base(handle) @@ -38,13 +39,14 @@ public TrackTableViewDataSource(IntPtr handle) : base(handle) /// Optional scrollHandler public TrackTableViewDataSource(UITableView tableView, ObservableCollection source, Func contextMenuFactory, Func swipeActionFactory, - bool canSelectRows = false, Action scrollHandler = null) + bool canSelectRows = false, Action scrollHandler = null, Action tapHandler = null) { _tableView = tableView; _sourceCollection = source; _menuFactory = contextMenuFactory; _swipeFactory = swipeActionFactory; _scrollHandler = scrollHandler; + _tapHandler = tapHandler; _sourceCollection.CollectionChanged += (s,e) => UIApplication.SharedApplication.InvokeOnMainThread( () => UpdateUITableView(s,e)); @@ -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) diff --git a/Sources/Stylophone.iOS/ViewControllers/AlbumDetailViewController.cs b/Sources/Stylophone.iOS/ViewControllers/AlbumDetailViewController.cs index 8eeff0b..1c49a15 100644 --- a/Sources/Stylophone.iOS/ViewControllers/AlbumDetailViewController.cs +++ b/Sources/Stylophone.iOS/ViewControllers/AlbumDetailViewController.cs @@ -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; @@ -44,7 +45,10 @@ public override void AwakeFromNib() Binder.Bind(AlbumTrackInfo, "text", nameof(ViewModel.PlaylistInfo)); } - private void OnScroll(UIScrollView scrollView) + private void OnTap(NSIndexPath indexPath) => + ViewModel.AddToQueueCommand.Execute(new List { ViewModel?.Source[indexPath.Row] }); + + private void OnScroll(UIScrollView scrollView) { if (scrollView.ContentOffset.Y > 192) { diff --git a/Sources/Stylophone.iOS/ViewControllers/PlaylistViewController.cs b/Sources/Stylophone.iOS/ViewControllers/PlaylistViewController.cs index d05e785..ccd9110 100644 --- a/Sources/Stylophone.iOS/ViewControllers/PlaylistViewController.cs +++ b/Sources/Stylophone.iOS/ViewControllers/PlaylistViewController.cs @@ -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; @@ -103,6 +104,9 @@ public override void ViewWillDisappear(bool animated) ViewModel.Dispose(); } + private void OnTap(NSIndexPath indexPath) => + ViewModel.AddToQueueCommand.Execute(new List { ViewModel?.Source[indexPath.Row] }); + private void OnScroll(UIScrollView scrollView) { if (scrollView.ContentOffset.Y > 192) diff --git a/Sources/Stylophone.iOS/ViewControllers/QueueViewController.cs b/Sources/Stylophone.iOS/ViewControllers/QueueViewController.cs index d397e12..ad322d0 100644 --- a/Sources/Stylophone.iOS/ViewControllers/QueueViewController.cs +++ b/Sources/Stylophone.iOS/ViewControllers/QueueViewController.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Threading.Tasks; +using System.Collections; namespace Stylophone.iOS.ViewControllers { @@ -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() @@ -54,7 +55,8 @@ 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; @@ -62,6 +64,9 @@ public override void ViewDidLoad() _mpdService.SongChanged += ScrollToPlayingSong; } + private void OnTap(NSIndexPath indexPath) => + ViewModel.PlayTrackCommand.Execute(new List { ViewModel?.Source[indexPath.Row] }); + private void UpdateListOnPlaylistVersionChange(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(ViewModel.PlaylistVersion)) diff --git a/Sources/Stylophone.iOS/ViewControllers/SearchResultsViewController.cs b/Sources/Stylophone.iOS/ViewControllers/SearchResultsViewController.cs index 65e773b..3c2807e 100644 --- a/Sources/Stylophone.iOS/ViewControllers/SearchResultsViewController.cs +++ b/Sources/Stylophone.iOS/ViewControllers/SearchResultsViewController.cs @@ -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; @@ -58,6 +59,9 @@ public override void ViewDidLoad() SearchSegmentedControl.PrimaryActionTriggered += SearchSegmentedControl_PrimaryActionTriggered; } + private void OnTap(NSIndexPath indexPath) => + ViewModel.AddToQueueCommand.Execute(new List { ViewModel?.Source[indexPath.Row] }); + private void SearchSegmentedControl_PrimaryActionTriggered(object sender, EventArgs e) { switch (SearchSegmentedControl.SelectedSegment)