Created
December 27, 2013 04:57
-
-
Save jamesmontemagno/8142752 to your computer and use it in GitHub Desktop.
Compatibility classes if you use Action Bar Compat (v7) with MvvmCross
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.Content; | |
using Cirrious.MvvmCross.Binding.BindingContext; | |
using Cirrious.MvvmCross.Binding.Droid.BindingContext; | |
using Cirrious.MvvmCross.ViewModels; | |
using MeetupManager.Droid.Helpers; | |
using Cirrious.MvvmCross.Droid.Views; | |
namespace MyProject | |
{ | |
public abstract class MvxActionBarActivity | |
: MvxActionBarEventSourceActivity | |
, IMvxAndroidView | |
{ | |
protected MvxActionBarActivity() | |
{ | |
BindingContext = new MvxAndroidBindingContext(this, this); | |
this.AddEventListeners(); | |
} | |
public object DataContext | |
{ | |
get { return BindingContext.DataContext; } | |
set { BindingContext.DataContext = value; } | |
} | |
public IMvxViewModel ViewModel | |
{ | |
get { return DataContext as IMvxViewModel; } | |
set | |
{ | |
DataContext = value; | |
OnViewModelSet(); | |
} | |
} | |
public void MvxInternalStartActivityForResult(Intent intent, int requestCode) | |
{ | |
base.StartActivityForResult(intent, requestCode); | |
} | |
public IMvxBindingContext BindingContext { get; set; } | |
public override void SetContentView(int layoutResId) | |
{ | |
var view = this.BindingInflate(layoutResId, null); | |
SetContentView(view); | |
} | |
protected virtual void OnViewModelSet() | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.App; | |
using Android.Content; | |
using Android.OS; | |
using Cirrious.CrossCore.Droid.Views; | |
using Android.Support.V7.App; | |
using Cirrious.CrossCore.Core; | |
namespace MyProject | |
{ | |
public class MvxActionBarEventSourceActivity : ActionBarActivity | |
, IMvxEventSourceActivity | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
CreateWillBeCalled.Raise(this, bundle); | |
base.OnCreate(bundle); | |
CreateCalled.Raise(this, bundle); | |
} | |
protected override void OnDestroy() | |
{ | |
DestroyCalled.Raise(this); | |
base.OnDestroy(); | |
} | |
protected override void OnNewIntent(Intent intent) | |
{ | |
base.OnNewIntent(intent); | |
NewIntentCalled.Raise(this, intent); | |
} | |
protected override void OnResume() | |
{ | |
base.OnResume(); | |
ResumeCalled.Raise(this); | |
} | |
protected override void OnPause() | |
{ | |
PauseCalled.Raise(this); | |
base.OnPause(); | |
} | |
protected override void OnStart() | |
{ | |
base.OnStart(); | |
StartCalled.Raise(this); | |
} | |
protected override void OnRestart() | |
{ | |
base.OnRestart(); | |
RestartCalled.Raise(this); | |
} | |
protected override void OnStop() | |
{ | |
StopCalled.Raise(this); | |
base.OnStop(); | |
} | |
public override void StartActivityForResult(Intent intent, int requestCode) | |
{ | |
StartActivityForResultCalled.Raise(this, new MvxStartActivityForResultParameters(intent, requestCode)); | |
base.StartActivityForResult(intent, requestCode); | |
} | |
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) | |
{ | |
ActivityResultCalled.Raise(this, new MvxActivityResultParameters(requestCode, resultCode, data)); | |
base.OnActivityResult(requestCode, resultCode, data); | |
} | |
protected override void OnSaveInstanceState(Bundle outState) | |
{ | |
SaveInstanceStateCalled.Raise(this, outState); | |
base.OnSaveInstanceState(outState); | |
} | |
protected override void Dispose(bool disposing) | |
{ | |
if (disposing) | |
{ | |
DisposeCalled.Raise(this); | |
} | |
base.Dispose(disposing); | |
} | |
public event EventHandler DisposeCalled; | |
public event EventHandler<MvxValueEventArgs<Bundle>> CreateWillBeCalled; | |
public event EventHandler<MvxValueEventArgs<Bundle>> CreateCalled; | |
public event EventHandler DestroyCalled; | |
public event EventHandler<MvxValueEventArgs<Intent>> NewIntentCalled; | |
public event EventHandler ResumeCalled; | |
public event EventHandler PauseCalled; | |
public event EventHandler StartCalled; | |
public event EventHandler RestartCalled; | |
public event EventHandler StopCalled; | |
public event EventHandler<MvxValueEventArgs<Bundle>> SaveInstanceStateCalled; | |
public event EventHandler<MvxValueEventArgs<MvxStartActivityForResultParameters>> StartActivityForResultCalled; | |
public event EventHandler<MvxValueEventArgs<MvxActivityResultParameters>> ActivityResultCalled; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using Android.OS; | |
using Cirrious.MvvmCross.Droid.Views; | |
using MeetupManager.Portable.ViewModels; | |
namespace MyProject | |
{ | |
[Activity (Label = "FirstView")] | |
public class FirstView : MvxActionBarActivity | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment