Skip to content

Commit

Permalink
iOS: ResumePlayback can now actually resume playback! But it only loa…
Browse files Browse the repository at this point in the history
…ds the query of the artist name/album title and doesn't select the actual song. The Player view creation is also buggy. Time to go to bed!!!

Related to issue #405.
  • Loading branch information
ycastonguay committed Oct 22, 2013
1 parent 0308af3 commit f17ba2a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 25 deletions.
39 changes: 34 additions & 5 deletions MPfm/MPfm.MVP/Presenters/ResumePlaybackPresenter.cs
Expand Up @@ -22,6 +22,11 @@
using MPfm.Library.Services.Interfaces;
using System.Threading.Tasks;
using System.Threading;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Messages;
using TinyMessenger;
using System.Linq;

namespace MPfm.MVP.Presenters
{
Expand All @@ -30,19 +35,31 @@ namespace MPfm.MVP.Presenters
/// </summary>
public class ResumePlaybackPresenter : BasePresenter<IResumePlaybackView>, IResumePlaybackPresenter
{
private readonly MobileNavigationManager _mobileNavigationManager;
private readonly NavigationManager _navigationManager;
private readonly ITinyMessengerHub _messengerHub;
private readonly ICloudLibraryService _cloudLibrary;
private readonly IAudioFileCacheService _audioFileCacheService;

public ResumePlaybackPresenter(ICloudLibraryService cloudLibrary)
public ResumePlaybackPresenter(ITinyMessengerHub messengerHub, IAudioFileCacheService audioFileCacheService, ICloudLibraryService cloudLibrary)
{
_messengerHub = messengerHub;
_audioFileCacheService = audioFileCacheService;
_cloudLibrary = cloudLibrary;
_cloudLibrary.OnDropboxDataChanged += (data) => {
Task.Factory.StartNew(() => {
Console.WriteLine("ResumePlaybackPresenter - OnDropboxDataChanged - Sleeping 1 second...");
Thread.Sleep(1000);
Console.WriteLine("ResumePlaybackPresenter - OnDropboxDataChanged - Sleeping...");
Thread.Sleep(500); // TODO: Wait for download to finish with listener (see Dropbox docs)
Console.WriteLine("ResumePlaybackPresenter - OnDropboxDataChanged - Fetching device infos...");
RefreshDevices();
});
};

#if IOS || ANDROID || WINDOWS_PHONE || WINDOWSSTORE
_mobileNavigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
#else
_navigationManager = Bootstrapper.GetContainer().Resolve<NavigationManager>();
#endif
}

public override void BindView(IResumePlaybackView view)
Expand Down Expand Up @@ -71,9 +88,21 @@ private void RefreshDevices()

private void ResumePlayback(CloudDeviceInfo device)
{
var audioFile = _audioFileCacheService.AudioFiles.FirstOrDefault(x => x.Id == device.AudioFileId);
Action<IBaseView> onViewBindedToPresenter = (theView) => _messengerHub.PublishAsync<MobileLibraryBrowserItemClickedMessage>(new MobileLibraryBrowserItemClickedMessage(this)
{
Query = new LibraryQuery() {
ArtistName = device.ArtistName,
AlbumTitle = device.AlbumTitle
},
FilePath = audioFile != null ? audioFile.FilePath : string.Empty
});



#if IOS || ANDROID || WINDOWS_PHONE || WINDOWSSTORE
_mobileNavigationManager.CreatePlayerView(MobileNavigationTabType.More, onViewBindedToPresenter);
#else
_navigationManager.CreateSyncMenuView(device);
#endif
}
}
}
18 changes: 11 additions & 7 deletions MPfm/MPfm.iOS/Classes/Controllers/ResumePlaybackViewController.cs
Expand Up @@ -18,14 +18,15 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using MPfm.Library.Objects;
using MPfm.MVP.Views;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MPfm.iOS.Classes.Controllers.Base;
using MPfm.iOS.Classes.Controls;
using MPfm.iOS.Classes.Objects;
using MPfm.iOS.Classes.Services;
using MPfm.Library.Objects;
using System.Linq;

namespace MPfm.iOS
{
Expand All @@ -44,6 +45,8 @@ public override void ViewDidLoad()
tableView.WeakDataSource = this;
tableView.WeakDelegate = this;

this.View.BackgroundColor = GlobalTheme.BackgroundColor;

base.ViewDidLoad();
}

Expand Down Expand Up @@ -73,10 +76,10 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
}

cell.ImageView.Hidden = true;
cell.TextLabel.Text = string.Format("{0}/{1}/{2}", device.DeviceType, device.DeviceName, device.DeviceId);
cell.TextLabel.Font = UIFont.FromName("HelveticaNeue", 11);
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", 11);
cell.DetailTextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 12);
cell.Accessory = UITableViewCellAccessory.None;
cell.ImageChevron.Image = UIImage.FromBundle("Images/Tables/chevron");
cell.ImageChevron.Hidden = false;
Expand All @@ -87,7 +90,7 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
[Export ("tableView:didSelectRowAtIndexPath:")]
public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
//OnItemClick(_items[indexPath.Row].Key);
OnResumePlayback(_devices[indexPath.Row]);
}

[Export ("tableView:didHighlightRowAtIndexPath:")]
Expand All @@ -112,7 +115,8 @@ public float HeightForRow(UITableView tableView, NSIndexPath indexPath)

partial void actionResumePlayback(NSObject sender)
{

//var indexPath = tableView.IndexPathForSelectedRow;
//Console.WriteLine("indexPath: {0}", indexPath);
}

#region IResumePlaybackView implementation
Expand Down
6 changes: 3 additions & 3 deletions MPfm/MPfm.iOS/MPfm.iOS.csproj
Expand Up @@ -110,12 +110,12 @@
<Reference Include="TinyIoC">
<HintPath>..\MPfm.Core\Lib\iOS\TinyIoC.dll</HintPath>
</Reference>
<Reference Include="DropBoxSync.iOS">
<HintPath>..\Components\dropboxsync-1.9.1\lib\ios\DropBoxSync.iOS.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\MPfm.Library\Lib\iOS\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="DropBoxSync.iOS">
<HintPath>..\Components\dropboxsync-1.9.1\lib\ios\DropBoxSync.iOS.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
Expand Down
23 changes: 13 additions & 10 deletions MPfm/MPfm.iOS/XIB/iPhone/ResumePlaybackViewController_iPhone.xib
Expand Up @@ -16,29 +16,32 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Select a device from which to resume playback from:" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Fmt-h4-3LP">
<rect key="frame" x="20" y="27" width="280" height="36"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Select a device from the to list to resume playback:" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Fmt-h4-3LP">
<rect key="frame" x="13" y="8" width="292" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="nYx-or-spr">
<rect key="frame" x="0.0" y="76" width="320" height="329"/>
<rect key="frame" x="0.0" y="63" width="320" height="417"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</tableView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="181-yh-9pI" customClass="MPfmButton">
<rect key="frame" x="20" y="416" width="280" height="44"/>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="181-yh-9pI" customClass="MPfmButton">
<rect key="frame" x="25" y="22" width="280" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="14"/>
<state key="normal" title="Resume Playback"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="13"/>
<state key="normal" title="Re">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="actionResumePlayback:" destination="-1" eventType="touchUpInside" id="5kI-8k-cel"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
</view>
</objects>
Expand Down

0 comments on commit f17ba2a

Please sign in to comment.