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 00000000..7367565f Binary files /dev/null and b/MPfm/MPfm.iOS/Images/Icons/dropbox.png differ 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 00000000..aad19fe1 Binary files /dev/null and b/MPfm/MPfm.iOS/Images/Icons/dropbox@2x.png differ 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 @@ +