Ejemplo n.º 1
0
        protected virtual MvxBasePresentationAttribute CreateAttributeForViewModel(Type viewModelType)
        {
            var viewType = ViewsContainer.GetViewType(viewModelType);

            if (viewType.IsSubclassOf(typeof(DialogFragment)))
            {
                MvxTrace.Trace("PresentationAttribute not found for {0}. Assuming DialogFragment presentation", viewModelType.Name);
                return(new MvxDialogFragmentPresentationAttribute()
                {
                    ViewType = viewType, ViewModelType = viewModelType
                });
            }

            if (viewType.IsSubclassOf(typeof(Fragment)))
            {
                MvxTrace.Trace("PresentationAttribute not found for {0}. Assuming Fragment presentation", viewModelType.Name);
                return(new MvxFragmentPresentationAttribute(GetCurrentActivityViewModelType(), Android.Resource.Id.Content)
                {
                    ViewType = viewType, ViewModelType = viewModelType
                });
            }

            MvxTrace.Trace("PresentationAttribute not found for {0}. Assuming Activity presentation", viewModelType.Name);
            return(new MvxActivityPresentationAttribute()
            {
                ViewType = viewType, ViewModelType = viewModelType
            });
        }
Ejemplo n.º 2
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            ViewsContainer container = new ViewsContainer();

            ViewsContainer.mainView = new MainWindow();
            ViewsContainer.mainView.Show();
        }
        public virtual MvxBasePresentationAttribute GetPresentationAttribute(MvxViewModelRequest request)
        {
            var viewType = ViewsContainer.GetViewType(request.ViewModelType);

            var overrideAttribute = GetOverridePresentationAttribute(request, viewType);

            if (overrideAttribute != null)
            {
                return(overrideAttribute);
            }

            var attribute = viewType
                            .GetCustomAttributes(typeof(MvxBasePresentationAttribute), true)
                            .FirstOrDefault() as MvxBasePresentationAttribute;

            if (attribute != null)
            {
                if (attribute.ViewType == null)
                {
                    attribute.ViewType = viewType;
                }

                if (attribute.ViewModelType == null)
                {
                    attribute.ViewModelType = request.ViewModelType;
                }

                return(attribute);
            }

            return(CreatePresentationAttribute(request.ViewModelType, viewType));
        }
Ejemplo n.º 4
0
        protected virtual void ShowHostActivity(MvxFragmentPresentationAttribute attribute)
        {
            ValidateArguments(attribute);

            if (attribute.ActivityHostViewModelType == null)
            {
                throw new ArgumentException("ActivityHostViewModelType not set on attribute");
            }

            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);

            if (PendingRequest != null)
            {
                hostViewModelRequest.PresentationValues = PendingRequest.PresentationValues;
            }

            Show(hostViewModelRequest);
        }
Ejemplo n.º 5
0
 public ViewFactory(CanvasContainer canvasContainer, ViewsContainer viewsContainer,
                    ICameraManager cameraManager, ILoggerManager loggerManager)
 {
     _cameraManager   = cameraManager;
     _canvasContainer = canvasContainer;
     _viewsContainer  = viewsContainer;
     _logger          = loggerManager.GetLogger();
 }
Ejemplo n.º 6
0
 public void RemoveEnemy(EnemyView inEnemyView)
 {
     inEnemyView.RemoveAllComponents();
     inEnemyView.Visibility = false;
     SystemFacade.Level.Level.RemoveView(inEnemyView.name, inEnemyView.index);
     ViewsContainer.RemoveView(inEnemyView);
     Enemies.Remove(inEnemyView);
     Object.Destroy(inEnemyView.gameObject);
 }
Ejemplo n.º 7
0
        protected virtual void ShowHostActivity(MvxFragmentPresentationAttribute attribute)
        {
            var viewType = ViewsContainer.GetViewType(attribute.ActivityHostViewModelType);
            if (!viewType.IsSubclassOf(typeof(Activity)))
                throw new MvxException("The host activity doesn't inherit Activity");

            var hostViewModelRequest = MvxViewModelRequest.GetDefaultRequest(attribute.ActivityHostViewModelType);
            hostViewModelRequest.PresentationValues = _pendingRequest.PresentationValues;
            Show(hostViewModelRequest);
        }
Ejemplo n.º 8
0
 private void InitializeHelpers()
 {
     // --------------------------------------------------------------------------------
     // Create and Initialize Helper classes
     // --------------------------------------------------------------------------------
     ViewsContainer = new ViewsContainer(this);
     ObjectMap.Initialize(this);
     SystemFacade.Initialize(this);
     ViewFacade.Initialize(this);
 }
Ejemplo n.º 9
0
        public override async ValueTask<MvxBasePresentationAttribute?> GetPresentationAttribute(MvxViewModelRequest request)
        {
            var viewType = ViewsContainer.GetViewType(request.ViewModelType);

            var overrideAttribute = await GetOverridePresentationAttribute(request, viewType).ConfigureAwait(false);
            if (overrideAttribute != null)
                return overrideAttribute;

            IList<MvxBasePresentationAttribute> attributes = viewType.GetCustomAttributes<MvxBasePresentationAttribute>(true).ToList();
            if (attributes?.Count > 0)
            {
                MvxBasePresentationAttribute? attribute = null;

                if (attributes.Count > 1)
                {
                    var fragmentAttributes = attributes.OfType<MvxFragmentPresentationAttribute>();

                    // check if fragment can be displayed as child fragment first
                    foreach (var item in fragmentAttributes.Where(att => att.FragmentHostViewType != null))
                    {
                        var fragment = GetFragmentByViewType(item.FragmentHostViewType);

                        // if the fragment exists, and is on top, then use the current attribute 
                        if (fragment != null && fragment.IsVisible && fragment.View.FindViewById(item.FragmentContentId) != null)
                        {
                            attribute = item;
                            break;
                        }
                    }

                    // if attribute is still null, check if fragment can be displayed in current activity
                    if (attribute == null)
                    {
                        var currentActivityHostViewModelType = GetCurrentActivityViewModelType();
                        foreach (var item in fragmentAttributes.Where(att => att.ActivityHostViewModelType != null))
                        {
                            if (CurrentActivity.FindViewById(item.FragmentContentId) != null && item.ActivityHostViewModelType == currentActivityHostViewModelType)
                            {
                                attribute = item;
                                break;
                            }
                        }
                    }
                }

                if (attribute == null)
                    attribute = attributes.FirstOrDefault();

                attribute.ViewType = viewType;

                return attribute;
            }

            return await CreatePresentationAttribute(request.ViewModelType, viewType).ConfigureAwait(false);
        }
Ejemplo n.º 10
0
        public void RemovePlayer()
        {
            Player.OnTakeDamage -= OnPlayerTakeDamage;
            Player.Destroyed    -= OnPlayerDie;
            SystemFacade.Level.Level.RemoveView(Player.name, Player.index);
            ViewsContainer.RemoveView(Player);
            Object.Destroy(Player.gameObject);
            Player = null;

            Log("Game is over !!");
        }
Ejemplo n.º 11
0
        public virtual MvxBasePresentationAttribute GetPresentationAttribute(MvxViewModelRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (request.ViewModelType == null)
            {
                throw new InvalidOperationException("Cannot get view types for null ViewModelType");
            }

            if (ViewsContainer == null)
            {
                throw new InvalidOperationException($"Cannot get view types from null {nameof(ViewsContainer)}");
            }

            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)
            {
                return(overrideAttribute);
            }

            var attribute = viewType
                            .GetCustomAttributes(typeof(MvxBasePresentationAttribute), true)
                            .FirstOrDefault();

            if (attribute is MvxBasePresentationAttribute basePresentationAttribute)
            {
                if (basePresentationAttribute.ViewType == null)
                {
                    basePresentationAttribute.ViewType = viewType;
                }

                if (basePresentationAttribute.ViewModelType == null)
                {
                    basePresentationAttribute.ViewModelType = request.ViewModelType;
                }

                return(basePresentationAttribute);
            }

            return(CreatePresentationAttribute(request.ViewModelType, viewType));
        }
Ejemplo n.º 12
0
        protected override void ShowHostActivity(MvxFragmentPresentationAttribute attribute)
        {
            var viewType = ViewsContainer.GetViewType(attribute.ActivityHostViewModelType);

            if (!viewType.IsSubclassOf(typeof(FragmentActivity)))
            {
                throw new MvxException("The host activity doesnt inherit FragmentActivity");
            }

            var hostViewModelRequest = MvxViewModelRequest.GetDefaultRequest(attribute.ActivityHostViewModelType);

            Show(hostViewModelRequest);
        }
Ejemplo n.º 13
0
        public override void ChangePresentation(MvxPresentationHint hint)
        {
            var navigation = GetPageOfType <NavigationPage>().Navigation;

            if (hint is MvxPopToRootPresentationHint popToRootHint)
            {
                navigation.PopToRootAsync(popToRootHint.Animated);
                return;
            }
            if (hint is MvxPopPresentationHint popHint)
            {
                foreach (var page in navigation.NavigationStack)
                {
                    page.Navigation.PopAsync(popHint.Animated);
                    if (page is IMvxPage mvxPage && mvxPage.ViewModel.GetType() == popHint.ViewModelToPopTo)
                    {
                        return;
                    }
                }
                return;
            }
            if (hint is MvxRemovePresentationHint removeHint)
            {
                var page = navigation.NavigationStack
                           .OfType <IMvxPage>()
                           .FirstOrDefault(view => view.ViewModel.GetType() == removeHint.ViewModelToRemove) as Page;
                if (page != null)
                {
                    navigation.RemovePage(page);
                }
                return;
            }
            if (hint is MvxPagePresentationHint pageHint)
            {
                var pageType = ViewsContainer.GetViewType(pageHint.ViewModel);
                if (GetPageOfTypeByType(pageType) is Page page)
                {
                    if (page.Parent is TabbedPage tabbedPage)
                    {
                        tabbedPage.CurrentPage = page;
                    }
                    else if (page.Parent is CarouselPage carouselPage && page is ContentPage contentPage)
                    {
                        carouselPage.CurrentPage = contentPage;
                    }
                }
                return;
            }

            base.ChangePresentation(hint);
        }
Ejemplo n.º 14
0
        public void ResolveWindow_RegisterCommandWIthCommandFactory_CommandsAreResolvedByFactory()
        {
            UnityContainer container = new UnityContainer();

            var viewsContainer = new ViewsContainer(container);
            viewsContainer.With<System.Windows.Window>()
                .RegisterViewModel<DummyViewModel>()
                .RegisterCommand<DummyViewModel>((vm) => vm.CommandA, (v, vm) => new CommandB())
                .RegisterCommand<DummyViewModel>((vm) => vm.CommandB, (v, vm) => new CommandB());

            var resolvedWindow = viewsContainer.ResolveWindow<System.Windows.Window>();

            var dummyViewModel = (DummyViewModel)resolvedWindow.DataContext;
            Assert.IsInstanceOfType(dummyViewModel.CommandA, typeof(CommandB));
            Assert.IsInstanceOfType(dummyViewModel.CommandB, typeof(CommandB));
        }
        private static ConnectionResolverViewModel CreateViewModel()
        {
            var container = new UnityContainer();

            var viewsContainer = new ViewsContainer(container);

            MabadoViewBootLoader viewBootLoader = new MabadoViewBootLoader(container, viewsContainer);

            viewBootLoader.RegisterConnectionResolverModule();

            OverrideMockedDependencies(container);

            ConnectionResolverView view = viewsContainer.ResolveWindow<ConnectionResolverView>();

            var viewModel = view.DataContext as ConnectionResolverViewModel;
            return viewModel;
        }
Ejemplo n.º 16
0
        public override MvxBasePresentationAttribute GetPresentationAttribute(MvxViewModelRequest request)
        {
            ValidateArguments(request);

            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)
            {
                return(overrideAttribute);
            }

            IList <MvxBasePresentationAttribute> attributes =
                viewType.GetCustomAttributes <MvxBasePresentationAttribute>(true).ToList();

            if (attributes.Count > 0)
            {
                MvxBasePresentationAttribute?attribute = null;

                if (attributes.Count > 1)
                {
                    var fragmentAttributes = attributes.OfType <MvxFragmentPresentationAttribute>().ToArray();

                    // check if fragment can be displayed as child fragment first
                    attribute = GetAttributeForFragmentChildPresentation(fragmentAttributes);

                    // if attribute is still null, check if fragment can be displayed in current activity
                    attribute ??= GetAttributeForFragmentPresentation(fragmentAttributes);
                }

                // fallback to first attribute
                attribute ??= attributes[0];
                attribute.ViewType = viewType;

                return(attribute);
            }

            return(CreatePresentationAttribute(request.ViewModelType, viewType));
        }
Ejemplo n.º 17
0
        public PlayerView CreatePlayer()
        {
            // --------------------------------------------------------------------------------
            // Setup Player
            // --------------------------------------------------------------------------------
            //here we can add the ability to select a specific player (if we have more than one)
            Sprites = SystemFacade.Resources.LoadSpriteAtlas(ResourcesMap.Players);
            var player = new PlayerView(this.application, "Player", LayerNames.Player, _config.profile);

            player.SetSprite(Sprites[22]);
            SystemFacade.Level.Level.AddView(player, _config.startPosition);
            ViewsContainer.AddView(player);

            // --------------------------------------------------------------------------------
            // Setup Physics (Add Collider Component)
            // --------------------------------------------------------------------------------
            var boxSize = new Vector2(Sprites[22].bounds.size.x, Sprites[22].bounds.size.y);

            player.AddComponent(new HitBox(player, boxSize, _config.profile.mass));

            // --------------------------------------------------------------------------------
            // Setup Animation (Add Animator Component)
            // --------------------------------------------------------------------------------
            player.profile.SetAnimationsSource(this.Sprites); //set sprite sheet source to all animations
            player.AddComponent(new GameAnimator(player, player.SpriteRenderer));

            // --------------------------------------------------------------------------------
            // Setup Player Controller (Add Control View Component)
            // --------------------------------------------------------------------------------
            player.AddComponent(new ControlView(player, _config.profile));

            // --------------------------------------------------------------------------------
            // Add Parallax Effect to background
            // --------------------------------------------------------------------------------
            SystemFacade.Level.AddParallaxEffect(player);

            // --------------------------------------------------------------------------------
            // Setup Camera follow
            // --------------------------------------------------------------------------------
            SystemFacade.Camera.AddTargetToFollow(player.gameObject.transform);

            return(player);
        }
Ejemplo n.º 18
0
        private bool TryShowPage(MvxViewModelRequest request)
        {
            var viewType = ViewsContainer.GetViewType(request.ViewModelType);
            var page     = FormsPagePresenter.CreatePage(viewType, request, null);

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

            var mainPage = _formsApplication.MainPage as NavigationPage;

            if (mainPage == null)
            {
                _formsApplication.MainPage = new NavigationPage(page);
                mainPage = FormsApplication.MainPage as NavigationPage;
                CustomPlatformInitialization(mainPage);
            }
            else
            {
                try
                {
                    // check for modal presentation parameter
                    string modalParameter;
                    if (request.PresentationValues != null && request.PresentationValues.TryGetValue(ModalPresentationParameter, out modalParameter) && bool.Parse(modalParameter))
                    {
                        mainPage.Navigation.PushModalAsync(page);
                    }
                    else
                    {
                        // calling this sync blocks UI and never navigates hence code continues regardless here
                        mainPage.PushAsync(page);
                    }
                }
                catch (Exception e)
                {
                    Mvx.Error("Exception pushing {0}: {1}\n{2}", page.GetType(), e.Message, e.StackTrace);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 19
0
        public void AddEnemy(Vector2 inPosition, NpcDataHolder inNpcData)
        {
            // --------------------------------------------------------------------------------
            // Setup Player
            // --------------------------------------------------------------------------------
            //here we can add ability to add a specific player (if we have more than one)
            Sprites = SystemFacade.Resources.LoadSpriteAtlas(ResourcesMap.Enemies);
            var enemy = new EnemyView(this.application, inNpcData.name, LayerNames.GameObjects, inNpcData.profile);

            enemy.SetSprite(Sprites[22]);

            // --------------------------------------------------------------------------------
            // Setup Physics (Add Collider Component)
            // --------------------------------------------------------------------------------
            var boxSize = new Vector2(Sprites[22].bounds.size.x, Sprites[22].bounds.size.y);

            enemy.AddComponent(new HitBox(enemy, boxSize, inNpcData.profile.mass, false));

            // --------------------------------------------------------------------------------
            // Setup Animation (Add Animator Component)
            // --------------------------------------------------------------------------------
            enemy.Profile.SetAnimationsSource(this.Sprites); //set sprite sheet source to all animations
            enemy.AddComponent(new GameAnimator(enemy, enemy.SpriteRenderer));

            // --------------------------------------------------------------------------------
            // Setup Controller (Add NpcController Component)
            // --------------------------------------------------------------------------------
            var controller = enemy.AddComponent(new NpcController(enemy, inNpcData.startFacing));

            // --------------------------------------------------------------------------------
            // Setup AI (Add StateMachine Component)
            // --------------------------------------------------------------------------------
            var entryState   = SystemFacade.AI.CreateEnemyAi(controller, inNpcData);
            var stateMachine = enemy.AddComponent(new StateMachine(enemy, entryState));

            stateMachine.Start();

            SystemFacade.Level.Level.AddView(enemy, inPosition);
            ViewsContainer.AddView(enemy);
            Enemies.Add(enemy);
        }
        private Core.Level CreateLevel()
        {
            // --------------------------------------------------------------------------------
            // Setup Level
            // --------------------------------------------------------------------------------
            Level = CreateEmptyLevel();
            Level.Move(Vector2.zero);
            var levelSprite = SystemFacade.Resources.LoadSprite(ResourcesMap.Level);
            var levelView   = new SpriteView(this.application, "Level", LayerNames.Level);

            levelView.SetSprite(levelSprite);
            Level.AddLevel(levelView, new Vector3(0, 0, 1));
            ViewsContainer.AddView(levelView);
            // --------------------------------------------------------------------------------
            // Setup Background
            // --------------------------------------------------------------------------------

            /*var bgPos = new Vector2(
             *      (SystemFacade.Renderer.ScreenWidth / 2 / SystemFacade.Renderer.CurrentResolution)
             *     ,(SystemFacade.Renderer.ScreenHeight / 2 / SystemFacade.Renderer.CurrentResolution));*/

            var bgSprite = SystemFacade.Resources.LoadSprite(ResourcesMap.Background);

            _background = new SpriteView(this.application, "Background", LayerNames.Background);
            _background.SetSprite(bgSprite);

            //- duplicate the background to fit the level platform
            var duplicated = new SpriteView(this.application, "Background", LayerNames.Background);

            duplicated.SetSprite(bgSprite);

            _background.AddChild(duplicated);
            duplicated.SetPosition(new Vector2(_background.GetSize().x, 0));  //apply offset


            Level.AddBackground(_background, _config.backgroundPosition);
            ViewsContainer.AddView(_background);

            return(Level);
        }
        public CameraSystem(GameController inController, Application inApp, SystemConfig inConfig = null) : base(inController, inApp, inConfig)
        {
            // --------------------------------------------------------------------------------
            // Set system config
            // --------------------------------------------------------------------------------
            _config = inConfig as CameraSystemConfig;
            if (_config == null)
            {
                throw new Exception($"System config must be not null.");
            }

            // --------------------------------------------------------------------------------
            // Create Camera view
            // --------------------------------------------------------------------------------
            //cameraView = new CameraView(this.application, Camera.gameObject); //here if we want to set an existing camera from unity
            CameraView = new CameraView(this.application, "Camera", _config);
            ViewsContainer.AddView(CameraView);
            _targetFollow = null;
            // --------------------------------------------------------------------------------
            // Add Camera Shake Component
            // --------------------------------------------------------------------------------
            //Todo : Add camera shake
        }
Ejemplo n.º 22
0
        public async override Task <bool> ChangePresentation(MvxPresentationHint hint)
        {
#if DEBUG // Only wrap in try-finally when in debug
            try
            {
#endif
            var navigation = GetPageOfType <NavigationPage>()?.Navigation;
            if (hint is MvxPopToRootPresentationHint popToRootHint)
            {
                // Make sure all modals are closed
                await CloseAllModals(popToRootHint.Animated);

                // Double check we have a navigation page, otherwise
                // we can just return as we must be already at the root page
                if (navigation == null)
                {
                    return(true);
                }

                // Close all pages back to the root
                await navigation.PopToRootAsync(popToRootHint.Animated);

                return(true);
            }
            if (hint is MvxPopPresentationHint popHint)
            {
                var matched = await PopModalToViewModel(navigation, popHint);

                if (matched)
                {
                    return(true);
                }


                await PopToViewModel(navigation, popHint.ViewModelToPopTo, popHint.Animated);

                return(true);
            }
            if (hint is MvxRemovePresentationHint removeHint)
            {
                foreach (var modal in navigation.ModalStack)
                {
                    var removed = RemoveByViewModel(modal.Navigation, removeHint.ViewModelToRemove);
                    if (removed)
                    {
                        return(true);
                    }
                }

                RemoveByViewModel(navigation, removeHint.ViewModelToRemove);
                return(true);
            }
            if (hint is MvxPagePresentationHint pageHint)
            {
                var pageType = ViewsContainer.GetViewType(pageHint.ViewModel);
                if (GetPageOfTypeByType(pageType) is Page page)
                {
                    if (page.Parent is TabbedPage tabbedPage)
                    {
                        tabbedPage.CurrentPage = page;
                    }
                    else if (page.Parent is CarouselPage carouselPage && page is ContentPage contentPage)
                    {
                        carouselPage.CurrentPage = contentPage;
                    }
                }
                return(true);
            }
            if (hint is MvxPopRecursivePresentationHint popRecursiveHint)
            {
                var levels = popRecursiveHint.LevelsDeep;
                if (levels > navigation.NavigationStack.Count())
                {
                    levels = navigation.NavigationStack.Count();
                }
                for (int i = 0; i < levels; i++)
                {
                    await navigation.PopAsync(popRecursiveHint.Animated);
                }

                return(true);
            }

            return(true);

#if DEBUG // Only showing this when debugging MVX
        }

        finally
        {
            MvxFormsLog.Instance.Trace(FormsApplication.Hierarchy());
        }
#endif
        }
Ejemplo n.º 23
0
 //- Enemies
 public static EnemyView Enemy(string inEnemyName) => ViewsContainer.GetView("inEnemyName") as EnemyView;
Ejemplo n.º 24
0
 public ConnectToLabCommand(IUnityContainer container, ViewsContainer viewsContainer)
 {
     _container = container;
     _viewsContainer = viewsContainer;
 }
Ejemplo n.º 25
0
        public override MvxBasePresentationAttribute GetPresentationAttribute(Type viewModelType)
        {
            var viewType = ViewsContainer.GetViewType(viewModelType);

            var overrideAttribute = GetOverridePresentationAttribute(viewModelType, viewType);

            if (overrideAttribute != null)
            {
                return(overrideAttribute);
            }

            IList <MvxBasePresentationAttribute> attributes = viewType.GetCustomAttributes <MvxBasePresentationAttribute>(true).ToList();

            if (attributes != null && attributes.Count > 0)
            {
                MvxBasePresentationAttribute attribute = null;

                if (attributes.Count > 1)
                {
                    var fragmentAttributes = attributes.OfType <MvxFragmentPresentationAttribute>();

                    // check if fragment can be displayed as child fragment first
                    foreach (var item in fragmentAttributes.Where(att => att.FragmentHostViewType != null))
                    {
                        var fragment = GetFragmentByViewType(item.FragmentHostViewType);

                        // if the fragment exists, and is on top, then use the current attribute
                        if (fragment != null && fragment.IsVisible && fragment.View.FindViewById(item.FragmentContentId) != null)
                        {
                            attribute = item;
                            break;
                        }
                    }

                    // if attribute is still null, check if fragment can be displayed in current activity
                    if (attribute == null)
                    {
                        var currentActivityHostViewModelType = GetCurrentActivityViewModelType();
                        foreach (var item in fragmentAttributes.Where(att => att.ActivityHostViewModelType != null && att.ActivityHostViewModelType == currentActivityHostViewModelType))
                        {
                            // check for MvxTabLayoutPresentationAttribute
                            if (item is MvxTabLayoutPresentationAttribute tabLayoutAttribute &&
                                CurrentActivity.FindViewById(tabLayoutAttribute.TabLayoutResourceId) != null)
                            {
                                attribute = item;
                                break;
                            }

                            // check for MvxViewPagerFragmentPresentationAttribute
                            if (item is MvxViewPagerFragmentPresentationAttribute viewPagerAttribute &&
                                CurrentActivity.FindViewById(viewPagerAttribute.ViewPagerResourceId) != null)
                            {
                                attribute = item;
                                break;
                            }

                            // check for MvxFragmentPresentationAttribute
                            if (CurrentActivity.FindViewById(item.FragmentContentId) != null)
                            {
                                attribute = item;
                                break;
                            }
                        }
                    }
                }

                if (attribute == null)
                {
                    attribute = attributes.FirstOrDefault();
                }

                attribute.ViewType = viewType;

                return(attribute);
            }

            return(CreatePresentationAttribute(viewModelType, viewType));
        }
Ejemplo n.º 26
0
 public MabadoViewBootLoader(IUnityContainer container, ViewsContainer viewsContainer)
 {
     _container = container;
     _viewsContainer = viewsContainer;
 }
Ejemplo n.º 27
0
        protected virtual MvxBasePresentationAttribute GetAttributeForViewModel(Type viewModelType)
        {
            IList <MvxBasePresentationAttribute> attributes;

            if (ViewModelToPresentationAttributeMap.TryGetValue(viewModelType, out attributes))
            {
                MvxBasePresentationAttribute attribute = null;

                if (attributes.Count > 1)
                {
                    var fragmentAttributes = attributes.OfType <MvxFragmentPresentationAttribute>();

                    // check if fragment can be displayed as child fragment first
                    foreach (var item in fragmentAttributes.Where(att => att.FragmentHostViewType != null))
                    {
                        var fragment = GetFragmentByViewType(item.FragmentHostViewType);

                        // if the fragment exists, and is on top, then use the current attribute
                        if (fragment != null && fragment.IsVisible && fragment.View.FindViewById(item.FragmentContentId) != null)
                        {
                            attribute = item;
                            break;
                        }
                    }

                    // if attribute is still null, check if fragment can be displayed in current activity
                    if (attribute == null)
                    {
                        var currentActivityHostViewModelType = GetCurrentActivityViewModelType();
                        foreach (var item in fragmentAttributes.Where(att => att.ActivityHostViewModelType != null))
                        {
                            if (CurrentActivity.FindViewById(item.FragmentContentId) != null && item.ActivityHostViewModelType == currentActivityHostViewModelType)
                            {
                                attribute = item;
                                break;
                            }
                        }
                    }
                }

                if (attribute == null)
                {
                    attribute = attributes.FirstOrDefault();
                }

                if (attribute.ViewType?.GetInterfaces().OfType <IMvxOverridePresentationAttribute>().FirstOrDefault() is IMvxOverridePresentationAttribute view)
                {
                    var presentationAttribute = view.PresentationAttribute();

                    if (presentationAttribute != null)
                    {
                        return(presentationAttribute);
                    }
                }
                return(attribute);
            }

            var viewType = ViewsContainer.GetViewType(viewModelType);

            if (viewType.IsSubclassOf(typeof(DialogFragment)))
            {
                MvxTrace.Trace($"PresentationAttribute not found for {viewModelType.Name}. " +
                               $"Assuming DialogFragment presentation");
                return(new MvxDialogFragmentPresentationAttribute());
            }
            if (viewType.IsSubclassOf(typeof(Fragment)))
            {
                MvxTrace.Trace($"PresentationAttribute not found for {viewModelType.Name}. " +
                               $"Assuming Fragment presentation");
                return(new MvxFragmentPresentationAttribute(GetCurrentActivityViewModelType(), Android.Resource.Id.Content));
            }

            MvxTrace.Trace($"PresentationAttribute not found for {viewModelType.Name}. " +
                           $"Assuming Activity presentation");
            return(new MvxActivityPresentationAttribute()
            {
                ViewModelType = viewModelType
            });
        }
Ejemplo n.º 28
0
        public async override void ChangePresentation(MvxPresentationHint hint)
        {
            var navigation = GetPageOfType <NavigationPage>().Navigation;

            if (hint is MvxPopToRootPresentationHint popToRootHint)
            {
                // Make sure all modals are closed
                CloseAllModals(popToRootHint.Animated);

                // Double check we have a navigation page, otherwise
                // we can just return as we must be already at the root page
                if (navigation == null)
                {
                    return;
                }

                // Close all pages back to the root
                await navigation.PopToRootAsync(popToRootHint.Animated);

                return;
            }
            if (hint is MvxPopPresentationHint popHint)
            {
                var matched = await PopModalToViewModel(navigation, popHint);

                if (matched)
                {
                    return;
                }


                await PopToViewModel(navigation, popHint.ViewModelToPopTo, popHint.Animated);

                return;
            }
            if (hint is MvxRemovePresentationHint removeHint)
            {
                foreach (var modal in navigation.ModalStack)
                {
                    var removed = RemoveByViewModel(modal.Navigation, removeHint.ViewModelToRemove);
                    if (removed)
                    {
                        return;
                    }
                }

                RemoveByViewModel(navigation, removeHint.ViewModelToRemove);
                return;
            }
            if (hint is MvxPagePresentationHint pageHint)
            {
                var pageType = ViewsContainer.GetViewType(pageHint.ViewModel);
                if (GetPageOfTypeByType(pageType) is Page page)
                {
                    if (page.Parent is TabbedPage tabbedPage)
                    {
                        tabbedPage.CurrentPage = page;
                    }
                    else if (page.Parent is CarouselPage carouselPage && page is ContentPage contentPage)
                    {
                        carouselPage.CurrentPage = contentPage;
                    }
                }
                return;
            }

            base.ChangePresentation(hint);

#if DEBUG // Only showing this when debugging MVX
            MvxTrace.Trace(FormsApplication.Hierarchy());
#endif
        }