Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
iOS: Customized UINavigationController with new look and back button …
…functionality.

iOS: Added album art to list of songs in Mobile Library Browser.
iOS: Added icons and new fonts.

Related to issue #405 and issue #408.
  • Loading branch information
ycastonguay committed Feb 24, 2013
1 parent 4c81348 commit aaec148
Show file tree
Hide file tree
Showing 37 changed files with 1,244 additions and 376 deletions.
3 changes: 3 additions & 0 deletions MPfm/MPfm.MVP/Models/LibraryBrowserEntity.cs
Expand Up @@ -16,6 +16,7 @@
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System.Collections.Generic;
using MPfm.Sound.AudioFiles;

namespace MPfm.MVP.Models
{
Expand All @@ -40,6 +41,8 @@ public class LibraryBrowserEntity
/// Sub items (to create a tree view hierarchy).
/// </summary>
public List<LibraryBrowserEntity> SubItems { get; set; }

public AudioFile AudioFile { get; set; }

public LibraryBrowserEntity()
{
Expand Down
20 changes: 11 additions & 9 deletions MPfm/MPfm.MVP/Presenters/MobileLibraryBrowserPresenter.cs
Expand Up @@ -109,21 +109,25 @@ private void OnItemClick(int i)
private void RefreshLibraryBrowser()
{
_items = new List<LibraryBrowserEntity>();

switch (_browserType)
{
case MobileLibraryBrowserType.Playlists:
View.RefreshLibraryBrowser(_items, _browserType, "Playlists");
break;
case MobileLibraryBrowserType.Artists:
_items = GetArtists().ToList();
View.RefreshLibraryBrowser(_items, _browserType, "Artists");
break;
case MobileLibraryBrowserType.Albums:
_items = GetAlbums(_query.ArtistName).ToList();
_items = GetAlbums(_query.ArtistName).ToList();
View.RefreshLibraryBrowser(_items, _browserType, (String.IsNullOrEmpty(_query.ArtistName)) ? "Albums" : _query.ArtistName);
break;
case MobileLibraryBrowserType.Songs:
_items = GetSongs(_query.ArtistName, _query.AlbumTitle).ToList();
_items = GetSongs(_query.ArtistName, _query.AlbumTitle).ToList();
View.RefreshLibraryBrowser(_items, _browserType, (String.IsNullOrEmpty(_query.AlbumTitle)) ? "Songs" : _query.AlbumTitle);
break;
}
View.RefreshLibraryBrowser(_items);
}

private IEnumerable<LibraryBrowserEntity> GetArtists()
Expand Down Expand Up @@ -201,22 +205,20 @@ private IEnumerable<LibraryBrowserEntity> GetSongs(string artistName, string alb
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)
foreach (var audioFile in audioFiles)
{
list.Add(new LibraryBrowserEntity()
{
Title = song,
Title = audioFile.Title,
AudioFile = audioFile,
Type = LibraryBrowserEntityType.Song,
Query = new SongBrowserQueryEntity()
{
Format = format,
ArtistName = artistName,
AlbumTitle = albumTitle,
SearchTerms = song
SearchTerms = audioFile.Title
}
});
}
Expand Down
9 changes: 7 additions & 2 deletions MPfm/MPfm.MVP/Presenters/PlayerPresenter.cs
Expand Up @@ -77,6 +77,10 @@ public PlayerPresenter(ITinyMessengerHub messageHub, IPlayerService playerServic
{
Play(audioFileCacheService.SelectAudioFiles(m.Query), m.FilePath);
});
messageHub.Subscribe<PlayerPlaylistIndexChangedMessage>((PlayerPlaylistIndexChangedMessage m) =>
{
RefreshSongInformation(m.Data.AudioFileStarted);
});
}

public void Dispose()
Expand Down Expand Up @@ -105,14 +109,15 @@ void HandleTimerRefreshSongPositionElapsed(object sender, ElapsedEventArgs e)
if(playerService.IsSettingPosition)
return;

int available = playerService.GetDataAvailable();
//int available = playerService.GetDataAvailable();

// Create entity
PlayerPositionEntity entity = new PlayerPositionEntity();
entity.PositionBytes = playerService.GetPosition();
entity.PositionSamples = ConvertAudio.ToPCM(entity.PositionBytes, (uint)playerService.CurrentPlaylistItem.AudioFile.BitsPerSample, 2);
entity.PositionMS = (int)ConvertAudio.ToMS(entity.PositionSamples, (uint)playerService.CurrentPlaylistItem.AudioFile.SampleRate);
entity.Position = available.ToString() + " " + Conversion.MillisecondsToTimeString((ulong)entity.PositionMS);
//entity.Position = available.ToString() + " " + Conversion.MillisecondsToTimeString((ulong)entity.PositionMS);
entity.Position = Conversion.MillisecondsToTimeString((ulong)entity.PositionMS);
entity.PositionPercentage = ((float)playerService.GetPosition() / (float)playerService.CurrentPlaylistItem.LengthBytes) * 100;

// Send changes to view
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.MVP/Views/IMobileLibraryBrowserView.cs
Expand Up @@ -28,7 +28,7 @@ public interface IMobileLibraryBrowserView : IBaseView
{
Action<int> OnItemClick { get; set; }

void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities);
void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities, MobileLibraryBrowserType browserType, string navigationBarTitle);
}

public enum MobileLibraryBrowserType
Expand Down
3 changes: 3 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controllers/Base/BaseViewController.cs
Expand Up @@ -60,6 +60,9 @@ public override void ViewDidDisappear(bool animated)
public override void ViewDidLoad()
{
base.ViewDidLoad();

this.NavigationItem.SetHidesBackButton(true, true);

OnViewReady(this);
}

Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.iOS/Classes/Controllers/LoopsViewController.cs
Expand Up @@ -33,7 +33,7 @@ public LoopsViewController(Action<IBaseView> onViewReady)

public override void ViewDidLoad()
{
this.View.BackgroundColor = UIColor.Green;
lblTitle.Font = UIFont.FromName("OstrichSans-Black", 28);

base.ViewDidLoad();
}
Expand Down
25 changes: 16 additions & 9 deletions MPfm/MPfm.iOS/Classes/Controllers/LoopsViewController.designer.cs

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

2 changes: 1 addition & 1 deletion MPfm/MPfm.iOS/Classes/Controllers/MarkersViewController.cs
Expand Up @@ -33,7 +33,7 @@ public MarkersViewController(Action<IBaseView> onViewReady)

public override void ViewDidLoad()
{
this.View.BackgroundColor = UIColor.Blue;
lblTitle.Font = UIFont.FromName("OstrichSans-Black", 28);

base.ViewDidLoad();
}
Expand Down

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

Expand Up @@ -26,13 +26,18 @@
using MPfm.MVP.Views;
using MPfm.MVP.Models;
using System.Linq;
using MPfm.Sound.AudioFiles;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;

namespace MPfm.iOS.Classes.Controllers
{
public partial class MobileLibraryBrowserViewController : BaseViewController, IMobileLibraryBrowserView
{
private List<LibraryBrowserEntity> _items;
private string _cellIdentifier = "MobileLibraryBrowserCell";
private string _navigationBarTitle = string.Empty;
private MobileLibraryBrowserType _browserType;

public MobileLibraryBrowserViewController(Action<IBaseView> onViewReady)
: base (onViewReady, UserInterfaceIdiomIsPhone ? "MobileLibraryBrowserViewController_iPhone" : "MobileLibraryBrowserViewController_iPad", null)
Expand All @@ -45,6 +50,19 @@ public override void ViewDidLoad()
tableView.WeakDataSource = this;
tableView.WeakDelegate = this;

lblArtistName.Font = UIFont.FromName("OstrichSans-Black", 20);
lblAlbumTitle.Font = UIFont.FromName("OstrichSans-Black", 16);
lblSubtitle1.Font = UIFont.FromName("OstrichSans-Black", 12);
lblSubtitle2.Font = UIFont.FromName("OstrichSans-Black", 12);


//lblArtistName.SizeToFit();
//lblAlbumTitle.SizeToFit();
// lblArtistName.Font = UIFont.FromName("LeagueGothic-Italic", 26);
// lblAlbumTitle.Font = UIFont.FromName("LeagueGothic-Italic", 22);
// lblSubtitle1.Font = UIFont.FromName("LeagueGothic-Regular", 16);
// lblSubtitle2.Font = UIFont.FromName("LeagueGothic-Regular", 16);

base.ViewDidLoad();
}

Expand All @@ -53,7 +71,7 @@ public override void ViewWillAppear(bool animated)
base.ViewWillAppear(animated);

MPfmNavigationController navCtrl = (MPfmNavigationController)this.NavigationController;
navCtrl.SetTitle("Library Browser");
navCtrl.SetSubtitle(_navigationBarTitle);
}

public override void ViewDidDisappear(bool animated)
Expand All @@ -77,6 +95,8 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)

// Set cell style
var cellStyle = UITableViewCellStyle.Subtitle;
if (_browserType == MobileLibraryBrowserType.Albums)
cellStyle = UITableViewCellStyle.Default;

// Create cell if cell could not be recycled
if (cell == null)
Expand All @@ -85,26 +105,19 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
// Set title
cell.TextLabel.Text = _items[indexPath.Row].Title;
//cell.DetailTextLabel.Text = _items[indexPath.Row].
//cell.ImageView.Image = _items[indexPath.Row].Image;

if (_browserType == MobileLibraryBrowserType.Albums)
cell.ImageView.Image = UIImage.FromBundle("Images/icon114");

// Set font
//cell.TextLabel.Font = UIFont.FromName("Junction", 20);
cell.TextLabel.Font = UIFont.FromName("OstrichSans-Medium", 26);
cell.DetailTextLabel.Font = UIFont.FromName("OstrichSans-Medium", 18);
cell.TextLabel.Font = UIFont.FromName("OstrichSans-Medium", 20);
//cell.TextLabel.Font = UIFont.FromName("LeagueGothic-Regular", 26);
//cell.DetailTextLabel.Font = UIFont.FromName("LeagueGothic-Regular", 18);

// Set chevron
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

// // Check this is the version cell (remove all user interaction)
// if (viewModel.Items[indexPath.Row].ItemType == MoreItemType.Version)
// {
// cell.Accessory = UITableViewCellAccessory.None;
// cell.SelectionStyle = UITableViewCellSelectionStyle.None;
// cell.TextLabel.TextColor = UIColor.Gray;
// cell.TextLabel.TextAlignment = UITextAlignment.Center;
// cell.TextLabel.Font = UIFont.FromName("Asap", 16);
// }

return cell;
}

Expand All @@ -116,15 +129,50 @@ public void RowSelected(UITableView tableView, NSIndexPath indexPath)

#region IMobileLibraryBrowserView implementation

public MobileLibraryBrowserType BrowserType { get; set; }
public string Filter { get; set; }
public Action<int> OnItemClick { get; set; }

public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities)
public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities, MobileLibraryBrowserType browserType, string navigationBarTitle)
{
InvokeOnMainThread(() => {
_items = entities.ToList();
_browserType = browserType;
_navigationBarTitle = navigationBarTitle;
tableView.ReloadData();
// Hide album cover if not showing songs
if(browserType != MobileLibraryBrowserType.Songs)
{
viewAlbumCover.Hidden = true;
tableView.Frame = this.View.Frame;
}
else
{
var audioFile = _items[0].AudioFile;
lblArtistName.Text = audioFile.ArtistName;
lblAlbumTitle.Text = audioFile.AlbumTitle;
lblSubtitle1.Text = _items.Count().ToString() + " songs";
//CGSize s = [yourString sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
NSString strArtistName = new NSString(audioFile.ArtistName);
SizeF sizeArtistName = strArtistName.StringSize(lblArtistName.Font, new SizeF(lblArtistName.Frame.Width, lblArtistName.Frame.Height), UILineBreakMode.WordWrap);
lblArtistName.Frame = new RectangleF(lblArtistName.Frame.X, lblArtistName.Frame.Y, sizeArtistName.Width, sizeArtistName.Height);
NSString strAlbumTitle = new NSString(audioFile.AlbumTitle);
SizeF sizeAlbumTitle = strAlbumTitle.StringSize(lblAlbumTitle.Font, new SizeF(lblAlbumTitle.Frame.Width, lblAlbumTitle.Frame.Height), UILineBreakMode.WordWrap);
lblAlbumTitle.Frame = new RectangleF(lblAlbumTitle.Frame.X, lblAlbumTitle.Frame.Y, sizeAlbumTitle.Width, sizeAlbumTitle.Height);
// TODO: Add a memory cache and stop reloading the image from disk every time
byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath);
NSData imageData = NSData.FromArray(bytesImage);
UIImage image = UIImage.LoadFromData(imageData);
imageViewAlbumCover.Image = image;
imageViewAlbumCover.BackgroundColor = UIColor.Black;
CAGradientLayer gradient = new CAGradientLayer();
gradient.Frame = viewAlbumCover.Bounds;
gradient.Colors = new MonoTouch.CoreGraphics.CGColor[2] { new CGColor(0.1f, 0.1f, 0.1f, 1), new CGColor(0.4f, 0.4f, 0.4f, 1) }; //[NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
viewAlbumCover.Layer.InsertSublayer(gradient, 0);
}
});
}

Expand Down

0 comments on commit aaec148

Please sign in to comment.