Skip to content

Commit

Permalink
iOS: Fixed bugs related to contextual menu in Album collection view. …
Browse files Browse the repository at this point in the history
…Updated project after changes on other platforms.

Related to issue #405.
  • Loading branch information
ycastonguay committed Oct 5, 2013
1 parent e9c42a3 commit 6668955
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 29 deletions.
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/MPfm.MVP.iOS.csproj
Expand Up @@ -329,5 +329,6 @@
<Compile Include="Views\ISelectFoldersView.cs" />
<Compile Include="Presenters\Interfaces\ISelectFoldersPresenter.cs" />
<Compile Include="Presenters\SelectFoldersPresenter.cs" />
<Compile Include="Models\FolderEntity.cs" />
</ItemGroup>
</Project>
Expand Up @@ -35,6 +35,7 @@
using MPfm.iOS.Classes.Delegates;
using MPfm.iOS.Classes.Objects;
using MPfm.iOS.Helpers;
using MPfm.Core;

namespace MPfm.iOS.Classes.Controllers
{
Expand All @@ -52,7 +53,7 @@ public partial class MobileLibraryBrowserViewController : BaseViewController, IM
List<KeyValuePair<string, UIImage>> _thumbnailImageCache;
UIButton _btnDelete;
int _deleteCellIndex = -1;
int _menuCellIndex = -1;
int _editingAlbumRowPosition = -1;

public MobileLibraryBrowserViewController(Action<IBaseView> onViewReady)
: base (onViewReady, UserInterfaceIdiomIsPhone ? "MobileLibraryBrowserViewController_iPhone" : "MobileLibraryBrowserViewController_iPad", null)
Expand Down Expand Up @@ -252,17 +253,55 @@ private void HandleLongPressAlbums(UILongPressGestureRecognizer gestureRecognize
if (gestureRecognizer.State != UIGestureRecognizerState.Began)
return;

PointF pt = gestureRecognizer.LocationInView(tableView);
NSIndexPath indexPath = tableView.IndexPathForRowAtPoint(pt);
if (indexPath == null)
_menuCellIndex = -1;
else
_menuCellIndex = indexPath.Row;
Tracing.Log("MobileLibraryBrowserViewController - HandleLongPressAlbums");
PointF pt = gestureRecognizer.LocationInView(collectionView);
NSIndexPath indexPath = collectionView.IndexPathForItemAtPoint(pt);
SetEditingAlbumRow(indexPath.Row);
}

private void ResetEditingAlbumRow()
{
SetEditingAlbumRow(-1);
}

private void SetEditingAlbumRow(int position)
{
int oldPosition = _editingAlbumRowPosition;
_editingAlbumRowPosition = position;

if (oldPosition >= 0)
{
var oldItem = _items[oldPosition];
var oldCell = (MPfmCollectionAlbumViewCell)collectionView.VisibleCells.FirstOrDefault(x => x.Tag == oldPosition);
if (oldCell != null)
{
UIView.Animate(0.2, 0, UIViewAnimationOptions.CurveEaseIn, () => {
oldCell.PlayButton.Alpha = 0;
oldCell.AddButton.Alpha = 0;
oldCell.DeleteButton.Alpha = 0;
}, null);
}
}

if (position >= 0)
{
var item = _items[position];
var cell = (MPfmCollectionAlbumViewCell)collectionView.VisibleCells.FirstOrDefault(x => x.Tag == position);
if (cell != null)
{
UIView.Animate(0.2, 0, UIViewAnimationOptions.CurveEaseIn, () => {
cell.PlayButton.Alpha = 1;
cell.AddButton.Alpha = 1;
cell.DeleteButton.Alpha = 1;
}, null);
}
}
}

[Export ("collectionView:cellForItemAtIndexPath:")]
public UICollectionViewCell CellForItemAtIndexPath(UICollectionView collectionView, NSIndexPath indexPath)
{
Tracing.Log("MobileLibraryBrowserViewController - CellForItemAtIndexPath - indexPath.Row: {0}", indexPath.Row);
var cell = (MPfmCollectionAlbumViewCell)collectionView.DequeueReusableCell(_collectionCellIdentifier, indexPath);
cell.Tag = indexPath.Row;

Expand All @@ -289,9 +328,9 @@ public UICollectionViewCell CellForItemAtIndexPath(UICollectionView collectionVi
}
}

cell.PlayButton.Alpha = _menuCellIndex == indexPath.Row ? 1 : 0;
cell.AddButton.Alpha = _menuCellIndex == indexPath.Row ? 1 : 0;
cell.DeleteButton.Alpha = _menuCellIndex == indexPath.Row ? 1 : 0;
cell.PlayButton.Alpha = _editingAlbumRowPosition == indexPath.Row ? 1 : 0;
cell.AddButton.Alpha = _editingAlbumRowPosition == indexPath.Row ? 1 : 0;
cell.DeleteButton.Alpha = _editingAlbumRowPosition == indexPath.Row ? 1 : 0;

cell.PlayButton.TouchUpInside += HandleBtnPlayTouchUpInside;
cell.AddButton.TouchUpInside += HandleBtnAddTouchUpInside;
Expand Down Expand Up @@ -319,6 +358,7 @@ public int NumberOfSectionsInCollectionView(UICollectionView collectionView)
[Export ("collectionView:didSelectItemAtIndexPath:")]
public void CollectionDidSelectItemAtIndexPath(UICollectionView collectionView, NSIndexPath indexPath)
{
ResetEditingAlbumRow();
OnItemClick(indexPath.Row);
}

Expand Down Expand Up @@ -349,26 +389,17 @@ public bool CollectionShouldShowMenuForItemAtIndexPath(UICollectionView collecti

private void HandleBtnAddTouchUpInside(object sender, EventArgs e)
{
FadeOutMenu();
ResetEditingAlbumRow();
}

private void HandleBtnDeleteTouchUpInside(object sender, EventArgs e)
{
FadeOutMenu();
ResetEditingAlbumRow();
}

private void HandleBtnPlayTouchUpInside(object sender, EventArgs e)
{
FadeOutMenu();
}

private void FadeOutMenu()
{
// UIView.Animate(0.1, 0, UIViewAnimationOptions.CurveEaseIn, () => {
// PlayButton.Alpha = 0;
// AddButton.Alpha = 0;
// DeleteButton.Alpha = 0;
// }, null);
ResetEditingAlbumRow();
}

// [Export ("collectionView:viewForSupplementaryElementOfKind:atIndexPath:")]
Expand Down Expand Up @@ -744,6 +775,7 @@ public async void RefreshAlbumArtCell(string artistName, string albumTitle, byte
public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities, MobileLibraryBrowserType browserType, string navigationBarTitle, string navigationBarSubtitle, string breadcrumb, bool isPopBackstack, bool isBackstackEmpty)
{
InvokeOnMainThread(() => {
_editingAlbumRowPosition = -1;
_items = entities.ToList();
_browserType = browserType;
_navigationBarTitle = navigationBarTitle;
Expand Down
5 changes: 0 additions & 5 deletions MPfm/MPfm.iOS/Classes/Controls/MPfmCollectionAlbumViewCell.cs
Expand Up @@ -175,11 +175,6 @@ public void SetHighlight(bool highlighted)
_lblTitle.Frame = new RectangleF(_lblTitle.Frame.X, _lblTitle.Frame.Y - 1, _lblTitle.Frame.Width, _lblTitle.Frame.Height - 1);
_lblSubtitle.Frame = new RectangleF(_lblSubtitle.Frame.X, _lblSubtitle.Frame.Y - 4, _lblSubtitle.Frame.Width, _lblSubtitle.Frame.Height - 2);
}, null);
UIView.Animate(0.1, 0.7, UIViewAnimationOptions.CurveEaseIn, () => {
PlayButton.Alpha = 1;
AddButton.Alpha = 1;
DeleteButton.Alpha = 1;
}, null);
}
else
{
Expand Down
10 changes: 8 additions & 2 deletions MPfm/MPfm.iOS/Classes/Helpers/iOSSyncDeviceSpecifications.cs
Expand Up @@ -21,6 +21,7 @@
using MPfm.Library.Objects;
using MonoTouch.UIKit;
using MPfm.Library.Services;
using System.Collections.Generic;

namespace MPfm.iOS.Helpers
{
Expand All @@ -33,13 +34,13 @@ public class iOSSyncDeviceSpecifications : NSObject, ISyncDeviceSpecifications

public iOSSyncDeviceSpecifications()
{
Console.WriteLine(">>>>>>>>>>>>>>>>>> SETTING REACHABILITY EVENT");
Console.WriteLine("iOSSyncDeviceSpecifications - Setting Reachability event...");
ReachabilityHelper.ReachabilityChanged += HandleReachabilityChanged;
}

private void HandleReachabilityChanged(object sender, EventArgs e)
{
Console.WriteLine(">>>>>>>>>>>>>>>>>> REACHABILITY CHANGED");
Console.WriteLine("iOSSyncDeviceSpecifications - Reachability changed!");
}

public SyncDeviceType GetDeviceType()
Expand Down Expand Up @@ -79,6 +80,11 @@ public string GetMusicFolderPath()
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}

public List<string> GetRootFolderPaths()
{
return new List<string>();
}

public void ReportNetworkStateChange(NetworkState networkState)
{
if(OnNetworkStateChanged != null)
Expand Down

0 comments on commit 6668955

Please sign in to comment.