Skip to content

Commit

Permalink
Merge pull request #1188 from dbeattie71/4.0
Browse files Browse the repository at this point in the history
Fix merge of PR 1186
  • Loading branch information
martijn00 committed Dec 4, 2015
2 parents 39fc13c + 011af1c commit b6d5832
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
<Compile Include="Fragments\MvxSimpleLayoutInflaterHolder.cs" />
<Compile Include="MvxCachingFragmentActivity.cs" />
<Compile Include="MvxCreateViewParameters.cs" />
<Compile Include="MvxFragmentAttributeExtensionMethods.cs" />
<Compile Include="MvxFragmentViewExtensionMethods.cs" />
<Compile Include="MvxFragmentAttribute.cs" />
<Compile Include="MvxFragmentAttributeExtensionMethods.cs" />
<Compile Include="MvxTabsFragmentActivity.cs" />
<Compile Include="Presenter\IMvxFragmentHost.cs" />
<Compile Include="Presenter\IMvxFragmentsPresenter.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MvxBindingFragmentAdapter(IMvxEventSourceFragment eventSource)
protected override void HandlePauseCalled(object sender, EventArgs e)
{
base.HandlePauseCalled(sender, e);
if (!FragmentView.GetType().IsFragmentCacheable())
if (!FragmentView.GetType().IsCacheableFragmentAttribute())
return;

FragmentView.RegisterFragmentViewToCacheIfNeeded();
Expand All @@ -44,7 +44,7 @@ protected override void HandleCreateCalled(object sender, MvxValueEventArgs<Bund
{
FragmentView.EnsureSetupInitialized();

if (!FragmentView.GetType().IsFragmentCacheable())
if (!FragmentView.GetType().IsCacheableFragmentAttribute())
return;

Bundle bundle = null;
Expand Down Expand Up @@ -100,7 +100,7 @@ protected override void HandleCreateCalled(object sender, MvxValueEventArgs<Bund

protected override void HandleSaveInstanceStateCalled(object sender, MvxValueEventArgs<Bundle> bundleArgs)
{
if (!FragmentView.GetType().IsFragmentCacheable())
if (!FragmentView.GetType().IsCacheableFragmentAttribute())
return;

var mvxBundle = FragmentView.CreateSaveStateBundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public static Type FindAssociatedViewModelType(this IMvxFragmentView fragmentVie

if (viewModelType == null)
{
if (!type.HasMvxFragmentAttribute())
if (!type.IsCacheableFragmentAttribute())
throw new InvalidOperationException($"Your fragment is not generic and it does not have {nameof(MvxFragmentAttribute)} attribute set!");

var cacheableFragmentAttribute = type.GetMvxFragmentAttribute();
var cacheableFragmentAttribute = type.GetCacheableFragmentAttribute();
if (cacheableFragmentAttribute.ViewModelType == null)
throw new InvalidOperationException($"Your fragment is not generic and it does not use {nameof(MvxFragmentAttribute)} with ViewModel Type constructor.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected IEnumerable<Fragment> GetCurrentCacheableFragments()
return currentFragments
.Where(fragment => fragment != null)
// we are not interested in fragments which are not supposed to cache!
.Where(fragment => fragment.GetType().IsFragmentCacheable());
.Where(fragment => fragment.GetType().IsCacheableFragmentAttribute());
}

protected IMvxCachedFragmentInfo GetLastFragmentInfo()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// MvxConventionAttributeExtensionMethods.cs
// (c) Copyright Cirrious Ltd. http://www.cirrious.com
// MvvmCross is licensed using Microsoft Public License (Ms-PL)
// Contributions and inspirations noted in readme.md and license.txt
//
// Project Lead - Stuart Lodge, @slodge, me@slodge.com

using System;
using System.Linq;

namespace Cirrious.MvvmCross.Droid.FullFragging
{
public static class MvxFragmentAttributeExtensionMethods
{
public static bool IsCacheableFragmentAttribute(this Type candidateType)
{
var attributes = candidateType.GetCustomAttributes(typeof(MvxFragmentAttribute), true);
return attributes.Length > 0;
}

public static MvxFragmentAttribute GetCacheableFragmentAttribute(this Type fromFragmentType)
{
var attributes = fromFragmentType.GetCustomAttributes(typeof (MvxFragmentAttribute), true);

if (!attributes.Any())
throw new InvalidOperationException($"Type does not have {nameof(MvxFragmentAttribute)} attribute!");

var cacheableFragmentAttribute = attributes.First() as MvxFragmentAttribute;
return cacheableFragmentAttribute;
}
}
}

This file was deleted.

0 comments on commit b6d5832

Please sign in to comment.