Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First hack at getting suspend/resume running

  • Loading branch information...
commit ea8d8345b88df3b18ead98b4eb90b04f6fa95ee5 1 parent 4947103
Paul Betts paulcbetts authored
39 iOSPlayground/AppBootstrapper.cs
View
@@ -0,0 +1,39 @@
+using System;
+using ReactiveUI;
+using ReactiveUI.Mobile;
+using ReactiveUI.Routing;
+using System.Runtime.Serialization;
+using TinyIoC;
+using MonoTouch.UIKit;
+
+namespace iOSPlayground
+{
+ public class AppBootstrapper : ReactiveObject, IApplicationRootState
+ {
+ [IgnoreDataMember]
+ public TinyIoCContainer Kernel { get; protected set; }
+
+ [DataMember]
+ public IRoutingState Router { get; protected set; }
+
+ public AppBootstrapper()
+ {
+ Router = new RoutingState();
+
+ Kernel = new TinyIoCContainer();
+
+ // XXX: This is gross
+ Kernel.Register<UIViewController>(new RouterUINavigationController(Router), "InitialPage");
+
+ Kernel.Register(typeof(IViewFor<iOSPlaygroundViewModel>), typeof(iOSPlaygroundViewController));
+ Kernel.Register<IScreen>(this);
+
+ RxApp.ConfigureServiceLocator(
+ (t, s) => s != null ? Kernel.Resolve(t, s) : Kernel.Resolve(t),
+ (t, s) => Kernel.ResolveAll(t, true),
+ (c, t, s) => { if (s != null) { Kernel.Register(t, c, s); } else { Kernel.Register(t, c); } } );
+
+ Router.Navigate.Go<iOSPlaygroundViewModel>();
+ }
+ }
+}
51 iOSPlayground/AppDelegate.cs
View
@@ -4,6 +4,10 @@
using MonoTouch.Foundation;
using MonoTouch.UIKit;
+using ReactiveUI.Mobile;
+using ReactiveUI;
+using System.Reactive.Linq;
+using System.Reactive;
namespace iOSPlayground
{
@@ -11,33 +15,42 @@ namespace iOSPlayground
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
- public partial class AppDelegate : UIApplicationDelegate
+ public partial class AppDelegate : AutoSuspendAppDelegate
{
- // class-level declarations
- UIWindow window;
- iOSPlaygroundViewController viewController;
-
- //
- // This method is invoked when the application has loaded and is ready to run. In this
- // method you should instantiate the window, load the UI into it and then make the window
- // visible.
- //
- // You have 17 seconds to return from this method, or iOS will terminate your application.
- //
- public override bool FinishedLaunching(UIApplication app, NSDictionary options)
+ public override bool WillFinishLaunching(UIApplication application, NSDictionary launchOptions)
{
+ // NB: Hax
(new ReactiveUI.Xaml.ServiceLocationRegistration()).Register();
(new ReactiveUI.Routing.ServiceLocationRegistration()).Register();
(new ReactiveUI.Cocoa.ServiceLocationRegistration()).Register();
+ (new ReactiveUI.Mobile.ServiceLocationRegistration()).Register();
+
+ RxApp.Register(typeof(AppBootstrapper), typeof(IApplicationRootState));
+ RxApp.Register(typeof(DummySuspensionDriver), typeof(ISuspensionDriver));
+
+ var host = RxApp.GetService<ISuspensionHost>();
+ host.SetupDefaultSuspendResume();
- window = new UIWindow(UIScreen.MainScreen.Bounds);
-
- viewController = new iOSPlaygroundViewController();
- window.RootViewController = viewController;
- window.MakeKeyAndVisible();
-
return true;
}
}
+
+ public class DummySuspensionDriver : ISuspensionDriver
+ {
+ public IObservable<T> LoadState<T>() where T : class, IApplicationRootState
+ {
+ return Observable.Throw<T>(new Exception("Didn't work lol"));
+ }
+
+ public IObservable<Unit> SaveState<T>(T state) where T : class, IApplicationRootState
+ {
+ return Observable.Return(Unit.Default);
+ }
+
+ public IObservable<Unit> InvalidateState()
+ {
+ return Observable.Return(Unit.Default);
+ }
+ }
}
3,865 iOSPlayground/TinyIoC.cs
View
3,865 additions, 0 deletions not shown
7 iOSPlayground/iOSPlayground.csproj
View
@@ -101,6 +101,7 @@
<Reference Include="System.Reactive.PlatformServices">
<HintPath>..\ext\ios\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
+ <Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
@@ -115,6 +116,8 @@
<Compile Include="iOSPlaygroundViewController.designer.cs">
<DependentUpon>iOSPlaygroundViewController.cs</DependentUpon>
</Compile>
+ <Compile Include="AppBootstrapper.cs" />
+ <Compile Include="TinyIoC.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="iOSPlaygroundViewController.xib" />
@@ -137,5 +140,9 @@
<Project>{9091337A-9E94-4DBD-801E-05E1FDA78FFC}</Project>
<Name>ReactiveUI_Monotouch</Name>
</ProjectReference>
+ <ProjectReference Include="..\ReactiveUI.Mobile\ReactiveUI.Mobile_Monotouch.csproj">
+ <Project>{9091337A-9E94-4DBD-801E-15E10DB72FFC}</Project>
+ <Name>ReactiveUI.Mobile_Monotouch</Name>
+ </ProjectReference>
</ItemGroup>
</Project>
37 iOSPlayground/iOSPlaygroundViewController.cs
View
@@ -4,11 +4,32 @@
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using ReactiveUI;
+using ReactiveUI.Routing;
+using System.ComponentModel;
namespace iOSPlayground
{
- public partial class iOSPlaygroundViewController : UIViewController
+ public partial class iOSPlaygroundViewController : UIViewController, IViewFor<iOSPlaygroundViewModel>, INotifyPropertyChanged
{
+ #region Boring copy-paste code I want to die
+ iOSPlaygroundViewModel _ViewModel;
+ public iOSPlaygroundViewModel ViewModel {
+ get { return _ViewModel; }
+ set {
+ if (_ViewModel == value) return;
+ _ViewModel = value;
+ if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ViewModel"));
+ }
+ }
+
+ object IViewFor.ViewModel {
+ get { return ViewModel; }
+ set { ViewModel = (iOSPlaygroundViewModel)value; }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ #endregion
+
public iOSPlaygroundViewController() : base ("iOSPlaygroundViewController", null)
{
}
@@ -33,5 +54,19 @@ public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientati
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
}
}
+
+ public class iOSPlaygroundViewModel : ReactiveObject, IRoutableViewModel
+ {
+ public string UrlPathSegment {
+ get { return "Initial View"; }
+ }
+
+ public IScreen HostScreen { get; protected set; }
+
+ public iOSPlaygroundViewModel(IScreen hostScreen)
+ {
+ HostScreen = hostScreen ?? RxApp.GetService<IScreen>();
+ }
+ }
}
276 iOSPlayground/iOSPlaygroundViewController.xib
View
@@ -1,119 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
- <data>
- <int key="IBDocument.SystemTarget">1280</int>
- <string key="IBDocument.SystemVersion">11C25</string>
- <string key="IBDocument.InterfaceBuilderVersion">1919</string>
- <string key="IBDocument.AppKitVersion">1138.11</string>
- <string key="IBDocument.HIToolboxVersion">566.00</string>
- <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
- <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="NS.object.0">916</string>
- </object>
- <array key="IBDocument.IntegratedClassDependencies">
- <string>IBProxyObject</string>
- <string>IBUIView</string>
- </array>
- <array key="IBDocument.PluginDependencies">
- <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- </array>
- <object class="NSMutableDictionary" key="IBDocument.Metadata">
- <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
- <integer value="1" key="NS.object.0" />
- </object>
- <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
- <object class="IBProxyObject" id="372490531">
- <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
- <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
- </object>
- <object class="IBProxyObject" id="843779117">
- <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
- <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
- </object>
- <object class="IBUIView" id="774585933">
- <reference key="NSNextResponder" />
- <int key="NSvFlags">274</int>
- <string key="NSFrame">{{0, 20}, {320, 460}}</string>
- <reference key="NSSuperview" />
- <reference key="NSWindow" />
- <object class="NSColor" key="IBUIBackgroundColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MC43NQA</bytes>
- <object class="NSColorSpace" key="NSCustomColorSpace">
- <int key="NSID">2</int>
- </object>
- </object>
- <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
- <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics" />
- <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
- </object>
- </array>
- <object class="IBObjectContainer" key="IBDocument.Objects">
- <array class="NSMutableArray" key="connectionRecords">
- <object class="IBConnectionRecord">
- <object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">view</string>
- <reference key="source" ref="372490531" />
- <reference key="destination" ref="774585933" />
- </object>
- <int key="connectionID">7</int>
- </object>
- </array>
- <object class="IBMutableOrderedSet" key="objectRecords">
- <array key="orderedObjects">
- <object class="IBObjectRecord">
- <int key="objectID">0</int>
- <array key="object" id="0" />
- <reference key="children" ref="1000" />
- <nil key="parent" />
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">-1</int>
- <reference key="object" ref="372490531" />
- <reference key="parent" ref="0" />
- <string key="objectName">File's Owner</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">-2</int>
- <reference key="object" ref="843779117" />
- <reference key="parent" ref="0" />
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6</int>
- <reference key="object" ref="774585933" />
- <reference key="parent" ref="0" />
- </object>
- </array>
- </object>
- <dictionary class="NSMutableDictionary" key="flattenedProperties">
- <string key="-1.CustomClassName">iOSPlaygroundViewController</string>
- <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="-2.CustomClassName">UIResponder</string>
- <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- </dictionary>
- <dictionary class="NSMutableDictionary" key="unlocalizedProperties" />
- <nil key="activeLocalization" />
- <dictionary class="NSMutableDictionary" key="localizations" />
- <nil key="sourceID" />
- <int key="maxID">7</int>
- </object>
- <object class="IBClassDescriber" key="IBDocument.Classes">
- <array class="NSMutableArray" key="referencedPartialClassDescriptions">
- <object class="IBPartialClassDescription">
- <string key="className">iOSPlaygroundViewController</string>
- <string key="superclassName">UIViewController</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">iOSPlaygroundViewController.h</string>
- </object>
- </object>
- </array>
- </object>
- <int key="IBDocument.localizationMode">0</int>
- <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
- <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
- <int key="IBDocument.defaultPropertyAccessControl">3</int>
- <string key="IBCocoaTouchPluginVersion">916</string>
- </data>
+ <data>
+ <int key="IBDocument.SystemTarget">1552</int>
+ <string key="IBDocument.SystemVersion">12C60</string>
+ <string key="IBDocument.InterfaceBuilderVersion">3084</string>
+ <string key="IBDocument.AppKitVersion">1187.34</string>
+ <string key="IBDocument.HIToolboxVersion">625.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="NS.object.0">2083</string>
+ </object>
+ <array key="IBDocument.IntegratedClassDependencies">
+ <string>IBProxyObject</string>
+ <string>IBUILabel</string>
+ <string>IBUIView</string>
+ </array>
+ <array key="IBDocument.PluginDependencies">
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </array>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+ <integer value="1" key="NS.object.0"/>
+ </object>
+ <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <object class="IBProxyObject" id="372490531">
+ <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBProxyObject" id="843779117">
+ <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUIView" id="774585933">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">274</int>
+ <array class="NSMutableArray" key="NSSubviews">
+ <object class="IBUILabel" id="203465953">
+ <reference key="NSNextResponder" ref="774585933"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{138, 219}, {44, 21}}</string>
+ <reference key="NSSuperview" ref="774585933"/>
+ <reference key="NSWindow"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUIContentMode">7</int>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBUIText">Hello.</string>
+ <object class="NSColor" key="IBUITextColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MCAwIDAAA</bytes>
+ <string key="IBUIColorCocoaTouchKeyPath">darkTextColor</string>
+ </object>
+ <nil key="IBUIHighlightedColor"/>
+ <int key="IBUIBaselineAdjustment">0</int>
+ <object class="IBUIFontDescription" key="IBUIFontDescription">
+ <int key="type">1</int>
+ <double key="pointSize">17</double>
+ </object>
+ <object class="NSFont" key="IBUIFont">
+ <string key="NSName">Helvetica</string>
+ <double key="NSSize">17</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ <bool key="IBUIAdjustsFontSizeToFit">NO</bool>
+ </object>
+ </array>
+ <string key="NSFrame">{{0, 20}, {320, 460}}</string>
+ <reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC43NQA</bytes>
+ <object class="NSColorSpace" key="NSCustomColorSpace">
+ <int key="NSID">2</int>
+ </object>
+ </object>
+ <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
+ <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ </array>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <array class="NSMutableArray" key="connectionRecords">
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">view</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="774585933"/>
+ </object>
+ <int key="connectionID">7</int>
+ </object>
+ </array>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <array key="orderedObjects">
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <array key="object" id="0"/>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="372490531"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="843779117"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6</int>
+ <reference key="object" ref="774585933"/>
+ <array class="NSMutableArray" key="children">
+ <reference ref="203465953"/>
+ </array>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">8</int>
+ <reference key="object" ref="203465953"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
+ </array>
+ </object>
+ <dictionary class="NSMutableDictionary" key="flattenedProperties">
+ <string key="-1.CustomClassName">iOSPlaygroundViewController</string>
+ <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="-2.CustomClassName">UIResponder</string>
+ <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
+ <nil key="activeLocalization"/>
+ <dictionary class="NSMutableDictionary" key="localizations"/>
+ <nil key="sourceID"/>
+ <int key="maxID">8</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">iOSPlaygroundViewController</string>
+ <string key="superclassName">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/iOSPlaygroundViewController.h</string>
+ </object>
+ </object>
+ </array>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <string key="IBCocoaTouchPluginVersion">2083</string>
+ </data>
</archive>
Please sign in to comment.
Something went wrong with that request. Please try again.