Skip to content

Commit

Permalink
iOS: CloudPreferences is now fully functional with new look similar t…
Browse files Browse the repository at this point in the history
…o Settings in iOS 7. Lots of bug fixes in preferences.
  • Loading branch information
ycastonguay committed Nov 14, 2013
1 parent 09fd31b commit 33cc168
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 225 deletions.
1 change: 1 addition & 0 deletions MPfm/MPfm.MVP/Config/Models/CloudAppConfig.cs
Expand Up @@ -23,6 +23,7 @@ namespace MPfm.MVP.Config.Models
public class CloudAppConfig : IAppConfig
{
public bool IsDropboxResumePlaybackEnabled { get; set; }
public bool IsDropboxResumePlaybackWifiOnlyEnabled { get; set; }

public CloudAppConfig()
{
Expand Down
90 changes: 30 additions & 60 deletions MPfm/MPfm.iOS/Classes/Controllers/AudioPreferencesViewController.cs
Expand Up @@ -25,13 +25,22 @@
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using System.Collections.Generic;
using MPfm.iOS.Classes.Objects;

namespace MPfm.iOS
{
public partial class AudioPreferencesViewController : BasePreferencesViewController, IAudioPreferencesView
{
string _cellIdentifier = "AudioPreferencesCell";
List<string> _items = new List<string>();
List<PreferenceCellItem> _items = new List<PreferenceCellItem>();

#region BasePreferencesViewController

public override string CellIdentifier { get { return _cellIdentifier; } }
public override UITableView TableView { get { return tableView; } }
public override List<PreferenceCellItem> Items { get { return _items; } }

#endregion

public AudioPreferencesViewController()
: base (UserInterfaceIdiomIsPhone ? "AudioPreferencesViewController_iPhone" : "AudioPreferencesViewController_iPad", null)
Expand All @@ -40,18 +49,7 @@ public AudioPreferencesViewController()

public override void ViewDidLoad()
{
tableView.WeakDataSource = this;
tableView.WeakDelegate = this;

_items.Add("Bacon");
_items.Add("Drumstick");

if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
{
NavigationController.InteractivePopGestureRecognizer.WeakDelegate = this;
NavigationController.InteractivePopGestureRecognizer.Enabled = true;
}

GenerateItems();
base.ViewDidLoad();

var navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
Expand All @@ -66,58 +64,30 @@ public override void ViewWillAppear(bool animated)
navCtrl.SetTitle("Audio Preferences");
}

// [Export ("tableView:viewForHeaderInSection:")]
// public UIView ViewForHeaderInSection(UITableView tableview, int section)
// {
// }

[Export ("tableView:titleForHeaderInSection:")]
public string TitleForHeaderInSection(UITableView tableview, int section)
{
return "Audio Mixer";
}

[Export ("numberOfSectionsInTableView:")]
public int SectionsInTableView(UITableView tableview)
private void GenerateItems()
{
return 1;
}

[Export ("tableView:numberOfRowsInSection:")]
public int RowsInSection(UITableView tableview, int section)
{
return _items.Count;
}

[Export ("tableView:cellForRowAtIndexPath:")]
public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var item = _items[indexPath.Row];
MPfmTableViewCell cell = (MPfmTableViewCell)tableView.DequeueReusableCell(_cellIdentifier);
if (cell == null)
// We assume the items are in order for sections
_items = new List<PreferenceCellItem>();
_items.Add(new PreferenceCellItem()
{
var cellStyle = UITableViewCellStyle.Subtitle;
cell = new MPfmTableViewCell(cellStyle, _cellIdentifier);
}

cell.Tag = indexPath.Row;
cell.TextLabel.Text = item;
cell.TextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 16);
cell.Accessory = UITableViewCellAccessory.None;

return cell;
Id = "login_dropbox",
CellType = PreferenceCellType.Button,
HeaderTitle = "Dropbox",
Title = "Login to Dropbox",
IconName = "dropbox"
});
_items.Add(new PreferenceCellItem()
{
Id = "enable_dropbox_resume_playback",
CellType = PreferenceCellType.Boolean,
HeaderTitle = "Dropbox",
FooterTitle = "This will take a small amount of bandwidth (about 1 kilobyte) every time the player switches to a new song.",
Title = "Enable Resume Playback"
});
}

[Export ("tableView:didSelectRowAtIndexPath:")]
public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
//OnSelectItem(_items[indexPath.Row]);
}

[Export ("tableView:heightForRowAtIndexPath:")]
public float HeightForRow(UITableView tableView, NSIndexPath indexPath)
public override void PreferenceValueChanged(PreferenceCellItem item)
{
return 52;
}
}
}
Expand Up @@ -22,14 +22,156 @@
using MonoTouch.UIKit;
using MPfm.MVP;
using MPfm.MVP.Views;
using System.Drawing;
using MPfm.iOS.Classes.Controls;
using MPfm.iOS.Classes.Objects;

namespace MPfm.iOS.Classes.Controllers.Base
{
public abstract class BasePreferencesViewController : BaseViewController
{
public abstract string CellIdentifier { get; }
public abstract UITableView TableView { get; }
public abstract List<PreferenceCellItem> Items { get; }

public abstract void PreferenceValueChanged(PreferenceCellItem item);

//string _cellIdentifier = "CloudPreferencesCell";
//List<PreferenceCellItem> _items;

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

public override void ViewDidLoad()
{
TableView.WeakDataSource = this;
TableView.WeakDelegate = this;
TableView.BackgroundColor = UIColor.FromRGB(0.85f, 0.85f, 0.85f);
TableView.BackgroundView = null;

if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
{
NavigationController.InteractivePopGestureRecognizer.WeakDelegate = this;
NavigationController.InteractivePopGestureRecognizer.Enabled = true;
}

base.ViewDidLoad();
}

[Export ("tableView:viewForHeaderInSection:")]
public UIView ViewForHeaderInSection(UITableView tableview, int section)
{
string sectionTitle = TitleForHeaderInSection(tableview, section);
if(string.IsNullOrEmpty(sectionTitle))
return null;

var label = new UILabel();
label.Frame = new RectangleF(12, 18, View.Frame.Width, 34);
label.BackgroundColor = UIColor.Clear;
label.TextColor = UIColor.FromRGB(0.5f, 0.5f, 0.5f);
label.Font = UIFont.FromName("HelveticaNeue", 14);
label.Text = sectionTitle;

var view = new UIView();
//view.BackgroundColor = UIColor.Yellow;
view.AddSubview(label);

return view;
}

[Export ("tableView:viewForFooterInSection:")]
public UIView ViewForFooterInSection(UITableView tableview, int section)
{
string sectionTitle = TitleForFooterInSection(tableview, section);
if(string.IsNullOrEmpty(sectionTitle))
return null;

var label = new UILabel();
label.Frame = new RectangleF(12, 4, View.Frame.Width - 24, 48);
label.BackgroundColor = UIColor.Clear;
label.TextColor = UIColor.FromRGB(0.5f, 0.5f, 0.5f);
label.Font = UIFont.FromName("HelveticaNeue-Light", 13);
label.Text = sectionTitle;
label.Lines = 3;

var view = new UIView();
//view.BackgroundColor = UIColor.Yellow;
view.AddSubview(label);

return view;
}

[Export ("tableView:titleForHeaderInSection:")]
public string TitleForHeaderInSection(UITableView tableview, int section)
{
var distinct = Items.Select(x => x.HeaderTitle).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();
return distinct[section].ToUpper();
}

[Export ("tableView:titleForFooterInSection:")]
public string TitleForFooterInSection(UITableView tableview, int section)
{
var distinct = Items.Select(x => x.FooterTitle).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();

if(distinct.Count > 0)
return distinct[section];

return string.Empty;
}

[Export ("numberOfSectionsInTableView:")]
public int SectionsInTableView(UITableView tableview)
{
var distinct = Items.Select(x => x.HeaderTitle).Distinct().ToList();
return distinct.Count;
}

[Export ("tableView:numberOfRowsInSection:")]
public int RowsInSection(UITableView tableview, int section)
{
var distinct = Items.Select(x => x.HeaderTitle).Distinct().ToList();
string headerTitle = distinct[section];
return Items.Count(x => x.HeaderTitle == headerTitle);
}

[Export ("tableView:cellForRowAtIndexPath:")]
public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var item = Items[indexPath.Row];
MPfmPreferenceTableViewCell cell = (MPfmPreferenceTableViewCell)tableView.DequeueReusableCell(CellIdentifier);
if (cell == null)
{
var cellStyle = UITableViewCellStyle.Subtitle;
cell = new MPfmPreferenceTableViewCell(cellStyle, CellIdentifier);
}

if (!string.IsNullOrEmpty(item.IconName))
{
cell.ImageView.Alpha = 0.7f;
cell.ImageView.Image = UIImage.FromBundle(string.Format("/Images/Icons/{0}", item.IconName));
}

cell.Tag = indexPath.Row;
cell.Accessory = UITableViewCellAccessory.None;
cell.SetItem(item);
cell.OnPreferenceValueChanged += PreferenceValueChanged;

return cell;
}

[Export ("tableView:heightForHeaderInSection:")]
public float HeightForHeaderInSection(UITableView tableView, int section)
{
return 52;
}

[Export ("tableView:heightForRowAtIndexPath:")]
public float HeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return 52;
}

}
}
14 changes: 12 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.cs
Expand Up @@ -21,6 +21,7 @@ public override void ViewDidLoad()
{
base.ViewDidLoad();

activityIndicator.StartAnimating();
btnOK.TitleLabel.Text = "Cancel";
btnOK.SetImage(UIImage.FromBundle("Images/Buttons/cancel"));
viewPanel.Layer.CornerRadius = 8;
Expand Down Expand Up @@ -55,20 +56,29 @@ public void RefreshStatus(CloudConnectEntity entity)
{
if(entity.HasAuthenticationFailed)
{
lblStatus.Text = "Authentication failed.";
lblStatus.Hidden = true;
lblStatusCenter.Hidden = false;
lblStatusCenter.Text = "Authentication failed.";
btnOK.TitleLabel.Text = "OK";
btnOK.SetImage(UIImage.FromBundle("Images/Buttons/select"));
btnOK.UpdateLayout();
activityIndicator.Hidden = true;
}
else if(entity.IsAuthenticated)
{
lblStatus.Text = "Authentication successful!";
lblStatus.Hidden = true;
lblStatusCenter.Hidden = false;
lblStatusCenter.Text = "Authentication successful!";
btnOK.TitleLabel.Text = "OK";
btnOK.SetImage(UIImage.FromBundle("Images/Buttons/select"));
btnOK.UpdateLayout();
activityIndicator.Hidden = true;
}
else
{
lblStatus.Hidden = false;
lblStatusCenter.Hidden = true;
}
});
}

Expand Down

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

0 comments on commit 33cc168

Please sign in to comment.