Permalink
Browse files

First hack at getting suspend/resume running

  • Loading branch information...
1 parent 4947103 commit ea8d8345b88df3b18ead98b4eb90b04f6fa95ee5 @paulcbetts paulcbetts committed Mar 20, 2013
@@ -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>();
+ }
+ }
+}
@@ -4,40 +4,53 @@
using MonoTouch.Foundation;
using MonoTouch.UIKit;
+using ReactiveUI.Mobile;
+using ReactiveUI;
+using System.Reactive.Linq;
+using System.Reactive;
namespace iOSPlayground
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// 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);
+ }
+ }
}
Oops, something went wrong.

0 comments on commit ea8d834

Please sign in to comment.