コード例 #1
0
 public override sealed void Close(IMvxViewModel viewModel)
 {
     if (_fragmentHostRegistrationSettings.IsTypeRegisteredAsFragment(viewModel.GetType()))
         CloseFragment(viewModel);
     else
         CloseActivity(viewModel);
 }
コード例 #2
0
        public void Bind(IMvxViewModel viewModel, IMvxBundle parameterValues = null, IMvxBundle savedState = null)
        {
            var controllerAware = viewModel as IControllerAware;
            if (controllerAware != null)
            {
                var viewModelType = viewModel.GetType();
                var name = viewModelType.FullName.Replace("ViewModel", "Controller");

                Type controllerType = GetControllerTypeForViewModel(_getCreateableTypes(), viewModel);

                if (controllerType == null)
                {
                    throw new ArgumentException(string.Format("Controller for view model {0} cannot be found.", viewModelType));
                }

                try
                {
                    var controller = (IMvxController) Mvx.IocConstruct(controllerType);
                    controllerAware.AttachController(controller);

                    var viewModelAware = controller as IViewModelAware;
                    if (viewModelAware != null)
                    {
                        viewModelAware.AttachViewModel(viewModel);
                    }

                    try
                    {
                        CallControllerInitMethods(controller, parameterValues);
                        if (savedState != null)
                        {
                            CallReloadStateMethods(controller, savedState);
                        }

                    }
                    catch (Exception ex)
                    {
                        MvxTrace.Error("MvxControllers: Problem initialising controller of type {0} - problem {1}",
                            controllerType.Name, ex.ToLongString());

                        throw;
                    }

                    controller.WaitForInitialize();
                }
                catch (Exception ex)
                {
                    MvxTrace.Error("MvxControllers: Problem creating controller of type {0} - problem {1}",
                        controllerType,
                        ex.ToLongString());

                    throw;
                }
            }
        }
コード例 #3
0
        public void RequestClose(IMvxViewModel viewModel)
        {
            var topPage = _frame.Content;
            var view = topPage as IMvxView;

            if (view == null)
            {
                MvxTrace.Trace("request close ignored for {0} - no current view", viewModel.GetType().Name);
                return;
            }

            if (view.ViewModel != viewModel)
            {
                MvxTrace.Trace("request close ignored for {0} - current view is registered for a different viewmodel of type {1}", viewModel.GetType().Name, view.ViewModel.GetType().Name);
                return;
            }

            MvxTrace.Trace("request close for {0} - will close current page {1}", viewModel.GetType().Name, view.GetType().Name);
            _frame.GoBack();
        }
コード例 #4
0
        public void RequestClose(IMvxViewModel viewModel)
        {
            var nav = MasterNavigationController;
            var top = nav.TopViewController;
            var view = top as IMvxTouchView;

            if (view == null)
            {
                MvxTrace.Trace("request close ignored for {0} - no current view controller", viewModel.GetType().Name);
                return;
            }

            if (view.ViewModel != viewModel)
            {
                MvxTrace.Trace("request close ignored for {0} - current view controller is registered for a different viewmodel of type {1}", viewModel.GetType().Name, view.ViewModel.GetType().Name);
                return;
            }

            MvxTrace.Trace("request close for {0} - will close current view controller {1}", viewModel.GetType().Name, view.GetType().Name);
            nav.PopViewControllerAnimated(true);
        }
コード例 #5
0
 public virtual bool Close(IMvxViewModel viewModel)
 {
     //Workaround for closing fragments. This will not work when showing multiple fragments of the same viewmodel type in one activity
     var frag = GetCurrentCacheableFragmentsInfo ().FirstOrDefault (x => x.ViewModelType == viewModel.GetType());
     if (frag == null)
     {
         return false;
     }
     // Close method can not be fully fixed at this moment. That requires some changes in main MvvmCross library
     CloseFragment(frag.Tag, frag.ContentId);
     return true;
 }
        public void RequestClose(IMvxViewModel viewModel)
        {
            var topActivity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>();
            
            var activity = topActivity.Activity;
            var view = activity as IMvxAndroidView;

            if (view == null)
            {
                MvxTrace.Trace("request close ignored for {0} - no current activity", viewModel.GetType().Name);
                return;
            }
            
            if (view.ViewModel != viewModel)
            {
                MvxTrace.Trace("request close ignored for {0} - current activity is registered for a different viewmodel of type {1}", viewModel.GetType().Name, view.ViewModel.GetType().Name);
                return;
            }

            MvxTrace.Trace("request close for {0} - will close current activity {1}", viewModel.GetType().Name, view.GetType().Name);
            activity.Finish();
        }
コード例 #7
0
        public virtual IMvxTouchView CreateView(IMvxViewModel viewModel)
        {
            var viewModelType = viewModel.GetType();
            var request = MvxShowViewModelRequest.GetDefaultRequest(viewModelType);
            var view = CreateView(request);
            var viewModelProperty = view.GetType().GetProperty("ViewModel");
            if (viewModelProperty == null)
                throw new MvxException("ViewModel Property missing for " + view.GetType());

            if (!viewModelProperty.CanWrite)
                throw new MvxException("ViewModel Property readonly for " + view.GetType());

            viewModelProperty.SetValue(view, viewModel, null);
            return view;
        }
コード例 #8
0
 protected void RunViewModelLifecycle(IMvxViewModel viewModel, IMvxBundle parameterValues, IMvxBundle savedState)
 {
     try
     {
         CallCustomInitMethods(viewModel, parameterValues);
         if (savedState != null)
         {
             CallReloadStateMethods(viewModel, savedState);
         }
         viewModel.Start();
     }
     catch (Exception exception)
     {
         throw exception.MvxWrap("Problem running viewModel lifecycle of type {0}", viewModel.GetType().Name);
     }
 }
コード例 #9
0
        public override async ValueTask <bool> Close(IMvxViewModel toClose)
        {
            // toClose is window
            if (FrameworkElementsDictionary.Any(i => (i.Key as IMvxWpfView)?.ViewModel == toClose) && await CloseWindow(toClose).ConfigureAwait(false))
            {
                return(true);
            }

            // toClose is content
            if (FrameworkElementsDictionary.Any(i => i.Value.Any() && (i.Value.Peek() as IMvxWpfView)?.ViewModel == toClose) && await CloseContentView(toClose).ConfigureAwait(false))
            {
                return(true);
            }

            MvxLog.Instance.Warn($"Could not close ViewModel type {toClose?.GetType().Name}");
            return(false);
        }
コード例 #10
0
 public MvxViewPagerFragmentInfo(string title, string tag, Type fragmentType, IMvxViewModel viewModel, object parameterValuesObject = null)
     : this(title, tag, fragmentType, viewModel.GetType(), parameterValuesObject)
 {
     ViewModel = viewModel;
 }
コード例 #11
0
 public IMvxControl GetControl(IMvxViewModel viewModelType)
 {
     return GetControl(viewModelType.GetType());
 }
コード例 #12
0
 public Task <TResult> Navigate <TParameter, TResult>(IMvxViewModel <TParameter, TResult> viewModel, TParameter param, IMvxBundle presentationBundle = null, CancellationToken cancellationToken = default)
 {
     LastNavigatedViewModel = viewModel.GetType();
     return(Task.FromResult(default(TResult)));
 }
コード例 #13
0
        public virtual bool Close(IMvxViewModel viewModel)
        {
            if (FragmentManager.BackStackEntryCount == 0)
            {
                base.OnBackPressed();
                return(true);
            }

            //Workaround for closing fragments. This will not work when showing multiple fragments of the same viewmodel type in one activity
            var frag = GetCurrentCacheableFragmentsInfo().FirstOrDefault(x => x.ViewModelType == viewModel.GetType());

            if (frag == null)
            {
                return(false);
            }

            // Close method can not be fully fixed at this moment. That requires some changes in main MvvmCross library
            CloseFragment(frag.Tag, frag.ContentId);
            return(true);
        }
コード例 #14
0
 private static void RunViewModelLifecycle(IMvxViewModel viewModel, IMvxBundle savedState,
     MvxViewModelRequest request)
 {
     try
     {
         if (request != null)
         {
             var parameterValues = new MvxBundle(request.ParameterValues);
             viewModel.CallBundleMethods("Init", parameterValues);
         }
         if (savedState != null)
         {
             viewModel.CallBundleMethods("ReloadState", savedState);
         }
         viewModel.Start();
     }
     catch (Exception exception)
     {
         throw exception.MvxWrap("Problem running viewModel lifecycle of type {0}", viewModel.GetType().Name);
     }
 }
コード例 #15
0
 public override Task <TResult> Navigate <TParameter, TResult>(IMvxViewModel <TParameter, TResult> viewModel, TParameter param, IMvxBundle presentationBundle = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     analyticsService.TrackCurrentPage(viewModel.GetType());
     return(base.Navigate <TParameter, TResult>(viewModel, param, presentationBundle, cancellationToken));
 }
コード例 #16
0
 protected void RunViewModelLifecycle(IMvxViewModel viewModel, IMvxBundle parameterValues = null, IMvxBundle savedState = null)
 {
     try
     {
         this.CallCustomInitMethods(viewModel, parameterValues);
         if (savedState != null)
         {
             this.CallReloadStateMethods(viewModel, savedState);
         }
         viewModel.Start();
     }
     catch (Exception exception)
     {
         throw exception.MvxWrap("Problem running viewModel lifecycle of type {0}", viewModel.GetType().Name);
     }
 }
コード例 #17
0
        protected void RunViewModelLifecycle(IMvxViewModel viewModel, IMvxBundle parameterValues, IMvxBundle savedState)
        {
            try
            {
                CallCustomInitMethods(viewModel, parameterValues);
                if (savedState != null)
                {
                    CallReloadStateMethods(viewModel, savedState);
                }
                viewModel.Start();

                viewModel.Prepare();

                viewModel.InitializeTask = MvxNotifyTask.Create(() => viewModel.Initialize());
            }
            catch (Exception exception)
            {
                throw exception.MvxWrap("Problem running viewModel lifecycle of type {0}", viewModel.GetType().Name);
            }
        }
コード例 #18
0
        private UIViewController GetLastPresentedControllerForViewModel(UINavigationController lastNotNullPresentedController, IMvxViewModel viewModel)
        {
            var mvxViewController = lastNotNullPresentedController.TopViewController as IMvxIosView;

            return(mvxViewController != null && mvxViewController.ViewModel.GetType() == viewModel.GetType() ?
                   lastNotNullPresentedController
                                                 :
                   GetLastPresentedController(lastNotNullPresentedController.PresentedViewController));
        }
コード例 #19
0
 public MvxViewModelInstanceRequest(IMvxViewModel viewModelInstance)
     : base(viewModelInstance.GetType(), null, null, MvxRequestedBy.Unknown)
 {
     this._viewModelInstance = viewModelInstance;
 }
コード例 #20
0
 public MenuItem(IMvxViewModel viewModel, HomeViewModel parent)
 {
     Name      = viewModel.GetType().Name.Replace("ViewModel", "");
     ViewModel = viewModel;
     _parent   = parent;
 }
コード例 #21
0
 public IMvxControl GetControl(IMvxViewModel viewModelType)
 {
     return(GetControl(viewModelType.GetType()));
 }
コード例 #22
0
 private static void RunViewModelLifecycle(IMvxViewModel viewModel, IMvxBundle savedState,
                                           MvxViewModelRequest request)
 {
     try
     {
         var parameterValues = new MvxBundle(request.ParameterValues);
         viewModel.CallBundleMethods("Init", parameterValues);
         if (savedState != null)
         {
             viewModel.CallBundleMethods("ReloadState", savedState);
         }
         viewModel.Start();
     }
     catch (Exception exception)
     {
         throw exception.MvxWrap("Problem running viewModel lifecycle of type {0}", viewModel.GetType().Name);
     }
 }
コード例 #23
0
        protected virtual bool CloseRootViewController(IMvxViewModel viewModel, MvxRootPresentationAttribute attribute)
        {
            Mvx.Warning($"Ignored attempt to close the window root (ViewModel type: {viewModel.GetType().Name}");

            return(false);
        }
コード例 #24
0
        public void RequestClose(IMvxViewModel viewModel)
        {
            var nav  = MasterNavigationController;
            var top  = nav.TopViewController;
            var view = top as IMvxTouchView;

            if (view == null)
            {
                MvxTrace.Trace("request close ignored for {0} - no current view controller", viewModel.GetType().Name);
                return;
            }

            if (view.ViewModel != viewModel)
            {
                MvxTrace.Trace("request close ignored for {0} - current view controller is registered for a different viewmodel of type {1}", viewModel.GetType().Name, view.ViewModel.GetType().Name);
                return;
            }

            MvxTrace.Trace("request close for {0} - will close current view controller {1}", viewModel.GetType().Name, view.GetType().Name);
            nav.PopViewControllerAnimated(true);
        }
コード例 #25
0
        protected void RunViewModelLifecycle <TParameter>(IMvxViewModel <TParameter> viewModel, TParameter param, IMvxBundle parameterValues, IMvxBundle savedState, IMvxNavigateEventArgs navigationArgs)
        {
            try
            {
                CallCustomInitMethods(viewModel, parameterValues);
                if (navigationArgs?.Cancel == true)
                {
                    return;
                }
                if (savedState != null)
                {
                    CallReloadStateMethods(viewModel, savedState);
                    if (navigationArgs?.Cancel == true)
                    {
                        return;
                    }
                }
                viewModel.Start();
                if (navigationArgs?.Cancel == true)
                {
                    return;
                }

                viewModel.Prepare();
                if (navigationArgs?.Cancel == true)
                {
                    return;
                }

                viewModel.Prepare(param);
                if (navigationArgs?.Cancel == true)
                {
                    return;
                }

                viewModel.InitializeTask = MvxNotifyTask.Create(() => viewModel.Initialize());
            }
            catch (Exception exception)
            {
                throw exception.MvxWrap("Problem running viewModel lifecycle of type {0}", viewModel.GetType().Name);
            }
        }
コード例 #26
0
 public override Task Navigate <TParameter>(IMvxViewModel <TParameter> viewModel, TParameter param, IMvxBundle presentationBundle = null)
 {
     analyticsService.TrackCurrentPage(viewModel.GetType());
     return(base.Navigate <TParameter>(viewModel, param, presentationBundle));
 }
コード例 #27
0
 public Task <bool> Navigate(IMvxViewModel viewModel, IMvxBundle presentationBundle = null, CancellationToken cancellationToken = default)
 {
     LastNavigatedViewModel = viewModel.GetType();
     return(Task.FromResult(true));
 }
コード例 #28
0
 public MvxViewModelInstanceRequest(IMvxViewModel viewModelInstance)
     : base(viewModelInstance.GetType(), null, null)
 {
     this._viewModelInstance = viewModelInstance;
 }
コード例 #29
0
        protected override void CallCustomInitMethods(IMvxViewModel viewModel, IMvxBundle parameterValues)
        {
            base.CallCustomInitMethods(viewModel, parameterValues);

            _analytics.LogViewModel(viewModel.GetType().Name);
        }
コード例 #30
0
 public bool Close(IMvxViewModel viewModel)
 {
     CloseFragment(viewModel.GetType().Name, Resource.Id.content_frame);
     return(true);
 }
コード例 #31
0
 public override void Close(IMvxViewModel viewModel)
 {
     GetPresentationAttributeAction(viewModel.GetType(), out MvxBasePresentationAttribute attribute).CloseAction.Invoke(viewModel, attribute);
 }
 public FragmentInfo(string title, string tag, Type fragmentType, IMvxViewModel viewModel, object parameterValuesObject = null)
     : this(title, tag, fragmentType, viewModel.GetType(), parameterValuesObject)
 {
     ViewModel = viewModel;
 }
コード例 #33
0
        public virtual Tuple<Intent, int> GetIntentWithKeyFor(IMvxViewModel viewModel)
        {
            var request = MvxViewModelRequest.GetDefaultRequest(viewModel.GetType());
            var intent = this.GetIntentFor(request);

            var key = Mvx.Resolve<IMvxChildViewModelCache>().Cache(viewModel);
            intent.PutExtra(SubViewModelKey, key);

            return new Tuple<Intent, int>(intent, key);
        }
コード例 #34
0
 public MvxViewModelInstanceRequest(IMvxViewModel viewModelInstance)
     : base(viewModelInstance.GetType(), null, null, MvxRequestedBy.Unknown)
 {
     _viewModelInstance = viewModelInstance;
 }
コード例 #35
0
 public override Task Navigate(IMvxViewModel viewModel, IMvxBundle presentationBundle = null)
 {
     analyticsService.CurrentPage.Track(viewModel.GetType());
     return(base.Navigate(viewModel, presentationBundle));
 }
コード例 #36
0
        protected virtual Type GetControllerTypeForViewModel(IEnumerable<Type> createableTypes, IMvxViewModel viewModel)
        {
            var name = viewModel.GetType().FullName.Replace("ViewModel", "Controller");

            var controllerType = createableTypes.FirstOrDefault(t => t.FullName == name);

            if (controllerType == null)
            {
                throw new ArgumentException(string.Format("Controller type {0} cannot be found.", name));
            }

            return controllerType;
        }
コード例 #37
0
        public void RequestClose(IMvxViewModel viewModel)
        {
            var topActivity = Mvx.Resolve <IMvxAndroidCurrentTopActivity>();

            var activity = topActivity.Activity;
            var view     = activity as IMvxAndroidView;

            if (view == null)
            {
                MvxTrace.Trace("request close ignored for {0} - no current activity", viewModel.GetType().Name);
                return;
            }

            if (view.ViewModel != viewModel)
            {
                MvxTrace.Trace("request close ignored for {0} - current activity is registered for a different viewmodel of type {1}", viewModel.GetType().Name, view.ViewModel.GetType().Name);
                return;
            }

            MvxTrace.Trace("request close for {0} - will close current activity {1}", viewModel.GetType().Name, view.GetType().Name);
            activity.Finish();
        }
コード例 #38
0
        protected virtual Task <bool> CloseRootViewController(IMvxViewModel viewModel, MvxRootPresentationAttribute attribute)
        {
            MvxLog.Instance.Warn($"Ignored attempt to close the window root (ViewModel type: {viewModel.GetType().Name}");

            return(Task.FromResult(false));
        }
コード例 #39
0
        public override async Task <bool> Close(IMvxViewModel toClose)
        {
            // toClose is window
            if (FrameworkElementsDictionary.Any(i => (i.Key as IMvxWpfView)?.ViewModel == toClose) && await CloseWindow(toClose))
            {
                return(true);
            }

            // toClose is content
            if (FrameworkElementsDictionary.Any(i => i.Value.Any() && (i.Value.Peek() as IMvxWpfView)?.ViewModel == toClose) && await CloseContentView(toClose))
            {
                return(true);
            }

            MvxLogHost.Default?.Log(LogLevel.Warning, "Could not close ViewModel type {ViewModelTypeName}", toClose.GetType().Name);
            return(false);
        }