forked from martijn00/MvvmCross-Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented basics of new MvvmCross->Forms coexiistence support.
Implemented scratch of Droid new example.
- Loading branch information
Showing
115 changed files
with
24,029 additions
and
10 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
MvvmCross.Forms.Presenter.Core/Attribute/MvxAssociatedViewTypeAttribute.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace MvvmCross.Forms.Presenter.Core.Attribute | ||
{ | ||
public class MvxAssociatedViewTypeAttribute : System.Attribute | ||
{ | ||
public MvxViewType ViewType { get; } | ||
|
||
public MvxAssociatedViewTypeAttribute(MvxViewType viewType) | ||
{ | ||
ViewType = viewType; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace MvvmCross.Forms.Presenter.Core.Attribute | ||
{ | ||
public enum MvxViewType | ||
{ | ||
Forms = 0, | ||
Classic = 1 | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Linq; | ||
using MvvmCross.Core.ViewModels; | ||
using MvvmCross.Core.Views; | ||
using MvvmCross.Forms.Presenter.Core.Attribute; | ||
using MvvmCross.Platform; | ||
|
||
namespace MvvmCross.Forms.Presenter.Core | ||
{ | ||
public class MvxFormsPresenterProxy : MvxViewPresenter | ||
{ | ||
public readonly IMvxViewPresenter ClassicMvxViewPresenter; | ||
public readonly MvxFormsPagePresenter FormsViewPresenter; | ||
|
||
public MvxFormsPresenterProxy(IMvxViewPresenter classicMvxViewPresenter, MvxFormsPagePresenter formsViewPresenter) | ||
{ | ||
ClassicMvxViewPresenter = classicMvxViewPresenter; | ||
FormsViewPresenter = formsViewPresenter; | ||
} | ||
|
||
public override void Show(MvxViewModelRequest request) | ||
{ | ||
var mvxViewType = GetViewType(request); | ||
switch (mvxViewType) | ||
{ | ||
case MvxViewType.Forms: | ||
FormsViewPresenter.Show(request); | ||
break; | ||
case MvxViewType.Classic: | ||
ClassicMvxViewPresenter.Show(request); | ||
break; | ||
} | ||
} | ||
|
||
|
||
public override void ChangePresentation(MvxPresentationHint hint) | ||
{ | ||
// TODO: At this moment only Classic ViewModels support change presentation | ||
ClassicMvxViewPresenter.ChangePresentation(hint); | ||
} | ||
|
||
protected virtual MvxViewType GetViewType(MvxViewModelRequest fromViewModelRequest) | ||
{ | ||
var mvxAssociatedViewTypeAttribute = | ||
fromViewModelRequest.ViewModelType.GetCustomAttributes(typeof(MvxAssociatedViewTypeAttribute), false) | ||
.Cast<MvxAssociatedViewTypeAttribute>() | ||
.SingleOrDefault(); | ||
|
||
return mvxAssociatedViewTypeAttribute?.ViewType ?? MvxViewType.Forms; | ||
} | ||
|
||
} | ||
} |
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
16 changes: 7 additions & 9 deletions
16
...enter.Droid/MvxFormsDroidPagePresenter.cs → ...nter.Droid/MvxDroidFormsPresenterProxy.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
// MvxFormsDroidPagePresenter.cs | ||
// MvxDroidFormsPresenterProxy.cs | ||
// 2015 (c) Copyright Cheesebaron. http://ostebaronen.dk | ||
// MvvmCross.Forms.Presenter is licensed using Microsoft Public License (Ms-PL) | ||
// Contributions and inspirations noted in readme.md and license.txt | ||
// | ||
// Project Lead - Tomasz Cielecki, @cheesebaron, [email protected] | ||
// Contributor - Marcos Cobeña Morián, @CobenaMarcos, [email protected] | ||
|
||
using MvvmCross.Core.Views; | ||
using MvvmCross.Droid.Views; | ||
using MvvmCross.Forms.Presenter.Core; | ||
|
||
namespace MvvmCross.Forms.Presenter.Droid | ||
{ | ||
public class MvxFormsDroidPagePresenter | ||
: MvxFormsPagePresenter | ||
public class MvxDroidFormsPresenterProxy | ||
: MvxFormsPresenterProxy | ||
, IMvxAndroidViewPresenter | ||
{ | ||
public MvxFormsDroidPagePresenter() | ||
{ | ||
} | ||
|
||
public MvxFormsDroidPagePresenter(MvxFormsApp mvxFormsApp) | ||
: base(mvxFormsApp) | ||
public MvxDroidFormsPresenterProxy(IMvxViewPresenter classicMvxViewPresenter, MvxFormsPagePresenter formsViewPresenter) : base(classicMvxViewPresenter, formsViewPresenter) | ||
{ | ||
} | ||
} | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
MvvmCross.Forms.Presenter.Droid/MvxFormsAppCompatActivity.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using Android.OS; | ||
using MvvmCross.Core.ViewModels; | ||
using MvvmCross.Core.Views; | ||
using MvvmCross.Forms.Presenter.Core; | ||
using MvvmCross.Platform; | ||
using Xamarin.Forms.Platform.Android; | ||
|
||
namespace MvvmCross.Forms.Presenter.Droid | ||
{ | ||
public abstract class MvxFormsAppCompatActivity : FormsAppCompatActivity | ||
{ | ||
protected override void OnCreate(Bundle bundle) | ||
{ | ||
base.OnCreate(bundle); | ||
|
||
Xamarin.Forms.Forms.Init(this, bundle); | ||
|
||
var mvxFormsApp = new MvxFormsApp(); | ||
LoadApplication(mvxFormsApp); | ||
|
||
var presenter = Mvx.Resolve<IMvxViewPresenter>() as MvxFormsPresenterProxy; | ||
if (presenter == null) | ||
{ | ||
var errorMsg = $"To use MvvmCross with Forms you have to use {nameof(MvxFormsPresenterProxy)}"; | ||
Mvx.Error(errorMsg); | ||
throw new InvalidOperationException(errorMsg); | ||
} | ||
|
||
var formsPresenter = presenter.FormsViewPresenter; | ||
if (formsPresenter == null) | ||
{ | ||
var errorMsg = | ||
$"To use MvvmCross with Android and Forms your {nameof(MvxFormsPresenterProxy)} have to use ${nameof(MvxFormsPagePresenter)} as Forms presenter."; | ||
Mvx.Error(errorMsg); | ||
throw new InvalidOperationException(errorMsg); | ||
} | ||
|
||
formsPresenter.MvxFormsApp = mvxFormsApp; | ||
|
||
// TODO: Forms specific MvxAppStart | ||
Mvx.Resolve<IMvxAppStart>().Start(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
MvvmCross.Forms.Presenter.Droid/MvxFormsSplashScreenActivity.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Android.OS; | ||
using MvvmCross.Droid.Views; | ||
|
||
namespace MvvmCross.Forms.Presenter.Droid | ||
{ | ||
public abstract class MvxFormsSplashScreenActivity : MvxSplashScreenActivity | ||
{ | ||
protected MvxFormsSplashScreenActivity(int resourceId = 0) : base(resourceId) | ||
{ | ||
} | ||
|
||
protected override void OnCreate(Bundle bundle) | ||
{ | ||
Xamarin.Forms.Forms.Init(this, bundle); | ||
// Leverage controls' StyleId attrib. to Xamarin.UITest | ||
Xamarin.Forms.Forms.ViewInitialized += (sender, e) => | ||
{ | ||
if (!string.IsNullOrWhiteSpace(e.View.StyleId)) | ||
{ | ||
e.NativeView.ContentDescription = e.View.StyleId; | ||
} | ||
}; | ||
|
||
base.OnCreate(bundle); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...Forms.Sample.Integration/IntegrationSample/IntegrationSample.Droid/Assets/AboutAssets.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Any raw assets you want to be deployed with your application can be placed in | ||
this directory (and child directories) and given a Build Action of "AndroidAsset". | ||
|
||
These files will be deployed with you package and will be accessible using Android's | ||
AssetManager, like this: | ||
|
||
public class ReadAsset : Activity | ||
{ | ||
protected override void OnCreate (Bundle bundle) | ||
{ | ||
base.OnCreate (bundle); | ||
|
||
InputStream input = Assets.Open ("my_asset.txt"); | ||
} | ||
} | ||
|
||
Additionally, some Android functions will automatically load asset files: | ||
|
||
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); |
18 changes: 18 additions & 0 deletions
18
...ss.Forms.Sample.Integration/IntegrationSample/IntegrationSample.Droid/FeedbackActivity.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using Android.App; | ||
using Android.Content; | ||
using Android.OS; | ||
using Android.Runtime; | ||
using Android.Views; | ||
using Android.Widget; | ||
|
||
namespace IntegrationSample.Droid | ||
{ | ||
class FeedbackActivity | ||
{ | ||
} | ||
} |
Oops, something went wrong.