forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.cs
More file actions
93 lines (75 loc) · 2.61 KB
/
MainActivity.cs
File metadata and controls
93 lines (75 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using ReactiveUI;
using System.ComponentModel;
using ReactiveUI.Android;
using ReactiveUI.Mobile;
using Splat;
namespace AndroidPlayground
{
// [Activity (Label = "AndroidPlayground", MainLauncher = true)]
public class MainView : ReactiveActivity<MainViewModel>
{
int count = 1;
readonly ActivityRoutedViewHost routeHelper;
readonly AutoSuspendActivityHelper suspendHelper;
public MainView()
{
// NB: This is dumb.
Console.WriteLine(App.Current);
RxApp.MainThreadScheduler = new WaitForDispatcherScheduler(() => new AndroidUIScheduler(this));
suspendHelper = new AutoSuspendActivityHelper(this);
suspendHelper.SuspensionHost.SetupDefaultSuspendResume();
routeHelper = new ActivityRoutedViewHost(this);
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
suspendHelper.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.myButton);
button.Click += (o,e) => {
ViewModel.HostScreen.Router.Navigate.Execute(new SecondaryViewModel(ViewModel.HostScreen));
};
this.OneWayBind(ViewModel, x => x.UrlPathSegment, x => x.ActionBar.Title);
}
public override bool OnKeyUp(Keycode keyCode, KeyEvent e)
{
return routeHelper.OnKeyUp(keyCode, e);
}
protected override void OnResume()
{
base.OnResume();
suspendHelper.OnResume();
}
protected override void OnPause()
{
base.OnPause();
suspendHelper.OnPause();
}
protected override void OnSaveInstanceState(Bundle outState)
{
base.OnSaveInstanceState(outState);
suspendHelper.OnSaveInstanceState(outState);
}
}
public class MainViewModel : ReactiveObject, IRoutableViewModel
{
public string UrlPathSegment {
get { return "Main!"; }
}
public IScreen HostScreen { get; protected set; }
public MainViewModel(IScreen hostScreen)
{
HostScreen = hostScreen ?? Locator.Current.GetService<IScreen>();
}
}
}