Skip to content

Commit

Permalink
iOS: AppConfigProvider is now completed; saving key/value preferences…
Browse files Browse the repository at this point in the history
… locally and on iCloud. Also added Dropbox Sync API to the project; all you can do for now is sign in, but it works!

Related to issue #406.
  • Loading branch information
ycastonguay committed Oct 15, 2013
1 parent de1f853 commit 3b64a4e
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 3 deletions.
7 changes: 7 additions & 0 deletions MPfm/MPfm.iOS/Classes/Controllers/MoreViewController.cs
Expand Up @@ -34,6 +34,7 @@
using MPfm.iOS.Classes.Controls;
using MPfm.iOS.Classes.Objects;
using MPfm.iOS.Helpers;
using DropBoxSync.iOS;

namespace MPfm.iOS
{
Expand Down Expand Up @@ -124,6 +125,12 @@ public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
[Export ("tableView:didSelectRowAtIndexPath:")]
public void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
if (_items[indexPath.Row].Key == MobileOptionsMenuType.SyncLibraryCloud)
{
DBAccountManager.SharedManager.LinkFromController(this);
return;
}

OnItemClick(_items[indexPath.Row].Key);
}

Expand Down
35 changes: 34 additions & 1 deletion MPfm/MPfm.iOS/Classes/Delegates/AppDelegate.cs
Expand Up @@ -33,6 +33,7 @@
using MPfm.iOS.Classes.Objects;
using MPfm.iOS.Classes.Providers;
using MPfm.iOS.Helpers;
using DropBoxSync.iOS;

namespace MPfm.iOS.Classes.Delegates
{
Expand All @@ -41,7 +42,10 @@ namespace MPfm.iOS.Classes.Delegates
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
{
private string _dropboxAppKey = "6tc6565743i743n";
private string _dropboxAppSecret = "fbkt3neevjjl0l2";

MPfmWindow _window;
MPfmTabBarController _tabBarController;
SplashViewController _splashViewController;
Expand Down Expand Up @@ -70,6 +74,8 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
UITabBar.Appearance.TintColor = UIColor.White;
UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;

RegisterDropbox();

_window = new MPfmWindow(UIScreen.MainScreen.Bounds);
_window.TintColor = GlobalTheme.SecondaryColor;

Expand Down Expand Up @@ -249,5 +255,32 @@ public void PushDialogSubview(MobileDialogPresentationType presentationType, str
navCtrl.PushViewController(viewController, true);
});
}

public void RegisterDropbox()
{
// The account manager stores all the account info. Create this when your app launches
var manager = new DBAccountManager (_dropboxAppKey, _dropboxAppSecret);
DBAccountManager.SharedManager = manager;

var account = manager.LinkedAccount;
if (account != null) {
var filesystem = new DBFilesystem (account);
DBFilesystem.SharedFilesystem = filesystem;
}
}

public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
var account = DBAccountManager.SharedManager.HandleOpenURL (url);
if (account != null) {
var filesystem = new DBFilesystem (account);
DBFilesystem.SharedFilesystem = filesystem;
Console.WriteLine ("App linked successfully!");
return true;
} else {
Console.WriteLine ("App is not linked");
return false;
}
}
}
}
89 changes: 88 additions & 1 deletion MPfm/MPfm.iOS/Classes/Providers/iOSAppConfigProvider.cs
Expand Up @@ -17,18 +17,105 @@

using MPfm.MVP.Config;
using MPfm.MVP.Config.Providers;
using System.Reflection;
using System.Diagnostics;
using MonoTouch.Foundation;

namespace MPfm.iOS.Classes.Providers
{
public class iOSAppConfigProvider : IAppConfigProvider
{
public RootAppConfig Load(string filePath)
{
return new RootAppConfig();
var config = new RootAppConfig();
config.IsFirstRun = false;
SaveRecursive(config, "Root.");
config.IsFirstRun = true;
LoadRecursive(config, "Root.");
return config;
}

public void Save(string filePath, RootAppConfig config)
{
SaveRecursive(config, "Root.");
}

private void LoadRecursive(IAppConfig config, string keyPreset)
{
// Create map by scanning properties
var keyStore = NSUbiquitousKeyValueStore.DefaultStore;
var propertyInfos = config.GetType().GetTypeInfo().DeclaredProperties;
foreach (PropertyInfo propertyInfo in propertyInfos)
{
var propertyType = propertyInfo.PropertyType;
string fullName = keyPreset + propertyInfo.Name;
bool isAssignable = typeof(IAppConfig).GetTypeInfo().IsAssignableFrom(propertyType.GetTypeInfo());
//Debug.WriteLine("{0} - {1} - isAssignable: {2}", fullName, propertyInfo.PropertyType.Name, isAssignable);

if (propertyType == typeof(int))
{
propertyInfo.SetValue(config, (int)keyStore.GetLong(fullName));
}
else if (propertyType == typeof(bool))
{
propertyInfo.SetValue(config, keyStore.GetBool(fullName));
}
else if (propertyType == typeof(double))
{
propertyInfo.SetValue(config, keyStore.GetDouble(fullName));
}
else if (propertyType == typeof(float))
{
propertyInfo.SetValue(config, (float)keyStore.GetDouble(fullName));
}
else if (propertyType == typeof(string))
{
propertyInfo.SetValue(config, keyStore.GetString(fullName));
}
else if (typeof(IAppConfig).GetTypeInfo().IsAssignableFrom(propertyType.GetTypeInfo()))
{
var subConfig = (IAppConfig)propertyInfo.GetValue(config);
LoadRecursive(subConfig, keyPreset + propertyType.Name + ".");
}
}
}

private void SaveRecursive(IAppConfig config, string keyPreset)
{
// Create map by scanning properties
var keyStore = NSUbiquitousKeyValueStore.DefaultStore;
var propertyInfos = config.GetType().GetTypeInfo().DeclaredProperties;
foreach (PropertyInfo propertyInfo in propertyInfos)
{
var propertyType = propertyInfo.PropertyType;
string fullName = keyPreset + propertyInfo.Name;
object value = propertyInfo.GetValue(config);
bool isAssignable = typeof (IAppConfig).GetTypeInfo().IsAssignableFrom(propertyType.GetTypeInfo());
//Debug.WriteLine("{0} - {1} - isAssignable: {2}", fullName, propertyInfo.PropertyType.Name, isAssignable);

if (propertyType == typeof(int))
{
keyStore.SetLong(fullName, (long)(int)value);
}
else if (propertyType == typeof(bool))
{
keyStore.SetBool(fullName, (bool)value);
}
else if (propertyType == typeof(double) || (propertyType == typeof(float)))
{
keyStore.SetDouble(fullName, System.Convert.ToDouble(value));
}
else if (propertyType == typeof(string))
{
string stringValue = value == null ? string.Empty : (string)value;
keyStore.SetString(fullName, stringValue);
}
else if (typeof (IAppConfig).GetTypeInfo().IsAssignableFrom(propertyType.GetTypeInfo()))
{
var subConfig = (IAppConfig)propertyInfo.GetValue(config);
SaveRecursive(subConfig, keyPreset + propertyType.Name + ".");
}
}
}
}
}
9 changes: 9 additions & 0 deletions MPfm/MPfm.iOS/Info.plist
Expand Up @@ -69,5 +69,14 @@
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>db-6tc6565743i743n</string>
</array>
</dict>
</array>
</dict>
</plist>
11 changes: 10 additions & 1 deletion MPfm/MPfm.iOS/MPfm.iOS.csproj
Expand Up @@ -56,7 +56,6 @@
<MtouchArch>ARMv7</MtouchArch>
<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 />
<CodesignProvision>5C51C790-BB21-4F44-BECA-051A853109C6</CodesignProvision>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
Expand Down Expand Up @@ -110,6 +109,9 @@
<Reference Include="TinyIoC">
<HintPath>..\MPfm.Core\Lib\iOS\TinyIoC.dll</HintPath>
</Reference>
<Reference Include="DropBoxSync.iOS">
<HintPath>..\Components\dropboxsync-1.9.1\lib\ios\DropBoxSync.iOS.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
Expand Down Expand Up @@ -521,4 +523,11 @@
<ITunesArtwork Include="iTunesArtwork" />
<ITunesArtwork Include="iTunesArtwork%402x" />
</ItemGroup>
<ItemGroup>
<XamarinComponentReference Include="dropboxsync">
<InstallationInProgress>True</InstallationInProgress>
<Version>1.9.1</Version>
<Visible>False</Visible>
</XamarinComponentReference>
</ItemGroup>
</Project>

0 comments on commit 3b64a4e

Please sign in to comment.