Loosely speaking, you can translate any Activity to an MvxActivity by inheriting some interfaces and by then cutting and pasting a small amount of code which does the basic loading and assignation of the ViewModel.
e.g. see the #Region
and IMvxAndroidView<TViewModel>
added to make MvxActivityView.cs from a normal Activity
.
e.g. it's the same region and interface used for adapting a specialised Activity like Google's MapActivity
into MvxMapActivityView.cs
At this level, the Activity/View has a ViewModel
which can be used in C# code, but has no clever xml inflation - it has no clever Binding
support.
Code can be written at this level - I've shipped apps without binding - but many users prefer to add DataBinding too...
To add this DataBinding support, you need to add a bit more code which provides BindingInflate, storage of bindings, disposal of bindings, etc.
e.g. a raw MvxActivityView
is extended using the IMvxBindingActivity
interface and a #region like: MvxBindingActivityView.cs
e.g. MvxMapActivityView
is extended using the same region and interface: MvxBindingMapActivityView.cs
So to extend your the custom AndroidGameActivity
:
- Inherit from
AndroidGameActivity
to get ViewModelOwningGameActivity<T>
and cut and paste the IMvxAndroidView<TViewModel>
interface and #region
from MvxActivityView<T>
to provide the ViewModel methods, fields and properties.
Then assuming you want binding:
- Inherit from
ViewModelOwningGameActivity<T>
to get BindingGameActivity<T>
and cut and paste the IMvxBindingActivity
and #region
from MvxBindingActivityView<T>
to get the binding methods
For specialist Activities you may want to add more - e.g. you may could add some custom helper methods for the MapActivity to plot points and lines, or for GameActivity to do whatever games do... but this is up to individual implementations.
Sorry about the cut and paste of code required in adapting Activities - I have tried to keep this to a minimum. However, writing Mvx is the one time so far that I've really wanted Multiple Inheritance or Mixins in C#
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…