Skip to content

Commit

Permalink
iOS: Added new screens, renamed Prototype screen to Player. Added emb…
Browse files Browse the repository at this point in the history
…edded fonts. Added a generic ListViewController, and more.

Related to issue #405.

git-svn-id: http://hamster-svn/svn/repos/base@680 765c1f7c-9fb8-954f-9ff8-dd0915cb3117
  • Loading branch information
animal committed Jan 17, 2013
1 parent 6b27ab8 commit 39ec49f
Show file tree
Hide file tree
Showing 26 changed files with 1,360 additions and 228 deletions.
51 changes: 0 additions & 51 deletions MPfm/branches/current/MPfm.iOS/Classes/AppDelegate.cs

This file was deleted.

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MPfm.MVP;

namespace MPfm.iOS
{
public abstract class BaseViewController : UIViewController//, IBaseView
{
//public Action OnViewDestroy { get; set; } // Is this useful on iOS?
//protected Action<IBaseView> OnViewReady { get; set; }

public BaseViewController(string nibName, NSBundle bundle)
: base(nibName, bundle)
{
}

// public void ShowView(bool shown)
// {
// this.View.Hidden = !shown;
// }
}
}

@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace MPfm.iOS
{
public partial class ListViewController : BaseViewController
{
private UIBarButtonItem btnBack;
private Action<GenericListItem> actionOnItemSelected;
private ListTableViewSource tableViewSource;
private string title;
public List<GenericListItem> Items { get; private set; }

static bool UserInterfaceIdiomIsPhone
{
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}

public ListViewController(string title, List<GenericListItem> items, Action<GenericListItem> actionOnItemSelected)
: base (UserInterfaceIdiomIsPhone ? "ListViewController_iPhone" : "ListViewController_iPad", null)
{
if (this.TabBarItem != null)
{
this.TabBarItem.Title = title;
this.TabBarItem.Image = UIImage.FromBundle("Images/Tabs/more");
}
this.title = title;
this.Items = items;
this.actionOnItemSelected = actionOnItemSelected;
}

public override void DidReceiveMemoryWarning()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning();

// Release any cached data, images, etc that aren't in use.
}

public override void ViewDidLoad()
{
base.ViewDidLoad();

// // Set NavCtrl title if available
// if(this.NavigationController != null)
// this.NavigationController.Title = this.TabBarItem.Title;

// Create text attributes for navigation bar button
UITextAttributes attr = new UITextAttributes();
attr.Font = UIFont.FromName("OstrichSans-Black", 16);
attr.TextColor = UIColor.White;
attr.TextShadowColor = UIColor.DarkGray;
attr.TextShadowOffset = new UIOffset(0, 0);

// Set back button for navigation bar
btnBack = new UIBarButtonItem(title, UIBarButtonItemStyle.Plain, null, null);
btnBack.SetTitleTextAttributes(attr, UIControlState.Normal);
this.NavigationItem.BackBarButtonItem = btnBack;

// Load data source
tableViewSource = new ListTableViewSource(Items, actionOnItemSelected);
tableView.Source = tableViewSource;
}

public override void ViewDidUnload()
{
base.ViewDidUnload();

// Clear any references to subviews of the main view in order to
// allow the Garbage Collector to collect them sooner.
//
// e.g. myOutlet.Dispose (); myOutlet = null;

ReleaseDesignerOutlets();
}

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

MPfmNavigationController navCtrl = (MPfmNavigationController)this.NavigationController;
navCtrl.SetTitle(title);
}

public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
if (UserInterfaceIdiomIsPhone)
{
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
} else
{
return true;
}
}
}
}

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

Expand Up @@ -11,10 +11,11 @@
using MPfm.Sound;
using MPfm.Core;
using System.Linq;
using MonoTouch.CoreGraphics;

namespace MPfm.iOS
{
public partial class MPfm_iOSViewController : UIViewController
public partial class PlayerViewController : BaseViewController
{
private IPlayer player;
private Timer timer;
Expand All @@ -23,8 +24,8 @@ public partial class MPfm_iOSViewController : UIViewController
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}

public MPfm_iOSViewController ()
: base (UserInterfaceIdiomIsPhone ? "MPfm_iOSViewController_iPhone" : "MPfm_iOSViewController_iPad", null)
public PlayerViewController()
: base (UserInterfaceIdiomIsPhone ? "PlayerViewController_iPhone" : "PlayerViewController_iPad", null)
{
}

Expand All @@ -39,7 +40,21 @@ public override void DidReceiveMemoryWarning ()
public override void ViewDidLoad()
{
base.ViewDidLoad();

// Set fonts
lblArtistName.Font = UIFont.FromName("OstrichSans-Black", 28);
lblAlbumTitle.Font = UIFont.FromName("OstrichSans-Medium", 24);
lblTitle.Font = UIFont.FromName("OstrichSans-Medium", 18);
lblPosition.Font = UIFont.FromName("OstrichSans-Black", 18);
lblLength.Font = UIFont.FromName("OstrichSans-Black", 18);
btnPrevious.Font = UIFont.FromName("OstrichSans-Black", 18);
btnPlayPause.Font = UIFont.FromName("OstrichSans-Black", 18);
btnNext.Font = UIFont.FromName("OstrichSans-Black", 18);

// Reduce the song position slider size
sliderPosition.Transform = CGAffineTransform.MakeScale(0.7f, 0.7f);
sliderPosition.Frame = new RectangleF(70, sliderPosition.Frame.Y, 180, sliderPosition.Frame.Height);

timer = new Timer();
timer.Interval = 100;
timer.Elapsed += (sender, e) => {
Expand All @@ -50,7 +65,7 @@ public override void ViewDidLoad()
long samples = ConvertAudio.ToPCM(bytes, (uint)MPfm.Player.Player.CurrentPlayer.Playlist.CurrentItem.AudioFile.BitsPerSample, 2);
long ms = ConvertAudio.ToMS(samples, (uint)MPfm.Player.Player.CurrentPlayer.Playlist.CurrentItem.AudioFile.SampleRate);
string pos = Conversion.MillisecondsToTimeString((ulong)ms);
lblPosition.Text = pos + " / " + player.Playlist.CurrentItem.LengthString;
lblPosition.Text = pos;
sliderPosition.Value = ms;
} catch
{
Expand Down Expand Up @@ -79,6 +94,14 @@ public override void ViewDidUnload ()

ReleaseDesignerOutlets ();
}

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

MPfmNavigationController navCtrl = (MPfmNavigationController)this.NavigationController;
navCtrl.SetTitle("Now Playing");
}

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
Expand All @@ -90,19 +113,21 @@ public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientat
}
}

private void RefreshAudioFile(AudioFile audioFile)
private void RefreshAudioFile(AudioFile audioFile, bool isSameAlbum)
{
InvokeOnMainThread(() => {
byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath);
NSData imageData = NSData.FromArray(bytesImage);
UIImage image = UIImage.LoadFromData(imageData);
if(!isSameAlbum)
{
byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath);
NSData imageData = NSData.FromArray(bytesImage);
UIImage image = UIImage.LoadFromData(imageData);
imageViewAlbumArt.Image = image;
}
lblArtistName.Text = audioFile.ArtistName;
lblAlbumTitle.Text = audioFile.AlbumTitle;
lblTitle.Text = audioFile.Title;
imageViewAlbumArt.Image = image;
lblLength.Text = player.Playlist.CurrentItem.LengthString;
sliderPosition.MaxValue = player.Playlist.CurrentItem.LengthMilliseconds;
});
}
Expand All @@ -129,27 +154,26 @@ private void Play()
}

player.OnPlaylistIndexChanged += (data) => {
RefreshAudioFile(data.AudioFileStarted);
if(data.AudioFileEnded != null &&
data.AudioFileEnded.ArtistName == data.AudioFileStarted.ArtistName &&
data.AudioFileEnded.AlbumTitle == data.AudioFileStarted.AlbumTitle)
{
RefreshAudioFile(data.AudioFileStarted, true);
}
else
{
RefreshAudioFile(data.AudioFileStarted, false);
}
};
timer.Start();
RefreshAudioFile(player.Playlist.CurrentItem.AudioFile);
}

partial void actionPlay(NSObject sender)
{
player.Play();
RefreshAudioFile(player.Playlist.CurrentItem.AudioFile, false);
}

partial void actionPause(NSObject sender)
{
player.Pause();
}

partial void actionStop(NSObject sender)
{
player.Stop();
}

partial void actionPrevious(NSObject sender)
{
player.Previous();
Expand Down

0 comments on commit 39ec49f

Please sign in to comment.