Skip to content

Commit

Permalink
The MobileLibraryBrowserPresenter now pushes another MLBP view when n…
Browse files Browse the repository at this point in the history
…ecessary.

A few bug fixes in loading audio files from database for the MobileLibraryBrowserPresenter.
MobileNavigationManager now requires a query for creating the MLBP view.
Added InvokeOnMainThread in all UIViewControllers.

Related to issue #408 and issue #409.
  • Loading branch information
ycastonguay committed Feb 20, 2013
1 parent 567b68f commit 612f3c1
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 129 deletions.
2 changes: 1 addition & 1 deletion MPfm/MPfm.Library/Database/DatabaseFacade.cs
Expand Up @@ -113,7 +113,7 @@ public List<AudioFile> SelectAudioFiles(AudioFileFormat format, string artistNam
{
sql.AppendLine(" AND ");
}
sql.AppendLine(" [ArtistName] = '" + albumTitle + "' ");
sql.AppendLine(" [AlbumTitle] = '" + albumTitle + "' ");
}
if(!String.IsNullOrEmpty(search))
{
Expand Down
13 changes: 7 additions & 6 deletions MPfm/MPfm.MVP/Navigation/MobileNavigationManager.cs
Expand Up @@ -21,6 +21,7 @@
using TinyIoC;
using MPfm.MVP.Views;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Models;

namespace MPfm.MVP.Navigation
{
Expand Down Expand Up @@ -63,10 +64,10 @@ public virtual void Start()
Action onInitDone = () =>
{
// Create 4 main tabs
var playlistsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Playlists, MobileLibraryBrowserType.Playlists);
var artistsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Artists, MobileLibraryBrowserType.Artists);
var albumsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Albums, MobileLibraryBrowserType.Albums);
var songsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Songs, MobileLibraryBrowserType.Songs);
var playlistsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Playlists, MobileLibraryBrowserType.Playlists, new SongBrowserQueryEntity());
var artistsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Artists, MobileLibraryBrowserType.Artists, new SongBrowserQueryEntity());
var albumsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Albums, MobileLibraryBrowserType.Albums, new SongBrowserQueryEntity());
var songsView = CreateMobileLibraryBrowserView(MobileNavigationTabType.Songs, MobileLibraryBrowserType.Songs, new SongBrowserQueryEntity());
AddTab(MobileNavigationTabType.Playlists, "Playlists", playlistsView);
AddTab(MobileNavigationTabType.Artists, "Artists", artistsView);
AddTab(MobileNavigationTabType.Albums, "Albums", albumsView);
Expand Down Expand Up @@ -196,7 +197,7 @@ public virtual ILibraryPreferencesView CreateLibraryPreferencesView()
return _libraryPreferencesView;
}

public virtual IMobileLibraryBrowserView CreateMobileLibraryBrowserView(MobileNavigationTabType tabType, MobileLibraryBrowserType browserType)
public virtual IMobileLibraryBrowserView CreateMobileLibraryBrowserView(MobileNavigationTabType tabType, MobileLibraryBrowserType browserType, SongBrowserQueryEntity query)
{
// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Action<IBaseView> onViewReady = (view) =>
Expand All @@ -205,7 +206,7 @@ public virtual IMobileLibraryBrowserView CreateMobileLibraryBrowserView(MobileNa
lock (_locker)
{
var presenter = Bootstrapper.GetContainer().Resolve<IMobileLibraryBrowserPresenter>(new NamedParameterOverloads()
{{"tabType", tabType }, { "browserType", browserType}});
{{"tabType", tabType}, {"browserType", browserType}, {"query", query}});
presenter.BindView((IMobileLibraryBrowserView) view);
_mobileLibraryBrowserList.Add((IMobileLibraryBrowserView) view, presenter);
}
Expand Down
47 changes: 34 additions & 13 deletions MPfm/MPfm.MVP/Presenters/MobileLibraryBrowserPresenter.cs
Expand Up @@ -40,13 +40,17 @@ public class MobileLibraryBrowserPresenter : BasePresenter<IMobileLibraryBrowser
private readonly ITinyMessengerHub _messengerHub;
private readonly ILibraryService _libraryService;
private readonly IAudioFileCacheService _audioFileCacheService;
private readonly SongBrowserQueryEntity _query;

private List<LibraryBrowserEntity> _items;

public AudioFileFormat Filter { get; private set; }

public MobileLibraryBrowserPresenter(MobileNavigationTabType tabType, MobileLibraryBrowserType browserType, ITinyMessengerHub messengerHub, MobileNavigationManager navigationManager,
public MobileLibraryBrowserPresenter(MobileNavigationTabType tabType, MobileLibraryBrowserType browserType, SongBrowserQueryEntity query,
ITinyMessengerHub messengerHub, MobileNavigationManager navigationManager,
ILibraryService libraryService, IAudioFileCacheService audioFileCacheService)
{
_query = query;
_tabType = tabType;
_browserType = browserType;
_messengerHub = messengerHub;
Expand Down Expand Up @@ -82,15 +86,16 @@ private void OnItemClick(int i)
// SONGS TAB: Songs --> Player

// Check if another MobileLibraryBrowser view needs to be pushed
if (_tabType == MobileNavigationTabType.Artists || _tabType == MobileNavigationTabType.Albums)
if ((_tabType == MobileNavigationTabType.Artists || _tabType == MobileNavigationTabType.Albums) &&
_browserType != MobileLibraryBrowserType.Songs)
{
var browserType = (_browserType == MobileLibraryBrowserType.Artists) ? MobileLibraryBrowserType.Albums : MobileLibraryBrowserType.Songs;
var newView = _navigationManager.CreateMobileLibraryBrowserView(_tabType, browserType);
var newView = _navigationManager.CreateMobileLibraryBrowserView(_tabType, browserType, _items[i].Query);
_navigationManager.PushTabView(_tabType, newView);
return;
}

// Make sure the view was binded to the presenter before publishing a message
// Make sure the view was binded to the presenter before publishing a message (TODO: Move Query param into CreatePlayerView)
Action<IBaseView> onViewBindedToPresenter = (theView) => _messengerHub.PublishAsync<MobileLibraryBrowserItemClickedMessage>(new MobileLibraryBrowserItemClickedMessage(this)
{
Query = _items[i].Query
Expand All @@ -104,12 +109,20 @@ private void OnItemClick(int i)
private void RefreshLibraryBrowser()
{
_items = new List<LibraryBrowserEntity>();
if (_tabType == MobileNavigationTabType.Artists)
_items = GetArtists().ToList();
else if (_tabType == MobileNavigationTabType.Albums)
_items = GetAlbums().ToList();
else if (_tabType == MobileNavigationTabType.Songs)
_items = GetSongs().ToList();
switch (_browserType)
{
case MobileLibraryBrowserType.Playlists:
break;
case MobileLibraryBrowserType.Artists:
_items = GetArtists().ToList();
break;
case MobileLibraryBrowserType.Albums:
_items = GetAlbums(_query.ArtistName).ToList();
break;
case MobileLibraryBrowserType.Songs:
_items = GetSongs(_query.ArtistName, _query.AlbumTitle).ToList();
break;
}
View.RefreshLibraryBrowser(_items);
}

Expand All @@ -136,10 +149,10 @@ private IEnumerable<LibraryBrowserEntity> GetArtists()

private IEnumerable<LibraryBrowserEntity> GetAlbums()
{
return GetArtistAlbums(string.Empty);
return GetAlbums(string.Empty);
}

private IEnumerable<LibraryBrowserEntity> GetArtistAlbums(string artistName)
private IEnumerable<LibraryBrowserEntity> GetAlbums(string artistName)
{
var format = AudioFileFormat.All;
var list = new List<LibraryBrowserEntity>();
Expand Down Expand Up @@ -181,7 +194,15 @@ private IEnumerable<LibraryBrowserEntity> GetSongs(string artistName, string alb
var format = AudioFileFormat.All;
var list = new List<LibraryBrowserEntity>();
var audioFiles = _libraryService.SelectAudioFiles(format, artistName, albumTitle, string.Empty);
var songs = audioFiles.Select(x => x.Title).OrderBy(x => x).ToList();

// If a single album is specified, order songs by disc number/track number
if (!String.IsNullOrEmpty(albumTitle))
audioFiles = audioFiles.OrderBy(x => x.DiscNumber).ThenBy(x => x.TrackNumber).ToList();
else
audioFiles = audioFiles.OrderBy(x => x.Title).ToList();

// Get song titles
var songs = audioFiles.Select(x => x.Title).ToList();

// Convert to entities
foreach (var song in songs)
Expand Down
3 changes: 0 additions & 3 deletions MPfm/MPfm.MVP/Presenters/UpdateLibraryPresenter.cs
Expand Up @@ -70,9 +70,6 @@ protected void updateLibraryService_RaiseProcessEndedEvent(object sender, Proces
{
// Refresh audio file cache service
_audioFileCacheService.RefreshCache();

// TODO: Tell other library/song browsers to update themselves!

View.ProcessEnded(e.Canceled);
}

Expand Down
Expand Up @@ -113,8 +113,10 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)

public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities)
{
_items = entities.ToList();
tableView.ReloadData();
InvokeOnMainThread(() => {
_items = entities.ToList();
tableView.ReloadData();
});
}

#endregion
Expand Down
6 changes: 4 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/MoreViewController.cs
Expand Up @@ -104,8 +104,10 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)

public void RefreshMenu(List<KeyValuePair<MobileOptionsMenuType, string>> options)
{
_items = options;
tableView.ReloadData();
InvokeOnMainThread(() => {
_items = options;
tableView.ReloadData();
});
}

#endregion
Expand Down
25 changes: 12 additions & 13 deletions MPfm/MPfm.iOS/Classes/Controllers/SplashViewController.cs
Expand Up @@ -27,18 +27,6 @@ namespace MPfm.iOS.Classes.Controllers
{
public partial class SplashViewController : BaseViewController, ISplashView
{
#region ISplashView implementation

public void RefreshStatus(string message)
{
}

public void InitDone()
{
}

#endregion

public SplashViewController(Action<IBaseView> onViewReady)
: base (onViewReady, UserInterfaceIdiomIsPhone ? "SplashViewController_iPhone" : "SplashViewController_iPad", null)
{
Expand All @@ -56,6 +44,17 @@ public override void ViewDidLoad()
{
base.ViewDidLoad();
}

#region ISplashView implementation

public void RefreshStatus(string message)
{
}

public void InitDone()
{
}

#endregion
}
}

33 changes: 31 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/UpdateLibraryViewController.cs
Expand Up @@ -45,8 +45,26 @@ public override void DidReceiveMemoryWarning()
public override void ViewDidLoad()
{
base.ViewDidLoad();

// Perform any additional setup after loading the view, typically from a nib.
}

public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);

string musicPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
OnStartUpdateLibrary(UpdateLibraryMode.SpecificFolder, null, musicPath);
}

partial void actionButtonClicked(NSObject sender)
{
if(button.Title(UIControlState.Normal) == "OK")
{
DismissViewController(true, null);
}
else
{
OnCancelUpdateLibrary();
}
}

#region IUpdateLibraryView implementation
Expand All @@ -56,6 +74,10 @@ public override void ViewDidLoad()

public void RefreshStatus(UpdateLibraryEntity entity)
{
InvokeOnMainThread(() => {
lblTitle.Text = entity.Title;
lblSubtitle.Text = entity.Subtitle;
});
}

public void AddToLog(string entry)
Expand All @@ -64,6 +86,13 @@ public void AddToLog(string entry)

public void ProcessEnded(bool canceled)
{
InvokeOnMainThread(() => {
lblTitle.Text = "Update library successful.";
lblSubtitle.Text = string.Empty;
button.SetTitle("OK", UIControlState.Normal);
activityIndicator.StopAnimating();
activityIndicator.Hidden = true;
});
}

#endregion
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 612f3c1

Please sign in to comment.