Ejemplo n.º 1
0
        private List <PushOperation> Push(List <PushInformation <TViewModel> > pushInformations)
        {
            List <PushOperation>    pushOperations = new List <PushOperation>();
            InnerStack <TViewModel> top            = null;

            if (_innerStacks.Count > 0)
            {
                top = _innerStacks[_innerStacks.Count - 1];
            }

            foreach (var pushInformation in pushInformations)
            {
                if (pushInformation.Factory is ActivityViewFactory activityViewFactory)
                {
                    var activityInnerStack = new ActivityInnerStack <TViewModel>(this, activityViewFactory.ActivityType, activityIsOnlyAFragmentContainer: false, shouldClearHistory: activityViewFactory.ShouldClearHistory);
                    pushOperations.Add(new ActivityPushOperation <TViewModel>(activityInnerStack, pushInformation.Instance.ViewModelInstance));
                    top = activityInnerStack;
                    _innerStacks.Add(top);
                }
                else if (pushInformation.Factory is DialogFragmentViewFactory dialogFragmentViewFactory)
                {
                    var host = top.GetActivityInnerStack();
                    if (host == null)
                    {
                        //need to push the activity first
                        var activityInnerStack = new ActivityInnerStack <TViewModel>(this, dialogFragmentViewFactory.HostActivityType, activityIsOnlyAFragmentContainer: true, shouldClearHistory: dialogFragmentViewFactory.ShouldClearHistory);
                        pushOperations.Add(new ActivityPushOperation <TViewModel>(activityInnerStack, viewModel: null));
                        top = host = activityInnerStack;
                        _innerStacks.Add(top);
                    }

                    var fragment = dialogFragmentViewFactory.Creator();

                    //we set screeninformation to the fragment can retrieve its viewmodel
                    if (fragment is IScreenView screenView)
                    {
                        screenView.ScreenRoute = pushInformation.Instance.ToString();
                        _viewModelLocatorService.AddViewModel(pushInformation.Instance.ToString(), pushInformation.Instance.ViewModelInstance);
                    }

                    var dialogFragmentInnerStack = new DialogFragmentInnerStack <TViewModel>(this, host, fragment);
                    pushOperations.Add(new FragmentPushOperation <TViewModel>(host)
                    {
                        FragmentStacksToPush =
                        {
                            dialogFragmentInnerStack
                        }
                    });
                    top = dialogFragmentInnerStack;
                    _innerStacks.Add(top);
                }
                else if (pushInformation.Factory is FragmentViewFactory fragmentViewFactory)
                {
                    var activityHost = top.GetActivityInnerStack();
                    if (activityHost == null)
                    {
                        //need to push the activity first
                        var activityInnerStack = new ActivityInnerStack <TViewModel>(this, fragmentViewFactory.HostActivityType, activityIsOnlyAFragmentContainer: true, shouldClearHistory: fragmentViewFactory.ShouldClearHistory);
                        pushOperations.Add(new ActivityPushOperation <TViewModel>(activityInnerStack, viewModel: null));
                        top = activityHost = activityInnerStack;
                        _innerStacks.Add(top);
                    }

                    var fragment = fragmentViewFactory.Creator();

                    //we set screeninformation to the fragment can retrieve its viewmodel
                    if (fragment is IScreenView screenView)
                    {
                        screenView.ScreenRoute = pushInformation.Instance.ToString();
                        _viewModelLocatorService.AddViewModel(pushInformation.Instance.ToString(), pushInformation.Instance.ViewModelInstance);
                    }

                    var fragmentInnerStack = new FragmentInnerStack <TViewModel>(this, activityHost, fragment);
                    pushOperations.Add(new FragmentPushOperation <TViewModel>(activityHost)
                    {
                        FragmentStacksToPush =
                        {
                            fragmentInnerStack
                        }
                    });
                    activityHost.FragmentStack.Add(fragmentInnerStack);
                }
                else
                {
                    throw new InvalidOperationException("This kind of factory is not supported...");
                }
            }

            //simplify list of pop operations
            int insertIndex = 0;

            for (int i = 1; i < pushOperations.Count; i++)
            {
                if (TryMerge(pushOperations[insertIndex], pushOperations[i], out PushOperation op))
                {
                    pushOperations[insertIndex] = op;
                }
                else
                {
                    insertIndex++;
                    if (insertIndex != i)
                    {
                        pushOperations[insertIndex] = pushOperations[i];
                    }
                }
            }

            if (insertIndex < pushOperations.Count - 1)
            {
                int firstIndexToRemove = insertIndex + 1;
                pushOperations.RemoveRange(firstIndexToRemove, pushOperations.Count - firstIndexToRemove);
            }

            return(pushOperations);
        }
 public MergedFragmentPopPushOperation(ActivityInnerStack <TViewModel> hostStack, List <IFragmentInnerStack> fragmentStacksToPop, List <IFragmentInnerStack> fragmentStacksToPush)
 {
     HostStack            = hostStack;
     FragmentStacksToPop  = fragmentStacksToPop;
     FragmentStacksToPush = fragmentStacksToPush;
 }
Ejemplo n.º 3
0
 public FragmentPopOperation(ActivityInnerStack <TViewModel> hostStack)
 {
     HostStack = hostStack;
 }
Ejemplo n.º 4
0
 public ActivityPushOperation(ActivityInnerStack <TViewModel> activityStack, IViewModel viewModel)
 {
     ActivityStack = activityStack;
     ViewModel     = viewModel;
 }
Ejemplo n.º 5
0
 public ActivityPopOperation(ActivityInnerStack <TViewModel> activityStack)
 {
     ActivityStack = activityStack;
 }