Skip to content

Commit

Permalink
iOS: More work for LibraryPreferencesViewCtrl and GeneralPrefrencesVi…
Browse files Browse the repository at this point in the history
…ewCtrl. Added new icons for preference buttons.
  • Loading branch information
ycastonguay committed Nov 17, 2013
1 parent 4cd99f6 commit 2f12277
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 43 deletions.
Expand Up @@ -174,8 +174,15 @@ public float HeightForHeaderInSection(UITableView tableView, int section)
[Export ("tableView:heightForRowAtIndexPath:")]
public float HeightForRow(UITableView tableView, NSIndexPath indexPath)
{
return 52;
}
var distinct = Items.Select(x => x.HeaderTitle).Distinct().ToList();
string headerTitle = distinct[indexPath.Section];
var items = Items.Where(x => x.HeaderTitle == headerTitle).ToList();
var item = items[indexPath.Row];

if (item.CellType == PreferenceCellType.Slider)
return 104;
else
return 52;
}
}
}
Expand Up @@ -85,19 +85,13 @@ private void GenerateItems()
FooterTitle = "Warning: Lower values require more CPU and memory."
});
_items.Add(new PreferenceCellItem()
{
Id = "peak_files_folder_size",
CellType = PreferenceCellType.Text,
HeaderTitle = "Peak Files",
Title = "Peak file folder size: 1425 MB"
});
_items.Add(new PreferenceCellItem()
{
Id = "delete_peak_files",
CellType = PreferenceCellType.Button,
HeaderTitle = "Peak Files",
Title = "Delete Peak Files",
IconName = "dropbox"
FooterTitle = "Peak file folder size: 1425 MB",
IconName = "delete"
});
}

Expand Down
114 changes: 94 additions & 20 deletions MPfm/MPfm.iOS/Classes/Controllers/LibraryPreferencesViewController.cs
Expand Up @@ -25,24 +25,34 @@
using MPfm.iOS.Classes.Controls;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using System.Collections.Generic;
using MPfm.iOS.Classes.Objects;
using System.Linq;

namespace MPfm.iOS
{
public partial class LibraryPreferencesViewController : BaseViewController, ILibraryPreferencesView
public partial class LibraryPreferencesViewController : BasePreferencesViewController, ILibraryPreferencesView
{
string _cellIdentifier = "CloudPreferencesCell";
//CloudAppConfig _config;
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 LibraryPreferencesViewController()
: base (UserInterfaceIdiomIsPhone ? "LibraryPreferencesViewController_iPhone" : "LibraryPreferencesViewController_iPad", null)
{
}

public override void ViewDidLoad()
{
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 @@ -57,20 +67,84 @@ public override void ViewWillAppear(bool animated)
navCtrl.SetTitle("Library Preferences");
}

// partial void actionResetLibrary(NSObject sender)
// {
// var alertView = new UIAlertView("Reset Library", "Are you sure you wish to reset your library?", null, "OK", new string[1]{"Cancel"});
// alertView.Clicked += (sender2, e) => {
// if(e.ButtonIndex == 0)
// OnResetLibrary();
// };
// alertView.Show();
// }
private void GenerateItems()
{
// We assume the items are in order for sections
_items = new List<PreferenceCellItem>();
_items.Add(new PreferenceCellItem()
{
Id = "sync_server_enabled",
CellType = PreferenceCellType.Boolean,
HeaderTitle = "Sync Service",
Title = "Enable Sync Service"
});
_items.Add(new PreferenceCellItem()
{
Id = "sync_server_port",
CellType = PreferenceCellType.Integer,
HeaderTitle = "Sync Service",
Title = "HTTP Port",
FooterTitle = "Note: The sync service is only used when Wi-Fi is available.",
Value = 53551
});
_items.Add(new PreferenceCellItem()
{
Id = "library_reset",
CellType = PreferenceCellType.Button,
HeaderTitle = "Library",
Title = "Reset Library",
IconName = "reset"
});
_items.Add(new PreferenceCellItem()
{
Id = "library_update",
CellType = PreferenceCellType.Button,
HeaderTitle = "Library",
Title = "Update Library",
FooterTitle = "Total library size: 8420 MB",
IconName = "update"
});
}

public override void PreferenceValueChanged(PreferenceCellItem item)
{
var localItem = _items.FirstOrDefault(x => x.Id == item.Id);
if (localItem == null)
return;

localItem.Value = item.Value;

// 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;
//
// partial void actionUpdateLibrary(NSObject sender)
// {
// OnUpdateLibrary();
// }
// OnSetCloudPreferences(_config);
}

[Export ("tableView:didSelectRowAtIndexPath:")]
public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
var distinct = _items.Select(x => x.HeaderTitle).Distinct().ToList();
string headerTitle = distinct[indexPath.Section];
var items = _items.Where(x => x.HeaderTitle == headerTitle).ToList();
var item = items[indexPath.Row];
tableView.DeselectRow(indexPath, true);

if (item.Id == "library_reset")
{
var alertView = new UIAlertView("Reset Library", "Are you sure you wish to reset your library?", null, "OK", new string[1]{"Cancel"});
alertView.Clicked += (sender2, e) => {
if(e.ButtonIndex == 0)
OnResetLibrary();
};
alertView.Show();
}
else if (item.Id == "library_update")
{
OnUpdateLibrary();
}
}

#region ILibraryPreferencesView implementation

Expand Down
46 changes: 39 additions & 7 deletions MPfm/MPfm.iOS/Classes/Controls/MPfmPreferenceTableViewCell.cs
Expand Up @@ -40,7 +40,8 @@ public class MPfmPreferenceTableViewCell : UITableViewCell
private bool _isTextLabelAllowedToChangeFrame = true;

public UIButton RightButton { get; private set; }
public UILabel LabelValue { get; private set; }
public UILabel ValueTextLabel { get; private set; }
public UISlider Slider { get; private set; }
public UISwitch Switch { get; private set; }

public MPfmPreferenceTableViewCell() : base()
Expand Down Expand Up @@ -82,11 +83,23 @@ public void Initialize()
DetailTextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 12);
ImageView.BackgroundColor = UIColor.Clear;

ValueTextLabel = new UILabel();
ValueTextLabel.BackgroundColor = UIColor.Clear;
ValueTextLabel.Font = UIFont.FromName("HelveticaNeue-Light", 16);
ValueTextLabel.TextColor = UIColor.Gray;
ValueTextLabel.TextAlignment = UITextAlignment.Right;
ValueTextLabel.HighlightedTextColor = UIColor.White;
AddSubview(ValueTextLabel);

RightButton = new UIButton(UIButtonType.Custom);
RightButton.Hidden = true;
RightButton.Frame = new RectangleF(screenSize.Width - Bounds.Height, 4, Bounds.Height, Bounds.Height);
AddSubview(RightButton);

Slider = new UISlider();
Slider.Hidden = true;
AddSubview(Slider);

Switch = new UISwitch();
//Switch.TintColor = GlobalTheme.SecondaryColor;
//Switch.ThumbTintColor = GlobalTheme.SecondaryColor;
Expand Down Expand Up @@ -116,15 +129,16 @@ public override void LayoutSubviews()
float x = 12;
if (ImageView.Image != null)
{
ImageView.Frame = new RectangleF(x, 10, 32, 32);
x += 40 + padding;
ImageView.Frame = new RectangleF(x, 14, 24, 24);
x += 32 + padding;
}

float titleY = 10 + 4;
if (!string.IsNullOrEmpty(DetailTextLabel.Text))
titleY = 2 + 4;

TextLabel.Frame = new RectangleF(x, titleY, textWidth - 52, 22);
ValueTextLabel.Frame = new RectangleF(0, titleY, Bounds.Width - 16, 22);

if (!string.IsNullOrEmpty(DetailTextLabel.Text))
DetailTextLabel.Frame = new RectangleF(x, 22 + 4, textWidth - 52, 16);
Expand All @@ -136,8 +150,10 @@ public override void LayoutSubviews()
Switch.ValueChanged += (sender, e) => {
_item.Value = Switch.On;
if(OnPreferenceValueChanged != null)
OnPreferenceValueChanged(_item);
OnPreferenceValueChanged(_item);
};

Slider.Frame = new RectangleF(12, 48, Bounds.Width - 24, 44);
}

public void SetItem(PreferenceCellItem item)
Expand All @@ -150,13 +166,29 @@ public void SetItem(PreferenceCellItem item)
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.CellType != PreferenceCellType.Text && item.Enabled ? UITableViewCellSelectionStyle.Default : UITableViewCellSelectionStyle.None;
Slider.Hidden = item.CellType != PreferenceCellType.Slider;
SelectionStyle = item.CellType != PreferenceCellType.Boolean && item.Enabled ? UITableViewCellSelectionStyle.Default : UITableViewCellSelectionStyle.None;

if (item.Value == null)
return;

if (item.CellType == PreferenceCellType.Boolean)
Switch.On = (bool)item.Value;
switch (item.CellType)
{
case PreferenceCellType.Button:
break;
case PreferenceCellType.Boolean:
Switch.On = (bool)item.Value;
break;
case PreferenceCellType.String:
break;
case PreferenceCellType.Integer:
ValueTextLabel.Text = ((int)item.Value).ToString();
break;
case PreferenceCellType.Slider:
break;
default:
throw new ArgumentOutOfRangeException();
}
}

public override void TouchesBegan(NSSet touches, UIEvent evt)
Expand Down
11 changes: 5 additions & 6 deletions MPfm/MPfm.iOS/Classes/Objects/PreferenceCellType.cs
Expand Up @@ -19,11 +19,10 @@ namespace MPfm.iOS.Classes.Objects
{
public enum PreferenceCellType
{
Text = 0,
Button = 1,
Boolean = 2,
String = 3,
Integer = 4,
Slider = 5
Button = 0,
Boolean = 1,
String = 2,
Integer = 3,
Slider = 4
}
}
Binary file added MPfm/MPfm.iOS/Images/Icons/delete.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.iOS/Images/Icons/delete@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.iOS/Images/Icons/reset.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.iOS/Images/Icons/reset@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.iOS/Images/Icons/update.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.iOS/Images/Icons/update@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions MPfm/MPfm.iOS/MPfm.iOS.csproj
Expand Up @@ -588,6 +588,12 @@
<BundleResource Include="Images\Tabs\albums%402x.png" />
<BundleResource Include="Images\Nav\albums.png" />
<BundleResource Include="Images\Nav\albums%402x.png" />
<BundleResource Include="Images\Icons\delete.png" />
<BundleResource Include="Images\Icons\delete%402x.png" />
<BundleResource Include="Images\Icons\reset.png" />
<BundleResource Include="Images\Icons\reset%402x.png" />
<BundleResource Include="Images\Icons\update.png" />
<BundleResource Include="Images\Icons\update%402x.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MPfm.Core\MPfm.Core.iOS.csproj">
Expand Down

0 comments on commit 2f12277

Please sign in to comment.