Skip to content

Commit

Permalink
iOS: Pimped the look of ResumePlayback. The cells are now disabled if…
Browse files Browse the repository at this point in the history
… the user cannot resume from a device. Several animation bug fixes in different cell views. More bug fixes.
  • Loading branch information
ycastonguay committed Nov 18, 2013
1 parent 98078b1 commit 2ea4959
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 93 deletions.
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/MPfm.MVP.iOS.csproj
Expand Up @@ -365,5 +365,6 @@
<Compile Include="Messages\MobileLibraryBrowserPopBackstackMessage.cs" />
<Compile Include="Messages\EqualizerPresetSelectedMessage.cs" />
<Compile Include="Models\MobileOptionsMenuEntity.cs" />
<Compile Include="Models\ResumePlaybackEntity.cs" />
</ItemGroup>
</Project>
30 changes: 30 additions & 0 deletions MPfm/MPfm.MVP/Models/ResumePlaybackEntity.cs
@@ -0,0 +1,30 @@
// 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 MPfm.Library.Objects;

namespace MPfm.MVP.Models
{
public class ResumePlaybackEntity
{
public CloudDeviceInfo DeviceInfo { get; set; }
public bool CanResumePlayback { get; set; }
public string LocalAudioFilePath { get; set; }
}
}
106 changes: 66 additions & 40 deletions MPfm/MPfm.MVP/Presenters/ResumePlaybackPresenter.cs
Expand Up @@ -16,19 +16,21 @@
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MPfm.Library.Objects;
using MPfm.Library.Services.Exceptions;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Views;
using MPfm.Library.Services.Interfaces;
using System.Threading.Tasks;
using System.Threading;
using TinyMessenger;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Messages;
using TinyMessenger;
using System.Linq;
using MPfm.MVP.Models;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Views;
using System.Collections.Generic;

namespace MPfm.MVP.Presenters
{
Expand Down Expand Up @@ -99,51 +101,75 @@ private void RefreshDevices()
// Prevent login status change during loading
_canRefreshCloudLoginStatus = false;

try
{
var devices = _cloudLibrary.PullDeviceInfos();
View.RefreshDevices(devices.OrderBy(x => x.DeviceName).ToList());
View.RefreshAppLinkedStatus(true);
}
catch (CloudAppNotLinkedException ex)
{
View.RefreshAppLinkedStatus(false);
}
catch (Exception ex)
Task.Factory.StartNew(() =>
{
View.ResumePlaybackError(ex);
}
_canRefreshCloudLoginStatus = true;
try
{
var devices = _cloudLibrary.PullDeviceInfos();
var entities = new List<ResumePlaybackEntity>();
foreach (var device in devices)
{
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());
}
var audioFiles = _audioFileCacheService.SelectAudioFiles(new LibraryQuery() {
ArtistName = device.ArtistName,
AlbumTitle = device.AlbumTitle
});
bool canResume = audioFiles.Count() > 0;
entities.Add(new ResumePlaybackEntity() {
DeviceInfo = device,
LocalAudioFilePath = audioFile == null ? string.Empty : audioFile.FilePath,
CanResumePlayback = canResume
});
}
View.RefreshDevices(entities.OrderByDescending(x => x.CanResumePlayback).ThenBy(x => x.DeviceInfo.DeviceName).ToList());
View.RefreshAppLinkedStatus(true);
} catch (CloudAppNotLinkedException ex)
{
View.RefreshAppLinkedStatus(false);
} catch (Exception ex)
{
View.ResumePlaybackError(ex);
}
_canRefreshCloudLoginStatus = true;
});
}

private void ResumePlayback(CloudDeviceInfo device)
private void ResumePlayback(ResumePlaybackEntity entity)
{
var audioFile = _audioFileCacheService.AudioFiles.FirstOrDefault(x => x.Id == device.AudioFileId);
var audioFile = _audioFileCacheService.AudioFiles.FirstOrDefault(x => x.Id == entity.DeviceInfo.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());
audioFile = _audioFileCacheService.AudioFiles.FirstOrDefault(x => x.ArtistName.ToUpper() == entity.DeviceInfo.ArtistName.ToUpper() &&
x.AlbumTitle.ToUpper() == entity.DeviceInfo.AlbumTitle.ToUpper() &&
x.Title.ToUpper() == entity.DeviceInfo.SongTitle.ToUpper());
}
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
var audioFiles = _audioFileCacheService.SelectAudioFiles(new LibraryQuery() {
ArtistName = entity.DeviceInfo.ArtistName,
AlbumTitle = entity.DeviceInfo.AlbumTitle
});

if (audioFiles.Count() == 0)
{
View.AudioFilesNotFoundError("No audio files found", "Unfortunately, you cannot resume this playlist because none of the audio files could be found on your device.");
return;
}

_playerService.Play(audioFiles, audioFile != null ? audioFile.FilePath : string.Empty, 0, false, false);

// Only need to create the Player view on mobile devices
#if IOS || ANDROID || WINDOWS_PHONE || WINDOWSSTORE
_mobileNavigationManager.CreatePlayerView(MobileNavigationTabType.More);
#else
var audioFiles = _audioFileCacheService.SelectAudioFiles(new LibraryQuery() {
ArtistName = device.ArtistName,
AlbumTitle = device.AlbumTitle
});
_playerService.Play(audioFiles, audioFile != null ? audioFile.FilePath : string.Empty);
#endif
}
}
Expand Down
6 changes: 4 additions & 2 deletions MPfm/MPfm.MVP/Views/IResumePlaybackView.cs
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using MPfm.Library.Objects;
using MPfm.MVP.Models;

namespace MPfm.MVP.Views
{
Expand All @@ -26,12 +27,13 @@ namespace MPfm.MVP.Views
/// </summary>
public interface IResumePlaybackView : IBaseView
{
Action<CloudDeviceInfo> OnResumePlayback { get; set; }
Action<ResumePlaybackEntity> OnResumePlayback { get; set; }
Action OnOpenPreferencesView { get; set; }
Action OnCheckCloudLoginStatus { get; set; }

void ResumePlaybackError(Exception ex);
void AudioFilesNotFoundError(string title, string message);
void RefreshAppLinkedStatus(bool isAppLinked);
void RefreshDevices(IEnumerable<CloudDeviceInfo> devices);
void RefreshDevices(IEnumerable<ResumePlaybackEntity> devices);
}
}
Expand Up @@ -110,7 +110,7 @@ private void GenerateItems()
CellType = PreferenceCellType.Boolean,
HeaderTitle = "Sync",
Title = "Synchronize only on Wi-Fi",
FooterTitle = "The cloud provider will be used to synchronize data between devices, excluding audio files. A small amount of bandwidth (≈1kb/call) is used every time you update a playlist, update a preset or skip to a different song.",
FooterTitle = "The cloud service will be used to synchronize data between devices, excluding audio files. A small amount of bandwidth (≈1kb/call) is used every time you update a playlist, update a preset or skip to a different song.",
Value = _config.IsDropboxResumePlaybackWifiOnlyEnabled
});
}
Expand Down
3 changes: 1 addition & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/MoreViewController.cs
Expand Up @@ -106,7 +106,7 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
cell.ImageView.Image = UIImage.FromBundle("Images/Icons/icon_settings");
break;
case MobileOptionsMenuType.SyncLibrary:
cell.ImageView.Image = UIImage.FromBundle("Images/Icons/icon_mobile");
cell.ImageView.Image = UIImage.FromBundle("Images/Icons/wifi");
break;
case MobileOptionsMenuType.SyncLibraryWebBrowser:
cell.ImageView.Image = UIImage.FromBundle("Images/Icons/icon_web");
Expand Down Expand Up @@ -135,7 +135,6 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
}

cell.TextLabel.Text = item.Title;
cell.TextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 16);
cell.Accessory = UITableViewCellAccessory.None;
cell.IsLargeIcon = true;
cell.ImageChevron.Image = UIImage.FromBundle("Images/Tables/chevron");
Expand Down

0 comments on commit 2ea4959

Please sign in to comment.