From 33cc168bfdd333d24886bce09a260c407db35fb9 Mon Sep 17 00:00:00 2001 From: ycastonguay Date: Thu, 14 Nov 2013 03:16:38 -0500 Subject: [PATCH] iOS: CloudPreferences is now fully functional with new look similar to Settings in iOS 7. Lots of bug fixes in preferences. --- MPfm/MPfm.MVP/Config/Models/CloudAppConfig.cs | 1 + .../AudioPreferencesViewController.cs | 90 +++------ .../Base/BasePreferencesViewController.cs | 142 ++++++++++++++ .../Controllers/CloudConnectViewController.cs | 14 +- .../CloudConnectViewController.designer.cs | 8 + .../CloudPreferencesViewController.cs | 181 ++++++------------ .../Controls/MPfmPreferenceTableViewCell.cs | 98 ++++++---- .../Classes/Controls/MPfmTableViewCell.cs | 4 +- .../Classes/Objects/PreferenceCellItem.cs | 39 ++++ .../Classes/Objects/PreferenceCellType.cs | 28 +++ MPfm/MPfm.iOS/Images/Icons/dropbox.png | Bin 0 -> 1802 bytes MPfm/MPfm.iOS/Images/Icons/dropbox@2x.png | Bin 0 -> 2928 bytes MPfm/MPfm.iOS/MPfm.iOS.csproj | 4 + .../iPad/CloudConnectViewController_iPad.xib | 8 + .../CloudConnectViewController_iPhone.xib | 10 +- 15 files changed, 402 insertions(+), 225 deletions(-) create mode 100644 MPfm/MPfm.iOS/Classes/Objects/PreferenceCellItem.cs create mode 100644 MPfm/MPfm.iOS/Classes/Objects/PreferenceCellType.cs create mode 100755 MPfm/MPfm.iOS/Images/Icons/dropbox.png create mode 100755 MPfm/MPfm.iOS/Images/Icons/dropbox@2x.png diff --git a/MPfm/MPfm.MVP/Config/Models/CloudAppConfig.cs b/MPfm/MPfm.MVP/Config/Models/CloudAppConfig.cs index 2fe4d38e..f7b0e1d7 100644 --- a/MPfm/MPfm.MVP/Config/Models/CloudAppConfig.cs +++ b/MPfm/MPfm.MVP/Config/Models/CloudAppConfig.cs @@ -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() { diff --git a/MPfm/MPfm.iOS/Classes/Controllers/AudioPreferencesViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/AudioPreferencesViewController.cs index 286add77..353841f2 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/AudioPreferencesViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/AudioPreferencesViewController.cs @@ -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 _items = new List(); + List _items = new List(); + + #region BasePreferencesViewController + + public override string CellIdentifier { get { return _cellIdentifier; } } + public override UITableView TableView { get { return tableView; } } + public override List Items { get { return _items; } } + + #endregion public AudioPreferencesViewController() : base (UserInterfaceIdiomIsPhone ? "AudioPreferencesViewController_iPhone" : "AudioPreferencesViewController_iPad", null) @@ -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(); @@ -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(); + _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; } } } diff --git a/MPfm/MPfm.iOS/Classes/Controllers/Base/BasePreferencesViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/Base/BasePreferencesViewController.cs index e3609db6..85d87327 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/Base/BasePreferencesViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/Base/BasePreferencesViewController.cs @@ -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 Items { get; } + + public abstract void PreferenceValueChanged(PreferenceCellItem item); + + //string _cellIdentifier = "CloudPreferencesCell"; + //List _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; + } + } } diff --git a/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.cs index e0fbc1cf..7fd48152 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.cs @@ -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; @@ -55,7 +56,9 @@ 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(); @@ -63,12 +66,19 @@ public void RefreshStatus(CloudConnectEntity entity) } 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; + } }); } diff --git a/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.designer.cs b/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.designer.cs index e770dbf0..2c6733d3 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.designer.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/CloudConnectViewController.designer.cs @@ -21,6 +21,9 @@ partial class CloudConnectViewController [Outlet] MonoTouch.UIKit.UILabel lblStatus { get; set; } + [Outlet] + MonoTouch.UIKit.UILabel lblStatusCenter { get; set; } + [Outlet] MonoTouch.UIKit.UIView viewPanel { get; set; } @@ -48,6 +51,11 @@ void ReleaseDesignerOutlets () viewPanel.Dispose (); viewPanel = null; } + + if (lblStatusCenter != null) { + lblStatusCenter.Dispose (); + lblStatusCenter = null; + } } } } diff --git a/MPfm/MPfm.iOS/Classes/Controllers/CloudPreferencesViewController.cs b/MPfm/MPfm.iOS/Classes/Controllers/CloudPreferencesViewController.cs index ef80ddd6..750e44f6 100644 --- a/MPfm/MPfm.iOS/Classes/Controllers/CloudPreferencesViewController.cs +++ b/MPfm/MPfm.iOS/Classes/Controllers/CloudPreferencesViewController.cs @@ -16,18 +16,18 @@ // along with MPfm. If not, see . using System; +using System.Collections.Generic; using System.Drawing; +using System.Linq; +using MPfm.MVP.Bootstrap; +using MPfm.MVP.Config.Models; using MPfm.MVP.Models; +using MPfm.MVP.Navigation; using MPfm.MVP.Views; using MonoTouch.Foundation; using MonoTouch.UIKit; using MPfm.iOS.Classes.Controllers.Base; -using MPfm.MVP.Config.Models; -using MPfm.MVP.Bootstrap; -using MPfm.MVP.Navigation; using MPfm.iOS.Classes.Controls; -using System.Collections.Generic; -using System.Linq; using MPfm.iOS.Classes.Objects; namespace MPfm.iOS @@ -36,7 +36,15 @@ public partial class CloudPreferencesViewController : BasePreferencesViewControl { string _cellIdentifier = "CloudPreferencesCell"; CloudAppConfig _config; - List _items; + List _items = new List(); + + #region BasePreferencesViewController + + public override string CellIdentifier { get { return _cellIdentifier; } } + public override UITableView TableView { get { return tableView; } } + public override List Items { get { return _items; } } + + #endregion public CloudPreferencesViewController() : base (UserInterfaceIdiomIsPhone ? "CloudPreferencesViewController_iPhone" : "CloudPreferencesViewController_iPad", null) @@ -45,22 +53,8 @@ public CloudPreferencesViewController() public override void ViewDidLoad() { - // TO DO: Move generic stuff to BasePreferencesVC - - tableView.WeakDataSource = this; - tableView.WeakDelegate = this; - - //tableView.SeparatorColor = GlobalTheme.BackgroundColor; - //tableView.BackgroundColor = GlobalTheme.BackgroundColor; - //tableView.BackgroundColor = GlobalTheme.LightColor; - tableView.BackgroundColor = UIColor.FromRGB(0.85f, 0.85f, 0.85f); - tableView.BackgroundView = null; - base.ViewDidLoad(); - //btnLoginDropbox.SetImage(UIImage.FromBundle("Images/Buttons/dropbox")); - GenerateItems(); - var navigationManager = Bootstrapper.GetContainer().Resolve(); navigationManager.BindCloudPreferencesView(this); } @@ -81,107 +75,53 @@ private void GenerateItems() { Id = "login_dropbox", CellType = PreferenceCellType.Button, - SectionTitle = "Dropbox", - Title = "Login to Dropbox" + HeaderTitle = "Dropbox", + Title = "Login to Dropbox", + IconName = "dropbox" }); _items.Add(new PreferenceCellItem() { Id = "enable_dropbox_resume_playback", CellType = PreferenceCellType.Boolean, - SectionTitle = "Dropbox", - Title = "Enable Resume Playback" + HeaderTitle = "Dropbox", + Title = "Enable Resume Playback", + Description = "Resume playback from other devices", + Value = _config.IsDropboxResumePlaybackEnabled }); _items.Add(new PreferenceCellItem() { - CellType = PreferenceCellType.Text, - SectionTitle = "Dropbox", - Title = "This will take a small amount of bandwidth (about 1 kilobyte) every time the player switches to a new song." + Id = "enable_dropbox_resume_playback_wifi_only", + CellType = PreferenceCellType.Boolean, + HeaderTitle = "Dropbox", + Title = "Synchronize only on Wi-Fi", + FooterTitle = "Resume Playback will take a small amount of bandwidth when the player switches to a new song (≈1kb/call).", + Value = _config.IsDropboxResumePlaybackWifiOnlyEnabled }); } - - [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:titleForHeaderInSection:")] - public string TitleForHeaderInSection(UITableView tableview, int section) - { - var distinct = _items.Select(x => x.SectionTitle).Distinct().ToList(); - return distinct[section].ToUpper(); - } - [Export ("numberOfSectionsInTableView:")] - public int SectionsInTableView(UITableView tableview) + public override void PreferenceValueChanged(PreferenceCellItem item) { - var distinct = _items.Select(x => x.SectionTitle).Distinct().ToList(); - return distinct.Count; - } + var localItem = _items.FirstOrDefault(x => x.Id == item.Id); + if (localItem == null) + return; - [Export ("tableView:numberOfRowsInSection:")] - public int RowsInSection(UITableView tableview, int section) - { - var distinct = _items.Select(x => x.SectionTitle).Distinct().ToList(); - string sectionTitle = distinct[section]; - return _items.Count(x => x.SectionTitle == sectionTitle); - } + localItem.Value = item.Value; - [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); - } - - cell.ImageView.Alpha = 0.7f; - if (item.CellType == PreferenceCellType.Button) - cell.ImageView.Image = UIImage.FromBundle("/Images/Icons/icon_cloud"); + if (item.Id == "enable_dropbox_resume_playback") + _config.IsDropboxResumePlaybackEnabled = (bool)item.Value; + else if (item.Id == "enable_dropbox_resume_playback_wifi_only") + _config.IsDropboxResumePlaybackWifiOnlyEnabled = (bool)item.Value; - cell.Tag = indexPath.Row; - cell.TextLabel.Text = item.Title; - cell.TextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 16); - cell.Accessory = UITableViewCellAccessory.None; - - return cell; + OnSetCloudPreferences(_config); } [Export ("tableView:didSelectRowAtIndexPath:")] public void RowSelected(UITableView tableView, NSIndexPath indexPath) { - //OnSelectItem(_items[indexPath.Row]); - } - - [Export ("tableView:heightForHeaderInSection:")] - public float HeightForHeaderInSection(UITableView tableView, int section) - { - return 52; - } - - [Export ("tableView:heightForRowAtIndexPath:")] - public float HeightForRow(UITableView tableView, NSIndexPath indexPath) - { - return 52; - } + var item = _items[indexPath.Row]; + if (item.Id == "login_dropbox") + OnDropboxLoginLogout(); + } #region ICloudPreferencesView implementation @@ -199,38 +139,29 @@ public void CloudPreferencesError(Exception ex) public void RefreshCloudPreferences(CloudAppConfig config) { _config = config; - - // Is there a way to get AppConfig properties and generate it into a flat list of settings with reflection? + InvokeOnMainThread(() => { + GenerateItems(); + tableView.ReloadData(); + }); } public void RefreshCloudPreferencesState(CloudPreferencesStateEntity entity) { InvokeOnMainThread(() => { - //btnLoginDropbox.TitleLabel.Text = entity.IsDropboxLinkedToApp ? "Logout from Dropbox" : "Login to Dropbox"; - //btnLoginDropbox.UpdateLayout(); + var itemLogin = _items.FirstOrDefault(x => x.Id == "login_dropbox"); + var itemEnableResumePlayback = _items.FirstOrDefault(x => x.Id == "enable_dropbox_resume_playback"); + var itemEnableResumePlaybackWifiOnly = _items.FirstOrDefault(x => x.Id == "enable_dropbox_resume_playback_wifi_only"); + if(itemLogin == null) + return; + + itemLogin.Title = entity.IsDropboxLinkedToApp ? "Logout from Dropbox" : "Login to Dropbox"; + itemEnableResumePlayback.Enabled = entity.IsDropboxLinkedToApp; + itemEnableResumePlaybackWifiOnly.Enabled = entity.IsDropboxLinkedToApp; + tableView.ReloadData(); }); } #endregion - } - - public enum PreferenceCellType - { - Text = 0, - Button = 1, - Boolean = 2, - String = 3, - Integer = 4, - Frequency = 5 - } - - public class PreferenceCellItem - { - public string Id { get; set; } - public PreferenceCellType CellType { get; set; } - public string SectionTitle { get; set; } - public string Title { get; set; } - public string Description { get; set; } - } + } } diff --git a/MPfm/MPfm.iOS/Classes/Controls/MPfmPreferenceTableViewCell.cs b/MPfm/MPfm.iOS/Classes/Controls/MPfmPreferenceTableViewCell.cs index 29e65c1b..e8baf482 100644 --- a/MPfm/MPfm.iOS/Classes/Controls/MPfmPreferenceTableViewCell.cs +++ b/MPfm/MPfm.iOS/Classes/Controls/MPfmPreferenceTableViewCell.cs @@ -33,7 +33,15 @@ namespace MPfm.iOS.Classes.Controls [Register("MPfmPreferenceTableViewCell")] public class MPfmPreferenceTableViewCell : UITableViewCell { + public delegate void PreferenceValueChanged(PreferenceCellItem item); + public event PreferenceValueChanged OnPreferenceValueChanged; + + private PreferenceCellItem _item; + private bool _isTextLabelAllowedToChangeFrame = true; + public UIButton RightButton { get; private set; } + public UILabel LabelValue { get; private set; } + public UISwitch Switch { get; private set; } public MPfmPreferenceTableViewCell() : base() { @@ -57,19 +65,21 @@ public void Initialize() UIView backView = new UIView(Frame); backView.BackgroundColor = GlobalTheme.LightColor; BackgroundView = backView; - BackgroundColor = UIColor.White; + //BackgroundColor = UIColor.White; UIView backViewSelected = new UIView(Frame); backViewSelected.BackgroundColor = GlobalTheme.SecondaryColor; SelectedBackgroundView = backViewSelected; - TextLabel.BackgroundColor = UIColor.FromWhiteAlpha(0, 0); - TextLabel.Font = UIFont.FromName("HelveticaNeue-Medium", 14); + //TextLabel.BackgroundColor = UIColor.FromWhiteAlpha(0, 0); + TextLabel.BackgroundColor = UIColor.Clear; + TextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 16); TextLabel.TextColor = UIColor.Black; TextLabel.HighlightedTextColor = UIColor.White; + DetailTextLabel.BackgroundColor = UIColor.Clear; DetailTextLabel.TextColor = UIColor.Gray; DetailTextLabel.HighlightedTextColor = UIColor.White; - DetailTextLabel.Font = UIFont.FromName("HelveticaNeue", 12); + DetailTextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 12); ImageView.BackgroundColor = UIColor.Clear; RightButton = new UIButton(UIButtonType.Custom); @@ -77,6 +87,11 @@ public void Initialize() RightButton.Frame = new RectangleF(screenSize.Width - Bounds.Height, 4, Bounds.Height, Bounds.Height); AddSubview(RightButton); + Switch = new UISwitch(); + //Switch.TintColor = GlobalTheme.SecondaryColor; + //Switch.ThumbTintColor = GlobalTheme.SecondaryColor; + AddSubview(Switch); + // Make sure the text label is over all other subviews TextLabel.RemoveFromSuperview(); AddSubview(TextLabel); @@ -98,30 +113,49 @@ public override void LayoutSubviews() if (RightButton.ImageView.Image != null) textWidth -= 44 + padding; - float x = 4; + float x = 12; if (ImageView.Image != null) { - ImageView.Frame = new RectangleF(x, 6, 40, 40); + ImageView.Frame = new RectangleF(x, 10, 32, 32); x += 40 + padding; - } - else - { - x += padding; } float titleY = 10 + 4; if (!string.IsNullOrEmpty(DetailTextLabel.Text)) titleY = 2 + 4; - TextLabel.Frame = new RectangleF(x, titleY, textWidth, 22); + TextLabel.Frame = new RectangleF(x, titleY, textWidth - 52, 22); + if (!string.IsNullOrEmpty(DetailTextLabel.Text)) - DetailTextLabel.Frame = new RectangleF(x, 22 + 4, textWidth, 16); + DetailTextLabel.Frame = new RectangleF(x, 22 + 4, textWidth - 52, 16); if (RightButton.ImageView.Image != null || !string.IsNullOrEmpty(RightButton.Title(UIControlState.Normal))) RightButton.Frame = new RectangleF(screenSize.Width - 44, 4, 44, 44); + Switch.Frame = new RectangleF(screenSize.Width - 66, 10, 60, 44); + Switch.ValueChanged += (sender, e) => { + _item.Value = Switch.On; + if(OnPreferenceValueChanged != null) + OnPreferenceValueChanged(_item); + }; } + public void SetItem(PreferenceCellItem item) + { + _item = item; + BackgroundView.BackgroundColor = item.Enabled ? UIColor.White : UIColor.FromRGB(0.95f, 0.95f, 0.95f); + TextLabel.Text = item.Title; + TextLabel.TextColor = item.Enabled ? UIColor.Black : UIColor.FromRGB(0.7f, 0.7f, 0.7f); + DetailTextLabel.Text = item.Description; + DetailTextLabel.TextColor = item.Enabled ? UIColor.Gray : UIColor.FromRGB(0.85f, 0.85f, 0.85f); + Switch.Hidden = item.CellType != PreferenceCellType.Boolean; + Switch.Enabled = item.Enabled; + SelectionStyle = item.CellType != PreferenceCellType.Boolean && item.Enabled ? UITableViewCellSelectionStyle.Default : UITableViewCellSelectionStyle.None; + + if(item.CellType == PreferenceCellType.Boolean) + Switch.On = (bool)item.Value; + } + public override void TouchesBegan(NSSet touches, UIEvent evt) { AnimatePress(true); @@ -142,35 +176,29 @@ public override void TouchesCancelled(NSSet touches, UIEvent evt) private void AnimatePress(bool on) { + //if (!IsTextAnimationEnabled) + // return; + + _isTextLabelAllowedToChangeFrame = !on; + if (!on) { - UIView.Animate(0.2, () => { - //BackgroundColor = GlobalTheme.SecondaryColor; - // if (LabelAlignment == UIControlContentHorizontalAlignment.Left) - // TitleLabel.Frame = new RectangleF(TitleLabel.Frame.X + 8, TitleLabel.Frame.Y, TitleLabel.Frame.Width, TitleLabel.Frame.Height); - // else if (LabelAlignment == UIControlContentHorizontalAlignment.Right) - // TitleLabel.Frame = new RectangleF(TitleLabel.Frame.X - 4, TitleLabel.Frame.Y, TitleLabel.Frame.Width, TitleLabel.Frame.Height); - - //TextLabel.Frame = new RectangleF(TextLabel.Frame.X - 26, TextLabel.Frame.Y, TextLabel.Frame.Width, TextLabel.Frame.Height); - //Console.WriteLine(">>>>>>>>>>> TVC - Scale 1"); - if(TextLabel.Transform.xx < 0.95f) return; // Ignore when scale is lower; it was done on purpose and will be restored to 1 later. + UIView.Animate(0.1, 0, UIViewAnimationOptions.CurveEaseIn, () => { + // Ignore when scale is lower; it was done on purpose and will be restored to 1 later. + if(TextLabel.Transform.xx < 0.95f) return; + TextLabel.Transform = CGAffineTransform.MakeScale(1, 1); - //Image.Transform = CGAffineTransform.MakeScale(1, 1); - }); + DetailTextLabel.Transform = CGAffineTransform.MakeScale(1, 1); + ImageView.Transform = CGAffineTransform.MakeScale(1, 1); + }, null); } else { - UIView.Animate(0.2, () => { - //BackgroundColor = GlobalTheme.SecondaryDarkColor; - //Console.WriteLine(">>>>>>>>>>> TVC - Scale 0.95f"); - TextLabel.Transform = CGAffineTransform.MakeScale(0.9f, 0.9f); - //Image.Transform = CGAffineTransform.MakeScale(0.9f, 0.9f); - //TextLabel.Frame = new RectangleF(TextLabel.Frame.X + 26, TextLabel.Frame.Y, TextLabel.Frame.Width, TextLabel.Frame.Height); - // if(LabelAlignment == UIControlContentHorizontalAlignment.Left) - //TitleLabel.Frame = new RectangleF(TitleLabel.Frame.X - 8, TitleLabel.Frame.Y, TitleLabel.Frame.Width, TitleLabel.Frame.Height); - // else if(LabelAlignment == UIControlContentHorizontalAlignment.Right) - // TitleLabel.Frame = new RectangleF(TitleLabel.Frame.X + 4, TitleLabel.Frame.Y, TitleLabel.Frame.Width, TitleLabel.Frame.Height); - }); + UIView.Animate(0.1, 0, UIViewAnimationOptions.CurveEaseIn, () => { + TextLabel.Transform = CGAffineTransform.MakeScale(0.96f, 0.96f); + DetailTextLabel.Transform = CGAffineTransform.MakeScale(0.96f, 0.96f); + ImageView.Transform = CGAffineTransform.MakeScale(0.9f, 0.9f); + }, null); } } } diff --git a/MPfm/MPfm.iOS/Classes/Controls/MPfmTableViewCell.cs b/MPfm/MPfm.iOS/Classes/Controls/MPfmTableViewCell.cs index 982a738b..4313fe5e 100644 --- a/MPfm/MPfm.iOS/Classes/Controls/MPfmTableViewCell.cs +++ b/MPfm/MPfm.iOS/Classes/Controls/MPfmTableViewCell.cs @@ -33,6 +33,8 @@ namespace MPfm.iOS.Classes.Controls [Register("MPfmTableViewCell")] public class MPfmTableViewCell : UITableViewCell { + private bool _isTextLabelAllowedToChangeFrame = true; + public UILabel IndexTextLabel { get; private set; } public UIButton RightButton { get; private set; } public UIImageView RightImage { get; private set; } @@ -318,8 +320,6 @@ public override void TouchesCancelled(NSSet touches, UIEvent evt) base.TouchesCancelled(touches, evt); } - private bool _isTextLabelAllowedToChangeFrame = true; - private void AnimatePress(bool on) { if (!IsTextAnimationEnabled) diff --git a/MPfm/MPfm.iOS/Classes/Objects/PreferenceCellItem.cs b/MPfm/MPfm.iOS/Classes/Objects/PreferenceCellItem.cs new file mode 100644 index 00000000..53133889 --- /dev/null +++ b/MPfm/MPfm.iOS/Classes/Objects/PreferenceCellItem.cs @@ -0,0 +1,39 @@ +// 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 . + +using MonoTouch.UIKit; + +namespace MPfm.iOS.Classes.Objects +{ + public class PreferenceCellItem + { + public string Id { get; set; } + public PreferenceCellType CellType { get; set; } + public string Title { get; set; } + public string HeaderTitle { get; set; } + public string FooterTitle { get; set; } + public string Description { get; set; } + public string IconName { get; set; } + public object Value { get; set; } + public bool Enabled { get; set; } + + public PreferenceCellItem() + { + Enabled = true; + } + } +} diff --git a/MPfm/MPfm.iOS/Classes/Objects/PreferenceCellType.cs b/MPfm/MPfm.iOS/Classes/Objects/PreferenceCellType.cs new file mode 100644 index 00000000..5f13352e --- /dev/null +++ b/MPfm/MPfm.iOS/Classes/Objects/PreferenceCellType.cs @@ -0,0 +1,28 @@ +// 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 . + +namespace MPfm.iOS.Classes.Objects +{ + public enum PreferenceCellType + { + Button = 0, + Boolean = 1, + String = 2, + Integer = 3, + Frequency = 4 + } +} diff --git a/MPfm/MPfm.iOS/Images/Icons/dropbox.png b/MPfm/MPfm.iOS/Images/Icons/dropbox.png new file mode 100755 index 0000000000000000000000000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M?V84h?)X$|gNtw(ig+!oI3cslc0=33kLsl1FwUEOooZ*6L3E&aCP zc7y3eUnjR3UH0!1rzf50xA9!tUMCegBROGjzmM3-t5+{0L5WDRReTB5vkj${YRxqkk6KyccgQ}K^ZFZa0cbph+{ zH=-wR9=Wux*syTzOJ6OfDXX-Om52wNn7=o~a`Qa1y|y9RE7qH;%{7|J*R8feYESr` ztkUD#Kgs&-{K~2>Y88EA`lXiJA;HZbyjA7H{;gQ*)zWG4Pj`;#zgb_Im)pqItE}X_ zX)^nJf}#JJ%vJvn3(FRYK5w^5tDkj>HAuwzPdBsA9M7HY`c|iOzO4WI`rCE}W`>=L VN%OMrt1SoBPM)rQF6*2UngAYCxUv8M literal 0 HcmV?d00001 diff --git a/MPfm/MPfm.iOS/Images/Icons/dropbox@2x.png b/MPfm/MPfm.iOS/Images/Icons/dropbox@2x.png new file mode 100755 index 0000000000000000000000000000000000000000..aad19fe1715e15666ad88caaa6806eb1e6fbaa28 GIT binary patch literal 2928 zcmaJ@c|25mA0D~UMOv1oby{g&+~k@=Z_QP?6`Hg(t0HX0BD2G+;X~*p258?`H}i1ck-(gOGF%b1&oyFwv#{}2hCi>phX=};64aO`ayfyTrz5+vKobCv&bkwBMt#vG$@Yua7!>jg1l~tR{hgE- z!x?GI6F^8j8fyY#30NcnKm#~4B9Ul}G{pi~4Av9_n3@1Y63&!_#Uj5xC|NWC%b(;* zrG1ShJCRWVFw7@mF#GrKNAJg>d4jzdz{0{}QNz^KM20XC9^k@EkqKA0>6-!-5`qFY zA7=Bo$VEk_A1?$Zqhy)>T>^*yU6w2S+9p}UFd`-&1E8^sC4B=j82=y2;e1C6VOQv% zeE+Ag(ER`(!ni_0UWfpc4bFelVkkbzRsbmM%gL++vxIDA=TDkNZsLM)nq$3cE6n8f~JE?B!C>V4(1ewYiE z_Cqd4mJDWbtp7FUZ&xz!EN;J>R(AMqdx$IZx?O?+uF0--oWr&8QSJ!3v$MX7FT zzMdfl5?7a|cn4icy3zp{uR_-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CtBxxh&(1*+r1C}D)U5NcAN_e?lKOaSlu=_he)tX5?;9UQ*ZdHe*I%JK5C}7 z@G*tqN_}Lz!jPD-n0(MIguBRpx2`88_YENUz86kTTh0$lA2c}U&%Rv!@Y(Y;gIEKC$%03!%3bPRs~q`>7dr2f z;%Br|9X%YmeQxs|2#mf!-e9QHIZ?^6y?o)G8_QaAJw|bE&)7Xi%EYa?P1N}=I zLe51x+-57cbOOzlr}JFHYxTcq^CAUiubGW=ceudWwn z*Qz?aUy=OTn~~^S6@_!0nTpyv91f;w_5R_yTyH5##8NslWZ3OxQWsLKn^GZn($mG? zd8iRz;rco_KG4-v*t#*bbf1=yJuT?%6mdyvT6qZu$t%!_Qp?D`tZw;eYMlR!+Nf2rR^>c9yw?e3A?G1Jog6Z*FvGaLQ> ze4)`RPHEhc**9AGo8-t|)m;xMti;vpNY8gu%{<#FfyZ;wy8|Be7_X6#-dSUJzuT|@ zdvR`!jD(U&xZ%z~imekU!e=}r&W?WkZkGo!=+FlqH; zZBh*k<;ep)#JW$3JBd4wv)So&!NSC OV7i?n^@`2!NB;v{wE{~3 literal 0 HcmV?d00001 diff --git a/MPfm/MPfm.iOS/MPfm.iOS.csproj b/MPfm/MPfm.iOS/MPfm.iOS.csproj index b91e5ec3..594fc5b9 100644 --- a/MPfm/MPfm.iOS/MPfm.iOS.csproj +++ b/MPfm/MPfm.iOS/MPfm.iOS.csproj @@ -325,6 +325,8 @@ MPfmCollectionViewCell.cs + + @@ -578,6 +580,8 @@ + + diff --git a/MPfm/MPfm.iOS/XIB/iPad/CloudConnectViewController_iPad.xib b/MPfm/MPfm.iOS/XIB/iPad/CloudConnectViewController_iPad.xib index 75b0c175..31b19cb6 100644 --- a/MPfm/MPfm.iOS/XIB/iPad/CloudConnectViewController_iPad.xib +++ b/MPfm/MPfm.iOS/XIB/iPad/CloudConnectViewController_iPad.xib @@ -10,6 +10,7 @@ + @@ -45,6 +46,13 @@ + diff --git a/MPfm/MPfm.iOS/XIB/iPhone/CloudConnectViewController_iPhone.xib b/MPfm/MPfm.iOS/XIB/iPhone/CloudConnectViewController_iPhone.xib index c9ff8a45..2e1de515 100644 --- a/MPfm/MPfm.iOS/XIB/iPhone/CloudConnectViewController_iPhone.xib +++ b/MPfm/MPfm.iOS/XIB/iPhone/CloudConnectViewController_iPhone.xib @@ -10,6 +10,7 @@ + @@ -41,7 +42,14 @@ +