Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
iOS: Replaced PreferencesViewControllers controls to table views. Fix…
…ed several bugs in PreferencesBaseViewController.
  • Loading branch information
ycastonguay committed Nov 16, 2013
1 parent 33cc168 commit 2e4dd1f
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 620 deletions.
Expand Up @@ -69,25 +69,53 @@ private void GenerateItems()
// We assume the items are in order for sections
_items = new List<PreferenceCellItem>();
_items.Add(new PreferenceCellItem()
{
{
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"
Title = "Enable Resume Playback",
Description = "Resume playback from other devices"
});
_items.Add(new PreferenceCellItem()
{
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)."
});
}

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;
//
// OnSetCloudPreferences(_config);
}

[Export ("tableView:didSelectRowAtIndexPath:")]
public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
// var item = _items[indexPath.Row];
// if (item.Id == "login_dropbox")
// OnDropboxLoginLogout();
}
}
}
Expand Up @@ -115,7 +115,7 @@ 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)
if(distinct.Count > 0 && section <= distinct.Count - 1)
return distinct[section];

return string.Empty;
Expand All @@ -139,12 +139,17 @@ public int RowsInSection(UITableView tableview, int section)
[Export ("tableView:cellForRowAtIndexPath:")]
public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var item = Items[indexPath.Row];
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];

MPfmPreferenceTableViewCell cell = (MPfmPreferenceTableViewCell)tableView.DequeueReusableCell(CellIdentifier);
if (cell == null)
{
var cellStyle = UITableViewCellStyle.Subtitle;
cell = new MPfmPreferenceTableViewCell(cellStyle, CellIdentifier);
cell.OnPreferenceValueChanged += PreferenceValueChanged;
}

if (!string.IsNullOrEmpty(item.IconName))
Expand All @@ -156,7 +161,6 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
cell.Tag = indexPath.Row;
cell.Accessory = UITableViewCellAccessory.None;
cell.SetItem(item);
cell.OnPreferenceValueChanged += PreferenceValueChanged;

return cell;
}
Expand Down
Expand Up @@ -24,26 +24,33 @@
using MPfm.iOS.Classes.Controllers.Base;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.iOS.Classes.Objects;
using System.Collections.Generic;

namespace MPfm.iOS
{
public partial class GeneralPreferencesViewController : BaseViewController, IGeneralPreferencesView
public partial class GeneralPreferencesViewController : BasePreferencesViewController, IGeneralPreferencesView
{
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 GeneralPreferencesViewController()
: base (UserInterfaceIdiomIsPhone ? "GeneralPreferencesViewController_iPhone" : "GeneralPreferencesViewController_iPad", null)
{
}

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

//btn.SetImage(UIImage.FromBundle("Images/Buttons/cancel"));

GenerateItems();
base.ViewDidLoad();

var navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
Expand All @@ -57,5 +64,65 @@ public override void ViewWillAppear(bool animated)
MPfmNavigationController navCtrl = (MPfmNavigationController)this.NavigationController;
navCtrl.SetTitle("General Preferences");
}

private void GenerateItems()
{
// We assume the items are in order for sections
_items = new List<PreferenceCellItem>();
_items.Add(new PreferenceCellItem()
{
Id = "update_frequency_song_position",
CellType = PreferenceCellType.Frequency,
HeaderTitle = "Update Frequency",
Title = "Song Position"
});
_items.Add(new PreferenceCellItem()
{
Id = "update_frequency_output_meter",
CellType = PreferenceCellType.Frequency,
HeaderTitle = "Update Frequency",
Title = "Output Meter",
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"
});
}

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;
//
// OnSetCloudPreferences(_config);
}

[Export ("tableView:didSelectRowAtIndexPath:")]
public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
// var item = _items[indexPath.Row];
// if (item.Id == "login_dropbox")
// OnDropboxLoginLogout();
}
}
}

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

Expand Up @@ -43,9 +43,6 @@ public override void ViewDidLoad()
NavigationController.InteractivePopGestureRecognizer.Enabled = true;
}

btnResetLibrary.SetImage(UIImage.FromBundle("Images/Buttons/reset"));
btnUpdateLibrary.SetImage(UIImage.FromBundle("Images/Buttons/refresh"));

base.ViewDidLoad();

var navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
Expand All @@ -60,20 +57,20 @@ 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();
}

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

#region ILibraryPreferencesView implementation

Expand Down

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

7 changes: 5 additions & 2 deletions MPfm/MPfm.iOS/Classes/Controls/MPfmPreferenceTableViewCell.cs
Expand Up @@ -150,9 +150,12 @@ 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.Enabled ? UITableViewCellSelectionStyle.Default : UITableViewCellSelectionStyle.None;
SelectionStyle = item.CellType != PreferenceCellType.Boolean && item.CellType != PreferenceCellType.Text && item.Enabled ? UITableViewCellSelectionStyle.Default : UITableViewCellSelectionStyle.None;

if(item.CellType == PreferenceCellType.Boolean)
if (item.Value == null)
return;

if (item.CellType == PreferenceCellType.Boolean)
Switch.On = (bool)item.Value;
}

Expand Down
11 changes: 6 additions & 5 deletions MPfm/MPfm.iOS/Classes/Objects/PreferenceCellType.cs
Expand Up @@ -19,10 +19,11 @@ namespace MPfm.iOS.Classes.Objects
{
public enum PreferenceCellType
{
Button = 0,
Boolean = 1,
String = 2,
Integer = 3,
Frequency = 4
Text = 0,
Button = 1,
Boolean = 2,
String = 3,
Integer = 4,
Frequency = 5
}
}
2 changes: 1 addition & 1 deletion MPfm/MPfm.iOS/MPfm.iOS.csproj
Expand Up @@ -26,7 +26,7 @@
<MtouchI18n>
</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>
<MtouchExtraArgs>-v -v -v --compiler=clang -gcc_flags "-L${ProjectDir}/Lib/ -framework Accelerate -framework AudioToolbox -ObjC -lstdc++ -lbass -lbassmix -lbass_fx -lbass_ape -lbass_mpc -lbassflac -lbasswv -all_load"</MtouchExtraArgs>
<CrashReportingApiKey>
</CrashReportingApiKey>
</PropertyGroup>
Expand Down

0 comments on commit 2e4dd1f

Please sign in to comment.