Beispiel #1
0
        private void DefaultNextAction()
        {
            if (CurrentFragment == null)
            {
                return;
            }

            bool isValid   = false;
            bool canGoNext = false;

            ShowWaitInfo(Resource.String.wizard_validating_title, Resource.String.wizard_validating_story);

            Task.Run(async() =>
            {
                try
                {
                    if (!_isHidden)
                    {
                        isValid   = CurrentFragment.Validate();
                        canGoNext = await CurrentFragment.BeforeGoNextAsync();
                    }
                    else
                    {
                        WizardCache.CachedAction = () =>
                        {
                            Toast.MakeText(this, GetString(Resource.String.action_not_completed),
                                           ToastLength.Long).Show();
                        };
                    }
                }
                catch (Exception exception)
                {
                    Logger.Error(exception);
                    WizardCache.CachedAction = () =>
                    {
                        Toast.MakeText(this, GetString(Resource.String.action_not_completed),
                                       ToastLength.Long).Show();
                    };
                }
                finally
                {
                    HideWait();
                    _fragmentButtons.ButtonNextEnabled = false;
                }

                if (isValid && canGoNext)
                {
                    WizardCache.CachedAction = () =>
                    {
                        _serializedData = CurrentFragment.GetData();
                        RunOnUiThread(() => Go(true));
                    };

                    if (!_isHidden)
                    {
                        RunCachedAction();
                    }
                }
            });
        }
Beispiel #2
0
 public IILEmitter Emit(Instruction instr)
 {
     if (_replaceQueue != null && _replaceQueue.Count > 0)
     {
         instr = Copy(_replaceQueue.Dequeue(), instr);
     }
     CurrentFragment.Add(instr);
     return(this);
 }
Beispiel #3
0
        private void FragmentButtons_NextClicked(object sender, EventArgs e)
        {
            if (CurrentFragment.OnNextClicked == default(Action))
            {
                this.DefaultNextAction();
                return;
            }

            CurrentFragment.OnNextClicked();
        }
Beispiel #4
0
        private void DefaultPreviousAction()
        {
            if (CurrentFragment == null)
            {
                return;
            }

            _serializedData = CurrentFragment.GetData();
            this.Go(false);
        }
Beispiel #5
0
        private void FragmentButtons_PrevClicked(object sender, EventArgs e)
        {
            if (CurrentFragment.OnPreviousClicked == default(Action))
            {
                this.DefaultPreviousAction();
                return;
            }

            CurrentFragment.OnPreviousClicked();
        }
Beispiel #6
0
        /// <summary>
        /// Remove all fragments from the back stack up to, but not including the specified view.
        /// </summary>
        /// <remarks>
        /// If the specified view is not found then all fragments will be removed up to, but not including, the initial view.
        /// </remarks>
        public void CloseUpToView(Type viewModelType)
        {
            var targetFragmentType  = SupportedFragmentViewModels[viewModelType];
            var backStackEntryCount = FragmentManager.BackStackEntryCount;

            for (var i = 0; i < backStackEntryCount; i++)
            {
                if (CurrentFragment.GetType() == targetFragmentType)
                {
                    break;
                }

                FragmentManager.PopBackStackImmediate();
            }

            this.FragmentChanged();
        }
Beispiel #7
0
        /// <summary>
        /// Given a view model attempts to close the fragment associated with it. If the fragment
        /// associated is currently being displayed in the fragment host then the backstack
        /// is popped.
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public bool Close(IMvxViewModel viewModel)
        {
            var fragmentTypeToClose = SupportedFragmentViewModels[viewModel.GetType()];

            if (CurrentFragment != null && CurrentFragment.GetType() == fragmentTypeToClose)
            {
                FragmentManager.PopBackStackImmediate();

                this.FragmentChanged();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #8
0
        /// <summary>
        /// This method does the actual loading of the fragment depending on current step.
        /// </summary>
        private void LoadFragment()
        {
            if (_currentFragmentType == null)
            {
                throw new InvalidOperationException("Cannot load fragment if there is CurrentFragmentType == null.");
            }

            // load the fragment needed
            CurrentFragment = Activator.CreateInstance(_currentFragmentType) as WizardStepFragment;

            if (CurrentFragment == null)
            {
                throw new Exception("Fragments used for steps in the wizard must inherit WizardStepFragment. Yours does not.");
            }


            if (!StepsHistory.ContainsKey(_currentStep))
            {
                StepsHistory.Add(_currentStep, CurrentFragment.GetType());
            }
            else
            {
                StepsHistory[_currentStep] = CurrentFragment.GetType();
            }

            if (!_serializedData.IsBlank())
            {
                RunOnUiThread(() => { CurrentFragment.SetData(_serializedData); });
            }

            // load the actual fragment needed
            if (!_isHidden)
            {
                SupportFragmentManager.BeginTransaction()
                .Replace(Resource.Id.frameContent, CurrentFragment, CurrentFragment.FragmentTag)
                .Commit();
            }


            this.SetButtonTitles();

            _fragmentButtons.SelectStep(_currentStep);
            HideKeyboard(true);
        }
Beispiel #9
0
        /// <summary>
        /// This method will initiate going back or forward depending on boolean given.
        /// </summary>
        /// <param name="goNext">True if go next, otherwise pass false</param>
        public void Go(bool goNext)
        {
            _serializedData = CurrentFragment.GetData();

            bool goPrevious = !goNext;

            if (goNext)
            {
                if (!CurrentFragment.IsLastStep)
                {
                    _currentStep++;
                }

                _currentFragmentType = CurrentFragment.GetNextFragment();
            }
            else
            {
                _currentStep--;
                if (!StepsHistory.ContainsKey(_currentStep))
                {
                    return;
                }

                _currentFragmentType = StepsHistory[_currentStep];
            }

            // if the final step, finish the wizard, otherwise load fragment
            if (!CurrentFragment.IsLastStep || goPrevious)
            {
                LoadFragment();
            }
            else
            {
                CurrentFragment.FinishWizard();
                WizardFinished = true;
            }
        }