Skip to content
Permalink
Browse files

Use MvvmCross and view models

  • Loading branch information...
petermajor committed Feb 25, 2016
1 parent 2fd1039 commit 2f3c0387209b4504c99407d74c10366ed7711be3
@@ -0,0 +1,9 @@
using MvvmCross.Platform.Plugins;

namespace CrossDrawer.Android.Bootstrap
{
public class JsonPluginBootstrap
: MvxPluginBootstrapAction<MvvmCross.Plugins.Json.PluginLoader>
{
}
}
@@ -15,7 +15,7 @@
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<AssemblyName>CrossDrawer.Android</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<TargetFrameworkVersion>v4.4</TargetFrameworkVersion>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -48,13 +48,50 @@
<Reference Include="Xamarin.Android.Support.v7.AppCompat">
<HintPath>..\packages\Xamarin.Android.Support.v7.AppCompat.23.1.1.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Platform.Droid">
<HintPath>..\packages\MvvmCross.Platform.4.0.0\lib\MonoAndroid\MvvmCross.Platform.Droid.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Platform">
<HintPath>..\packages\MvvmCross.Platform.4.0.0\lib\MonoAndroid\MvvmCross.Platform.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Droid">
<HintPath>..\packages\MvvmCross.Core.4.0.0\lib\MonoAndroid\MvvmCross.Droid.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Core">
<HintPath>..\packages\MvvmCross.Core.4.0.0\lib\MonoAndroid\MvvmCross.Core.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Plugins.Json">
<HintPath>..\packages\MvvmCross.Plugin.Json.4.0.0\lib\MonoAndroid\MvvmCross.Plugins.Json.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Droid.Support.V7.Fragging">
<HintPath>..\packages\MvvmCross.Droid.Support.V7.Fragging.4.0.1\lib\MonoAndroid403\MvvmCross.Droid.Support.V7.Fragging.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Binding.Droid">
<HintPath>..\packages\MvvmCross.Binding.4.0.0\lib\MonoAndroid\MvvmCross.Binding.Droid.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Binding">
<HintPath>..\packages\MvvmCross.Binding.4.0.0\lib\MonoAndroid\MvvmCross.Binding.dll</HintPath>
</Reference>
<Reference Include="MvvmCross.Localization">
<HintPath>..\packages\MvvmCross.Binding.4.0.0\lib\MonoAndroid\MvvmCross.Localization.dll</HintPath>
</Reference>
<Reference Include="Mono.Android.Export" />
<Reference Include="MvvmCross.Droid.Support.V7.AppCompat">
<HintPath>..\packages\MvvmCross.Droid.Support.V7.AppCompat.4.0.2\lib\MonoAndroid403\MvvmCross.Droid.Support.V7.AppCompat.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MyListFragment.cs" />
<Compile Include="MySettingsFragment.cs" />
<Compile Include="Bootstrap\JsonPluginBootstrap.cs" />
<Compile Include="Setup.cs" />
<Compile Include="SplashScreen.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
@@ -75,9 +112,17 @@
<AndroidResource Include="Resources\values\Styles.xml" />
<AndroidResource Include="Resources\values\Colors.xml" />
<AndroidResource Include="Resources\layout\Toolbar.axml" />
<AndroidResource Include="Resources\layout\Splash.axml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\drawable\" />
<Folder Include="New Folder\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\CrossDrawer.Core\CrossDrawer.Core.csproj">
<Project>{2B1F1B99-1201-4FD8-BC57-1DB0FEC21ADE}</Project>
<Name>CrossDrawer.Core</Name>
</ProjectReference>
</ItemGroup>
</Project>
@@ -1,30 +1,30 @@
using Android.App;
using System.Linq;
using Android.App;
using Android.OS;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using CrossDrawer.Core;
using MvvmCross.Droid.Support.V7.AppCompat;
using Fragment = Android.Support.V4.App.Fragment;
using Toolbar = Android.Support.V7.Widget.Toolbar;

namespace CrossDrawer.Android
{
[Activity (MainLauncher = true)]
public class MainActivity : AppCompatActivity
[Activity]
public class MainActivity : MvxCachingFragmentCompatActivity<MainViewModel>
{
Fragment[] _fragments = { new MyListFragment(), new MySettingsFragment() };

string[] _titles = { "My List", "My Settings" };

ActionBarDrawerToggle _drawerToggle;

ListView _drawerListView;

DrawerLayout _drawerLayout;

protected override void OnCreate (Bundle savedInstanceState)
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (savedInstanceState);
base.OnCreate (bundle);

SetContentView (Resource.Layout.Main);

@@ -35,7 +35,7 @@ protected override void OnCreate (Bundle savedInstanceState)

_drawerListView = FindViewById<ListView> (Resource.Id.drawerListView);
_drawerListView.ItemClick += (s, e) => ShowFragmentAt (e.Position);
_drawerListView.Adapter = new ArrayAdapter<string> (this, global::Android.Resource.Layout.SimpleListItem1, _titles);
_drawerListView.Adapter = new ArrayAdapter<string> (this, global::Android.Resource.Layout.SimpleListItem1, ViewModel.MenuItems.ToArray());

_drawerLayout = FindViewById<DrawerLayout> (Resource.Id.drawerLayout);

@@ -48,9 +48,9 @@ protected override void OnCreate (Bundle savedInstanceState)

void ShowFragmentAt (int position)
{
SupportFragmentManager.BeginTransaction ().Replace (Resource.Id.frameLayout, _fragments [position]).Commit ();
ViewModel.NavigateTo (position);

Title = _titles [position];
Title = ViewModel.MenuItems.ElementAt (position);

_drawerLayout.CloseDrawer (_drawerListView);
}
@@ -1,10 +1,15 @@
using Android.OS;
using Android.Runtime;
using Android.Views;
using Fragment = Android.Support.V4.App.Fragment;
using CrossDrawer.Core;
using MvvmCross.Droid.Support.V7.Fragging.Attributes;
using MvvmCross.Droid.Support.V7.Fragging.Fragments;

namespace CrossDrawer.Android
{
public class MyListFragment : Fragment
[MvxFragmentAttribute(typeof(MainViewModel), Resource.Id.frameLayout)]
[Register("crossdrawer.android.MyListFragment")]
public class MyListFragment : MvxFragment<MyListViewModel>
{
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
@@ -1,10 +1,15 @@
using Android.OS;
using Android.Runtime;
using Android.Views;
using Fragment = Android.Support.V4.App.Fragment;
using CrossDrawer.Core;
using MvvmCross.Droid.Support.V7.Fragging.Attributes;
using MvvmCross.Droid.Support.V7.Fragging.Fragments;

namespace CrossDrawer.Android
{
public class MySettingsFragment : Fragment
[MvxFragmentAttribute(typeof(MainViewModel), Resource.Id.frameLayout)]
[Register("crossdrawer.android.MySettingsFragment")]
public class MySettingsFragment : MvxFragment<MySettingsViewModel>
{
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{

0 comments on commit 2f3c038

Please sign in to comment.
You can’t perform that action at this time.