Esempio n. 1
0
        /// <summary>
        /// Enters a new media navigation context by modifying the list of available screens. This is used for
        /// presenting the result of a filter, where the menu must be changed.
        /// </summary>
        /// <param name="subViewSpecification">Specification for the sub view to be shown in the new navigation context.</param>
        /// <param name="currentMenuItemLabel">Current menu item label needed for distinction of available screens.</param>
        /// <param name="navbarDisplayLabel">Display label to be shown in the navigation bar for the new navigation context.</param>
        /// <returns>Newly created navigation data.</returns>
        public NavigationData StackAutonomousNavigationContext(ViewSpecification subViewSpecification, string currentMenuItemLabel, string navbarDisplayLabel)
        {
            AbstractScreenData currentScreen = AvailableScreens.FirstOrDefault(screen => screen.MenuItemLabel == currentMenuItemLabel);
            ICollection <AbstractScreenData> remainingScreens = new List <AbstractScreenData>(AvailableScreens.Where(screen => screen != currentScreen));

            WorkflowState newState = WorkflowState.CreateTransientState(
                "View: " + subViewSpecification.ViewDisplayName, subViewSpecification.ViewDisplayName,
                false, null, false, WorkflowType.Workflow, null);

            string             nextScreenName;
            AbstractScreenData nextScreen = null;

            // Try to load the prefered next screen from settings.
            if (LoadScreenHierarchy(CurrentScreenData.GetType().ToString(), out nextScreenName))
            {
                nextScreen = remainingScreens.FirstOrDefault(s => s.GetType().ToString() == nextScreenName);
            }

            // Default way: always take the first of the available screens.
            if (nextScreen == null)
            {
                nextScreen = remainingScreens.First(s => s != currentScreen);
            }

            ScreenConfig nextScreenConfig;

            LoadLayoutSettings(nextScreen.GetType().ToString(), out nextScreenConfig);

            Sorting.Sorting nextSortingMode = AvailableSortings.FirstOrDefault(
                sorting => sorting.GetType().ToString() == nextScreenConfig.Sorting && sorting.IsAvailable(nextScreen)) ?? _currentSorting;
            Sorting.Sorting nextGroupingMode = String.IsNullOrEmpty(nextScreenConfig.Grouping) ? null : AvailableGroupings.FirstOrDefault(
                grouping => grouping.GetType().ToString() == nextScreenConfig.Grouping && grouping.IsAvailable(nextScreen)) ?? _currentGrouping;

            NavigationData newNavigationData = new NavigationData(this, subViewSpecification.ViewDisplayName,
                                                                  newState.StateId, newState.StateId, subViewSpecification, nextScreen, remainingScreens,
                                                                  nextSortingMode, nextGroupingMode)
            {
                LayoutType = nextScreenConfig.LayoutType, LayoutSize = nextScreenConfig.LayoutSize
            };

            PushNewNavigationWorkflowState(newState, navbarDisplayLabel, newNavigationData);
            return(newNavigationData);
        }
        public virtual void InitMediaNavigation(MediaNavigationConfig config, out string mediaNavigationMode, out NavigationData navigationData)
        {
            PrepareAsync().Wait();

            IFilterTree filterTree = _customFilterTree ?? (_rootRole.HasValue ? new RelationshipFilterTree(_rootRole.Value) : (IFilterTree) new SimpleFilterTree());

            if (_filter != null)
            {
                filterTree.AddFilter(_filter);
            }

            //Default configuration
            string viewName = _viewName;

            AbstractScreenData nextScreen = null;

            //Apply any custom configuration
            if (config != null)
            {
                if (_availableScreens != null)
                {
                    //Use the configured root screen to load the next screen from the hierarchy
                    //and remove it from the list of available screens
                    AbstractScreenData configRoot = config.RootScreenType != null?_availableScreens.FirstOrDefault(s => s.GetType() == config.RootScreenType) : null;

                    if (configRoot != null)
                    {
                        viewName = configRoot.GetType().ToString();
                        _availableScreens.Remove(configRoot);
                    }

                    //Use the configured default screen if there is no saved screen hierarchy
                    AbstractScreenData configDefault = config.DefaultScreenType != null?_availableScreens.FirstOrDefault(s => s.GetType() == config.DefaultScreenType) : null;

                    if (configDefault != null)
                    {
                        _defaultScreen = configDefault;
                        // If we want to force the default screen to be shown, set the next screen
                        // here to avoid loading it from the screen hierarchy below.
                        if (config.AlwaysUseDefaultScreen)
                        {
                            nextScreen = configDefault;
                        }
                    }
                }

                //Apply any additional filters
                if (config.LinkedId.HasValue)
                {
                    filterTree.AddLinkedId(config.LinkedId.Value, config.FilterPath);
                }
                if (config.Filter != null)
                {
                    filterTree.AddFilter(config.Filter, config.FilterPath);
                }
            }

            IEnumerable <Guid> optionalMIATypeIDs = MediaNavigationModel.GetMediaSkinOptionalMIATypes(MediaNavigationMode);

            if (_optionalMias != null)
            {
                optionalMIATypeIDs = optionalMIATypeIDs.Union(_optionalMias).Except(_necessaryMias);
            }

            // Try to load the prefered next screen from settings if not already set.
            if (nextScreen == null && NavigationData.LoadScreenHierarchy(viewName, out string nextScreenName))
            {
                // Support for browsing mode.
                if (nextScreenName == Consts.USE_BROWSE_MODE)
                {
                    SetBrowseMode(optionalMIATypeIDs);
                }

                if (_availableScreens != null)
                {
                    nextScreen = _availableScreens.FirstOrDefault(s => s.GetType().ToString() == nextScreenName);
                }
            }

            if (_applyUserFilter)
            {
                var userFilter = UserHelper.GetUserRestrictionFilter(_necessaryMias.ToList());
                if (userFilter != null)
                {
                    filterTree.AddFilter(userFilter);
                }
            }

            // Prefer custom view specification.
            ViewSpecification rootViewSpecification = _customRootViewSpecification ??
                                                      // Always use the default view name for the root view specification, not any custom name that may
                                                      // have been specified in a navigation config, otherwise toggling browse mode won't work correctly.
                                                      // To switch to browse mode we update the root screen hierarchy to point to the browse screen and
                                                      // then navigate to the root wf state. The name of the root screen hierarchy is determined by the
                                                      // name specified here so it should always point to the actual root view name.
                                                      new MediaLibraryQueryViewSpecification(_viewName, filterTree, _necessaryMias, optionalMIATypeIDs, true)
            {
                MaxNumItems = Consts.MAX_NUM_ITEMS_VISIBLE,
            };

            if (nextScreen == null)
            {
                nextScreen = _defaultScreen;
            }

            ScreenConfig nextScreenConfig;

            NavigationData.LoadLayoutSettings(nextScreen.GetType().ToString(), out nextScreenConfig);

            Sorting.Sorting nextSortingMode  = _availableSortings.FirstOrDefault(sorting => sorting.GetType().ToString() == nextScreenConfig.Sorting) ?? _defaultSorting;
            Sorting.Sorting nextGroupingMode = _availableGroupings == null || String.IsNullOrEmpty(nextScreenConfig.Grouping) ? null : _availableGroupings.FirstOrDefault(grouping => grouping.GetType().ToString() == nextScreenConfig.Grouping) ?? _defaultGrouping;

            navigationData = new NavigationData(null, viewName, MediaNavigationRootState,
                                                MediaNavigationRootState, rootViewSpecification, nextScreen, _availableScreens, nextSortingMode, nextGroupingMode)
            {
                AvailableSortings  = _availableSortings,
                AvailableGroupings = _availableGroupings,
                LayoutType         = nextScreenConfig.LayoutType,
                LayoutSize         = nextScreenConfig.LayoutSize
            };
            mediaNavigationMode = MediaNavigationMode;
        }
Esempio n. 3
0
        public virtual void InitMediaNavigation(out string mediaNavigationMode, out NavigationData navigationData)
        {
            Prepare();

            string             nextScreenName;
            AbstractScreenData nextScreen = null;

            // Try to load the prefered next screen from settings.
            if (NavigationData.LoadScreenHierarchy(_viewName, out nextScreenName))
            {
                // Support for browsing mode.
                if (nextScreenName == Consts.USE_BROWSE_MODE)
                {
                    SetBrowseMode();
                }

                if (_availableScreens != null)
                {
                    nextScreen = _availableScreens.FirstOrDefault(s => s.GetType().ToString() == nextScreenName);
                }
            }

            IEnumerable <Guid> optionalMIATypeIDs = MediaNavigationModel.GetMediaSkinOptionalMIATypes(MediaNavigationMode);

            if (_optionalMias != null)
            {
                optionalMIATypeIDs = optionalMIATypeIDs.Union(_optionalMias);
                optionalMIATypeIDs = optionalMIATypeIDs.Except(_necessaryMias);
            }

            IFilterTree filterTree = _rootRole.HasValue ? new RelationshipFilterTree(_rootRole.Value) : (IFilterTree) new SimpleFilterTree();

            filterTree.AddFilter(_filter);

            // Prefer custom view specification.
            ViewSpecification rootViewSpecification = _customRootViewSpecification ??
                                                      new MediaLibraryQueryViewSpecification(_viewName, filterTree, _necessaryMias, optionalMIATypeIDs, true)
            {
                MaxNumItems = Consts.MAX_NUM_ITEMS_VISIBLE
            };

            if (nextScreen == null)
            {
                nextScreen = _defaultScreen;
            }

            ScreenConfig nextScreenConfig;

            NavigationData.LoadLayoutSettings(nextScreen.GetType().ToString(), out nextScreenConfig);

            Sorting.Sorting nextSortingMode  = _availableSortings.FirstOrDefault(sorting => sorting.GetType().ToString() == nextScreenConfig.Sorting) ?? _defaultSorting;
            Sorting.Sorting nextGroupingMode = _availableGroupings == null || String.IsNullOrEmpty(nextScreenConfig.Grouping) ? null : _availableGroupings.FirstOrDefault(grouping => grouping.GetType().ToString() == nextScreenConfig.Grouping) ?? _defaultGrouping;

            navigationData = new NavigationData(null, _viewName, MediaNavigationRootState,
                                                MediaNavigationRootState, rootViewSpecification, nextScreen, _availableScreens, nextSortingMode, nextGroupingMode)
            {
                AvailableSortings  = _availableSortings,
                AvailableGroupings = _availableGroupings,
                LayoutType         = nextScreenConfig.LayoutType,
                LayoutSize         = nextScreenConfig.LayoutSize
            };
            mediaNavigationMode = MediaNavigationMode;
        }