Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
iOS: Added custom class based on UITableViewCell.
Related to issue #405.
  • Loading branch information
ycastonguay committed Mar 6, 2013
1 parent 9aa5ce7 commit 3e5a9ce
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 36 deletions.
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/Presenters/MobileLibraryBrowserPresenter.cs
Expand Up @@ -238,6 +238,7 @@ private IEnumerable<LibraryBrowserEntity> GetSongs(string artistName, string alb
list.Add(new LibraryBrowserEntity()
{
Title = audioFile.Title,
Subtitle = audioFile.Length,
AudioFile = audioFile,
Type = LibraryBrowserEntityType.Song,
Query = new SongBrowserQueryEntity()
Expand Down
Expand Up @@ -98,65 +98,41 @@ public int RowsInSection(UITableView tableview, int section)
public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
// Request a recycled cell to save memory
UITableViewCell cell = tableView.DequeueReusableCell(_cellIdentifier);
MPfmTableViewCell cell = (MPfmTableViewCell)tableView.DequeueReusableCell(_cellIdentifier);

// Set cell style
var cellStyle = UITableViewCellStyle.Subtitle;

// Create cell if cell could not be recycled
if (cell == null)
cell = new UITableViewCell(cellStyle, _cellIdentifier);

// Create selected cell background view
UIView backView = new UIView(cell.Frame);
CAGradientLayer gradient = new CAGradientLayer();
gradient.Frame = cell.Bounds;
gradient.Colors = new MonoTouch.CoreGraphics.CGColor[2] { new CGColor(1.0f, 1.0f, 1.0f, 1), new CGColor(0.95f, 0.95f, 0.95f, 1) }; //[NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
backView.Layer.InsertSublayer(gradient, 0);
cell.BackgroundView = backView;

// Create selected cell background view
UIView backViewSelected = new UIView(cell.Frame);
CAGradientLayer gradientSelected = new CAGradientLayer();
gradientSelected.Frame = cell.Bounds;
gradientSelected.Colors = new MonoTouch.CoreGraphics.CGColor[2] { new CGColor(0.6f, 0.6f, 0.6f, 1), new CGColor(0.4f, 0.4f, 0.4f, 1) }; //[NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
backViewSelected.Layer.InsertSublayer(gradientSelected, 0);
cell.SelectedBackgroundView = backViewSelected;
cell = new MPfmTableViewCell(cellStyle, _cellIdentifier);

// Set title
cell.Tag = indexPath.Row;
cell.TextLabel.BackgroundColor = UIColor.Clear;
cell.TextLabel.Text = _items[indexPath.Row].Title;
cell.DetailTextLabel.Text = _items[indexPath.Row].Subtitle;

// Set subtitle/image if necessary
if (_browserType == MobileLibraryBrowserType.Albums)
{
cell.DetailTextLabel.BackgroundColor = UIColor.Clear;
cell.DetailTextLabel.TextColor = UIColor.Gray;
cell.DetailTextLabel.HighlightedTextColor = UIColor.White;
cell.DetailTextLabel.Font = UIFont.FromName("OstrichSans-Medium", 16);
cell.DetailTextLabel.Text = _items[indexPath.Row].Subtitle;
cell.ImageView.BackgroundColor = UIColor.White;
cell.ImageView.Frame = new RectangleF(0, 0, 44, 44);

// Check if album art is cached
string key = _items[indexPath.Row].Query.ArtistName + "_" + _items[indexPath.Row].Query.AlbumTitle;
string key = _items [indexPath.Row].Query.ArtistName + "_" + _items [indexPath.Row].Query.AlbumTitle;
KeyValuePair<string, UIImage> keyPair = _imageCache.FirstOrDefault(x => x.Key == key);
if(keyPair.Equals(default(KeyValuePair<string, UIImage>)))
if (keyPair.Equals(default(KeyValuePair<string, UIImage>)))
{
cell.ImageView.Image = UIImage.FromBundle("Images/emptyalbumart");
OnRequestAlbumArt(_items[indexPath.Row].Query.ArtistName, _items[indexPath.Row].Query.AlbumTitle);
}
OnRequestAlbumArt(_items [indexPath.Row].Query.ArtistName, _items [indexPath.Row].Query.AlbumTitle);
}
else
{
cell.ImageView.Image = keyPair.Value;
}
}
else if (_browserType == MobileLibraryBrowserType.Songs)
{
cell.IndexTextLabel.Text = _items[indexPath.Row].AudioFile.TrackNumber.ToString();
}

// Set font
cell.TextLabel.Font = UIFont.FromName("OstrichSans-Medium", 20);
cell.TextLabel.TextColor = UIColor.Black;
cell.TextLabel.HighlightedTextColor = UIColor.White;
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

return cell;
Expand Down
105 changes: 105 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controls/MPfmTableViewCell.cs
@@ -0,0 +1,105 @@
// 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 System.Drawing;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;

namespace MPfm.iOS.Classes.Controls
{
[Register("MPfmTableViewCell")]
public class MPfmTableViewCell : UITableViewCell
{
public UILabel IndexTextLabel { get; private set; }

public MPfmTableViewCell() : base()
{
Initialize();
}

public MPfmTableViewCell(RectangleF frame) : base(frame)
{
Initialize();
}

public MPfmTableViewCell(UITableViewCellStyle style, string reuseIdentifier) : base(style, reuseIdentifier)
{
Initialize();
}

public void Initialize()
{
// Create selected cell background view
UIView backView = new UIView(Frame);
CAGradientLayer gradient = new CAGradientLayer();
gradient.Frame = Bounds;
gradient.Colors = new MonoTouch.CoreGraphics.CGColor[2] { new CGColor(1.0f, 1.0f, 1.0f, 1), new CGColor(0.95f, 0.95f, 0.95f, 1) };
backView.Layer.InsertSublayer(gradient, 0);
BackgroundView = backView;

// Create selected cell background view
UIView backViewSelected = new UIView(Frame);
CAGradientLayer gradientSelected = new CAGradientLayer();
gradientSelected.Frame = Bounds;
gradientSelected.Colors = new MonoTouch.CoreGraphics.CGColor[2] { new CGColor(0.6f, 0.6f, 0.6f, 1), new CGColor(0.4f, 0.4f, 0.4f, 1) };
backViewSelected.Layer.InsertSublayer(gradientSelected, 0);
SelectedBackgroundView = backViewSelected;

TextLabel.BackgroundColor = UIColor.Clear;
TextLabel.Font = UIFont.FromName("OstrichSans-Medium", 20);
TextLabel.TextColor = UIColor.Black;
TextLabel.HighlightedTextColor = UIColor.White;
DetailTextLabel.BackgroundColor = UIColor.Clear;
DetailTextLabel.TextColor = UIColor.Gray;
DetailTextLabel.HighlightedTextColor = UIColor.White;
DetailTextLabel.Font = UIFont.FromName("OstrichSans-Medium", 16);
ImageView.BackgroundColor = UIColor.White;

IndexTextLabel = new UILabel();
IndexTextLabel.BackgroundColor = UIColor.Clear;
IndexTextLabel.Font = UIFont.FromName("OstrichSans-Black", 20);
IndexTextLabel.TextColor = UIColor.Black;
IndexTextLabel.HighlightedTextColor = UIColor.White;
AddSubview(IndexTextLabel);
}

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

// Check for subtitle
if (!string.IsNullOrEmpty(DetailTextLabel.Text))
{
TextLabel.Frame = new RectangleF(53, 4, Bounds.Width - 106, 22);
DetailTextLabel.Frame = new RectangleF(53, 24, Bounds.Width - 53, 16);
}
if (!string.IsNullOrEmpty(IndexTextLabel.Text))
{
TextLabel.Frame = new RectangleF(33, 4, Bounds.Width - 106, 22);
DetailTextLabel.Frame = new RectangleF(33, 24, Bounds.Width - 53, 16);
IndexTextLabel.Frame = new RectangleF(12, 4, 22, 38);
}
}
}
}
3 changes: 2 additions & 1 deletion MPfm/MPfm.iOS/MPfm.iOS.csproj
Expand Up @@ -56,7 +56,7 @@
<MtouchI18n />
<MtouchArch>ARMv7</MtouchArch>
<MtouchExtraArgs>-v -v -v -gcc_flags "-L${ProjectDir}/Lib/ -framework Accelerate -ObjC -lstdc++ -lbass -lbassmix -lbass_fx -lbass_ape -lbass_mpc -lbassflac -lbasswv -all_load"</MtouchExtraArgs>
<CodesignProvision>5C51C790-BB21-4F44-BECA-051A853109C6</CodesignProvision>
<CodesignProvision>1DD1E6B7-C93C-4B7E-BC11-47742877E8E0</CodesignProvision>
<CrashReportingApiKey />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
Expand Down Expand Up @@ -174,6 +174,7 @@
<Compile Include="Classes\Controls\MPfmWindow.cs" />
<Compile Include="Classes\Controls\MPfmWaveFormView.cs" />
<Compile Include="Classes\Helpers\DarwinHardwareHelper.cs" />
<Compile Include="Classes\Controls\MPfmTableViewCell.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="XIB\iPhone\SplashViewController_iPhone.xib" />
Expand Down

0 comments on commit 3e5a9ce

Please sign in to comment.