Skip to content

Commit

Permalink
Merge branch 'hotfix/7.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheesebaron committed Oct 21, 2020
2 parents be8333a + 818627d commit bfb3977
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions MvvmCross/Platforms/Android/Presenters/MvxAndroidViewPresenter.cs
Expand Up @@ -38,6 +38,9 @@ namespace MvvmCross.Platforms.Android.Presenters
#nullable enable
public class MvxAndroidViewPresenter : MvxAttributeViewPresenter, IMvxAndroidViewPresenter
{
public const string ViewModelRequestBundleKey = "__mvxViewModelRequest";
public const string SharedElementsBundleKey = "__sharedElementsKey";

private readonly Lazy<IMvxAndroidCurrentTopActivity> _androidCurrentTopActivity =
new Lazy<IMvxAndroidCurrentTopActivity>(() => Mvx.IoCProvider.Resolve<IMvxAndroidCurrentTopActivity>());

Expand All @@ -51,10 +54,8 @@ public class MvxAndroidViewPresenter : MvxAttributeViewPresenter, IMvxAndroidVie
new Lazy<IMvxLog>(() => Mvx.IoCProvider.Resolve<IMvxLog>());

protected IEnumerable<Assembly> AndroidViewAssemblies { get; set; }
public const string ViewModelRequestBundleKey = "__mvxViewModelRequest";
public const string SharedElementsBundleKey = "__sharedElementsKey";

protected MvxViewModelRequest? PendingRequest { get; private set; }
protected MvxViewModelRequest? PendingRequest { get; set; }

protected virtual FragmentManager? CurrentFragmentManager
{
Expand All @@ -67,7 +68,7 @@ public class MvxAndroidViewPresenter : MvxAttributeViewPresenter, IMvxAndroidVie
}
}

protected virtual Activity? CurrentActivity =>
protected virtual Activity? CurrentActivity =>
_androidCurrentTopActivity.Value?.Activity as Activity;

protected IMvxAndroidActivityLifetimeListener ActivityLifetimeListener =>
Expand Down Expand Up @@ -105,7 +106,7 @@ protected virtual void ActivityLifetimeListenerOnActivityChanged(object sender,

protected Type GetAssociatedViewModelType(Type fromFragmentType)
{
Type viewModelType = ViewModelTypeFinder.FindTypeOrNull(fromFragmentType);
var viewModelType = ViewModelTypeFinder?.FindTypeOrNull(fromFragmentType);
return viewModelType ?? fromFragmentType.GetBasePresentationAttributes().First().ViewModelType;
}

Expand All @@ -118,11 +119,13 @@ public override void RegisterAttributeTypes()
AttributeTypesToActionsDictionary.Register<MvxViewPagerFragmentPresentationAttribute>(ShowViewPagerFragment, CloseViewPagerFragment);
}

public override MvxBasePresentationAttribute? GetPresentationAttribute(MvxViewModelRequest request)
public override MvxBasePresentationAttribute GetPresentationAttribute(MvxViewModelRequest request)
{
ValidateArguments(request);

var viewType = ViewsContainer.GetViewType(request.ViewModelType);
var viewType = ViewsContainer?.GetViewType(request.ViewModelType);
if (viewType == null)
throw new InvalidOperationException($"Could not get view type for ViewModel Type: {request.ViewModelType}");

var overrideAttribute = GetOverridePresentationAttribute(request, viewType);
if (overrideAttribute != null)
Expand Down Expand Up @@ -200,7 +203,7 @@ public override void RegisterAttributeTypes()
return attribute;
}

public override MvxBasePresentationAttribute? CreatePresentationAttribute(Type? viewModelType, Type? viewType)
public override MvxBasePresentationAttribute CreatePresentationAttribute(Type? viewModelType, Type? viewType)
{
if (viewType == null)
throw new ArgumentNullException(nameof(viewType));
Expand All @@ -223,7 +226,7 @@ public override void RegisterAttributeTypes()
return new MvxActivityPresentationAttribute() { ViewType = viewType, ViewModelType = viewModelType };
}

return null;
throw new InvalidOperationException($"Don't know how to create a presentation attribute for type {viewType}");
}

public override Task<bool> ChangePresentation(MvxPresentationHint hint)
Expand Down Expand Up @@ -298,7 +301,7 @@ private bool ChangePagePresentation(MvxPagePresentationHint pagePresentationHint
if (CurrentActivity.IsActivityAlive())
currentActivityType = CurrentActivity!.GetType();

var activityViewModelType = ViewModelTypeFinder.FindTypeOrNull(currentActivityType);
var activityViewModelType = ViewModelTypeFinder?.FindTypeOrNull(currentActivityType);
return activityViewModelType;
}

Expand Down Expand Up @@ -444,8 +447,8 @@ protected virtual void ShowHostActivity(MvxFragmentPresentationAttribute attribu
{
ValidateArguments(attribute);

var viewType = ViewsContainer.GetViewType(attribute.ActivityHostViewModelType);
if (!viewType.IsSubclassOf(typeof(Activity)))
var viewType = ViewsContainer?.GetViewType(attribute.ActivityHostViewModelType);
if (viewType?.IsSubclassOf(typeof(Activity)) != true)
throw new MvxException("The host activity doesn't inherit Activity");

var hostViewModelRequest = MvxViewModelRequest.GetDefaultRequest(attribute.ActivityHostViewModelType);
Expand Down Expand Up @@ -501,7 +504,7 @@ protected virtual void ShowHostActivity(MvxFragmentPresentationAttribute attribu

// current implementation only supports one level of nesting

var fragmentHost = GetFragmentByViewType(attribute.FragmentHostViewType);
var fragmentHost = GetFragmentByViewType(attribute!.FragmentHostViewType);
if (fragmentHost == null)
throw new InvalidOperationException($"Fragment host not found when trying to show View {view.Name} as Nested Fragment");

Expand All @@ -528,7 +531,7 @@ protected virtual void ShowHostActivity(MvxFragmentPresentationAttribute attribu
{
fragmentView = (IMvxFragmentView)fragmentManager.FindFragmentByTag(fragmentName);
}
fragmentView = fragmentView ?? CreateFragment(fragmentManager, attribute, attribute.ViewType);
fragmentView ??= CreateFragment(fragmentManager, attribute, attribute.ViewType);

var fragment = fragmentView.ToFragment();
if (fragment == null)
Expand Down Expand Up @@ -602,13 +605,13 @@ protected virtual void ShowHostActivity(MvxFragmentPresentationAttribute attribu
{
var elements = new List<string>();

foreach (KeyValuePair<string, View> item in sharedElementsActivity.FetchSharedElementsToAnimate(attribute, request))
foreach (var (key, value) in sharedElementsActivity.FetchSharedElementsToAnimate(attribute, request))
{
var transitionName = item.Value.GetTransitionNameSupport();
var transitionName = value.GetTransitionNameSupport();
if (!string.IsNullOrEmpty(transitionName))
{
fragmentTransaction.AddSharedElement(item.Value, transitionName);
elements.Add($"{item.Key}:{transitionName}");
fragmentTransaction.AddSharedElement(value, transitionName);
elements.Add($"{key}:{transitionName}");
}
else
{
Expand Down Expand Up @@ -704,7 +707,7 @@ protected virtual void OnFragmentPopped(FragmentTransaction? fragmentTransaction
FragmentManager? fragmentManager = null;

// check for a ViewPager inside a Fragment
if (attribute!.FragmentHostViewType != null)
if (attribute.FragmentHostViewType != null)
{
var fragment = GetFragmentByViewType(attribute.FragmentHostViewType);
if (fragment == null)
Expand Down Expand Up @@ -778,7 +781,7 @@ protected virtual void OnFragmentPopped(FragmentTransaction? fragmentTransaction
TabLayout? tabLayout = null;

// check for a ViewPager inside a Fragment
if (attribute?.FragmentHostViewType != null)
if (attribute.FragmentHostViewType != null)
{
var fragment = GetFragmentByViewType(attribute.FragmentHostViewType);

Expand Down Expand Up @@ -833,7 +836,7 @@ protected virtual Task<bool> CloseActivity(IMvxViewModel viewModel, MvxActivityP

string tag = attribute.ViewType.FragmentJavaName();
var toClose = CurrentFragmentManager?.FindFragmentByTag(tag);
if (toClose != null && toClose is DialogFragment dialog)
if (toClose is DialogFragment dialog)
{
dialog.DismissAllowingStateLoss();
return Task.FromResult(true);
Expand Down

0 comments on commit bfb3977

Please sign in to comment.