Skip to content

Commit

Permalink
iOS: Added ResumePlaybackTableViewCell with a lot more info to displa…
Browse files Browse the repository at this point in the history
…y for Resume Playback. The player now actually resumes to the same song as the other devices! Fixed bugs in Resume Playback view.

Related to issue #405.
  • Loading branch information
ycastonguay committed Oct 23, 2013
1 parent f17ba2a commit 3510ae1
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 14 deletions.
8 changes: 7 additions & 1 deletion MPfm/MPfm.MVP/Presenters/ResumePlaybackPresenter.cs
Expand Up @@ -78,7 +78,7 @@ private void RefreshDevices()
try
{
var devices = _cloudLibrary.PullDeviceInfos();
View.RefreshDevices(devices);
View.RefreshDevices(devices.OrderBy(x => x.DeviceName).ToList());
}
catch (Exception ex)
{
Expand All @@ -89,6 +89,12 @@ private void RefreshDevices()
private void ResumePlayback(CloudDeviceInfo device)
{
var audioFile = _audioFileCacheService.AudioFiles.FirstOrDefault(x => x.Id == device.AudioFileId);
if (audioFile == null)
{
audioFile = _audioFileCacheService.AudioFiles.FirstOrDefault(x => x.ArtistName.ToUpper() == device.ArtistName.ToUpper() &&
x.AlbumTitle.ToUpper() == device.AlbumTitle.ToUpper() &&
x.Title.ToUpper() == device.SongTitle.ToUpper());
}
Action<IBaseView> onViewBindedToPresenter = (theView) => _messengerHub.PublishAsync<MobileLibraryBrowserItemClickedMessage>(new MobileLibraryBrowserItemClickedMessage(this)
{
Query = new LibraryQuery() {
Expand Down
23 changes: 10 additions & 13 deletions MPfm/MPfm.iOS/Classes/Controllers/ResumePlaybackViewController.cs
Expand Up @@ -68,21 +68,18 @@ public int RowsInSection(UITableView tableview, int section)
public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var device = _devices[indexPath.Row];
MPfmTableViewCell cell = (MPfmTableViewCell)tableView.DequeueReusableCell(_cellIdentifier);
MPfmResumePlaybackTableViewCell cell = (MPfmResumePlaybackTableViewCell)tableView.DequeueReusableCell(_cellIdentifier);
if (cell == null)
{
var cellStyle = UITableViewCellStyle.Subtitle;
cell = new MPfmTableViewCell(cellStyle, _cellIdentifier);
cell = new MPfmResumePlaybackTableViewCell(cellStyle, _cellIdentifier);
}

cell.ImageView.Hidden = true;
cell.TextLabel.Text = device.DeviceName; //string.Format("{0} ({1})", device.DeviceName, device.DeviceType);
cell.TextLabel.Font = UIFont.FromName("HelveticaNeue", 14);
cell.DetailTextLabel.Text = string.Format("{0}/{1}/{2}", device.ArtistName, device.AlbumTitle, device.SongTitle);
cell.DetailTextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 12);
cell.Accessory = UITableViewCellAccessory.None;
cell.ImageChevron.Image = UIImage.FromBundle("Images/Tables/chevron");
cell.ImageChevron.Hidden = false;
cell.TextLabel.Text = device.DeviceName;
cell.DetailTextLabel.Text = "On-the-fly Playlist";
cell.LabelArtistName.Text = device.ArtistName;
cell.LabelAlbumTitle.Text = device.AlbumTitle;
cell.LabelSongTitle.Text = device.SongTitle;

return cell;
}
Expand All @@ -96,21 +93,21 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)
[Export ("tableView:didHighlightRowAtIndexPath:")]
public void DidHighlightRowAtIndexPath(UITableView tableView, NSIndexPath indexPath)
{
var cell = (MPfmTableViewCell)tableView.CellAt(indexPath);
var cell = (MPfmResumePlaybackTableViewCell)tableView.CellAt(indexPath);
cell.ImageChevron.Image = UIImage.FromBundle("Images/Tables/chevron_white");
}

[Export ("tableView:didUnhighlightRowAtIndexPath:")]
public void DidUnhighlightRowAtIndexPath(UITableView tableView, NSIndexPath indexPath)
{
var cell = (MPfmTableViewCell)tableView.CellAt(indexPath);
var cell = (MPfmResumePlaybackTableViewCell)tableView.CellAt(indexPath);
cell.ImageChevron.Image = UIImage.FromBundle("Images/Tables/chevron");
}

[Export ("tableView:heightForRowAtIndexPath:")]
public float HeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return 52;
return 116;
}

partial void actionResumePlayback(NSObject sender)
Expand Down
185 changes: 185 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controls/MPfmResumePlaybackTableViewCell.cs
@@ -0,0 +1,185 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MPfm.iOS.Classes.Objects;
using MPfm.iOS.Helpers;

namespace MPfm.iOS.Classes.Controls
{
[Register("MPfmResumePlaybackTableViewCell")]
public class MPfmResumePlaybackTableViewCell : UITableViewCell
{
public bool IsTextAnimationEnabled { get; set; }
public UILabel LabelArtistName { get; private set; }
public UILabel LabelAlbumTitle { get; private set; }
public UILabel LabelSongTitle { get; private set; }
public UIImageView ImageChevron { get; private set; }
public UIImageView ImageAlbum { get; private set; }

public MPfmResumePlaybackTableViewCell() : base()
{
Initialize();
}

public MPfmResumePlaybackTableViewCell(RectangleF frame) : base(frame)
{
Initialize();
}

public MPfmResumePlaybackTableViewCell(UITableViewCellStyle style, string reuseIdentifier) : base(style, reuseIdentifier)
{
Initialize();
}

public void Initialize()
{
SelectionStyle = UITableViewCellSelectionStyle.Default;

UIView backView = new UIView(Frame);
backView.BackgroundColor = GlobalTheme.LightColor;
BackgroundView = backView;
BackgroundColor = UIColor.White;

UIView backViewSelected = new UIView(Frame);
backViewSelected.BackgroundColor = GlobalTheme.SecondaryColor;
SelectedBackgroundView = backViewSelected;

ImageAlbum = new UIImageView();
ImageAlbum.BackgroundColor = UIColor.DarkGray;
AddSubview(ImageAlbum);

TextLabel.Layer.AnchorPoint = new PointF(0, 0.5f);
TextLabel.BackgroundColor = UIColor.Clear;
TextLabel.Font = UIFont.FromName("HelveticaNeue-Medium", 14);
TextLabel.TextColor = UIColor.Black;
TextLabel.HighlightedTextColor = UIColor.White;
DetailTextLabel.Layer.AnchorPoint = new PointF(0, 0.5f);
DetailTextLabel.TextColor = UIColor.Gray;
DetailTextLabel.BackgroundColor = UIColor.Clear;
DetailTextLabel.HighlightedTextColor = UIColor.White;
DetailTextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 14);
ImageView.Hidden = true;
ImageView.BackgroundColor = UIColor.Clear;

// Make sure the text label is over all other subviews
DetailTextLabel.RemoveFromSuperview();
ImageView.RemoveFromSuperview();
AddSubview(DetailTextLabel);
AddSubview(ImageView);

LabelArtistName = new UILabel();
LabelArtistName.BackgroundColor = UIColor.Clear;
LabelArtistName.Font = UIFont.FromName("HelveticaNeue", 13);
LabelArtistName.TextColor = UIColor.Black;
LabelArtistName.LineBreakMode = UILineBreakMode.TailTruncation;
LabelArtistName.HighlightedTextColor = UIColor.White;
AddSubview(LabelArtistName);

LabelAlbumTitle = new UILabel();
LabelAlbumTitle.BackgroundColor = UIColor.Clear;
LabelAlbumTitle.Font = UIFont.FromName("HelveticaNeue", 12);
LabelAlbumTitle.TextColor = UIColor.FromRGBA(0.1f, 0.1f, 0.1f, 1);
LabelAlbumTitle.LineBreakMode = UILineBreakMode.TailTruncation;
LabelAlbumTitle.HighlightedTextColor = UIColor.White;
AddSubview(LabelAlbumTitle);

LabelSongTitle = new UILabel();
LabelSongTitle.BackgroundColor = UIColor.Clear;
LabelSongTitle.Font = UIFont.FromName("HelveticaNeue-Light", 12);
LabelSongTitle.TextColor = UIColor.FromRGBA(0.2f, 0.2f, 0.2f, 1);
LabelSongTitle.LineBreakMode = UILineBreakMode.TailTruncation;
LabelSongTitle.HighlightedTextColor = UIColor.White;
AddSubview(LabelSongTitle);

ImageChevron = new UIImageView(UIImage.FromBundle("Images/Tables/chevron"));
ImageChevron.BackgroundColor = UIColor.Clear;
AddSubview(ImageChevron);

// Make sure the text label is over all other subviews
TextLabel.RemoveFromSuperview();
AddSubview(TextLabel);
}

public override void LayoutSubviews()
{
//BackgroundView.Frame = new RectangleF(0, 0, Frame.Width, Frame.Height);
SelectedBackgroundView.Frame = new RectangleF(0, 0, Frame.Width, Frame.Height);

TextLabel.Frame = new RectangleF(12, 6, 300, 20);
DetailTextLabel.Frame = new RectangleF(12, 24, 300, 20);
LabelArtistName.Frame = new RectangleF(74, 52, 232, 18);
LabelAlbumTitle.Frame = new RectangleF(74, 68, 232, 18);
LabelSongTitle.Frame = new RectangleF(74, 84, 232, 18);
ImageAlbum.Frame = new RectangleF(12, 50, 54, 54);
ImageChevron.Frame = new RectangleF(UIScreen.MainScreen.Bounds.Width - 22, 36, 22, 44);
}

public override void TouchesBegan(NSSet touches, UIEvent evt)
{
AnimatePress(true);
base.TouchesBegan(touches, evt);
}

public override void TouchesEnded(NSSet touches, UIEvent evt)
{
AnimatePress(false);
base.TouchesEnded(touches, evt);
}

public override void TouchesCancelled(NSSet touches, UIEvent evt)
{
AnimatePress(false);
base.TouchesCancelled(touches, evt);
}

private void AnimatePress(bool on)
{
if (!IsTextAnimationEnabled)
return;

if (!on)
{
UIView.Animate(0.1, 0, UIViewAnimationOptions.CurveEaseIn, () => {
// Ignore when scale is lower; it was done on purpose and will be restored to 1 later.
if(TextLabel.Transform.xx < 0.95f) return;
TextLabel.Transform = CGAffineTransform.MakeScale(1, 1);
DetailTextLabel.Transform = CGAffineTransform.MakeScale(1, 1);
//IndexTextLabel.Transform = CGAffineTransform.MakeScale(1, 1);
}, null);
}
else
{
UIView.Animate(0.1, 0, UIViewAnimationOptions.CurveEaseIn, () => {
TextLabel.Transform = CGAffineTransform.MakeScale(0.96f, 0.96f);
DetailTextLabel.Transform = CGAffineTransform.MakeScale(0.96f, 0.96f);
//IndexTextLabel.Transform = CGAffineTransform.MakeScale(0.96f, 0.96f);
}, null);
}
}
}
}
3 changes: 3 additions & 0 deletions MPfm/MPfm.iOS/MPfm.iOS.csproj
Expand Up @@ -290,6 +290,9 @@
<Compile Include="Classes\Controllers\SyncConnectManualViewController.designer.cs">
<DependentUpon>SyncConnectManualViewController.cs</DependentUpon>
</Compile>
<Compile Include="Classes\Controls\MPfmResumePlaybackTableViewCell.cs">
<DependentUpon>MPfmCollectionViewCell.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="XIB\iPhone\SplashViewController_iPhone.xib" />
Expand Down

0 comments on commit 3510ae1

Please sign in to comment.