示例#1
0
 public FilterValue(string title, FilterTreePath relativeFilterPath, IFilter selectAttributeFilter, int numItems, MLFilterCriterion criterion)
 {
     _title = title;
     _relativeFilterPath    = relativeFilterPath;
     _selectAttributeFilter = selectAttributeFilter;
     _numItems  = numItems;
     _criterion = criterion;
 }
 public FilterValue(string title, FilterTreePath relativeFilterPath, IFilter selectAttributeFilter, MediaItem item, MLFilterCriterion criterion)
 {
     _title = title;
     _relativeFilterPath    = relativeFilterPath;
     _selectAttributeFilter = selectAttributeFilter;
     _item      = item;
     _criterion = criterion;
     if (item != null)
     {
         _linkedId = item.MediaItemId;
     }
 }
示例#3
0
 protected AbstractSeriesFilterScreenData(string screen, string menuItemLabel, string navbarSubViewNavigationDisplayLabel,
                                          MLFilterCriterion filterCriterion) : base(screen, menuItemLabel, navbarSubViewNavigationDisplayLabel, filterCriterion)
 {
     _filterPath = new FilterTreePath(SeriesAspect.ROLE_SERIES);
     _necessaryFilteredMIATypeIds = Consts.NECESSARY_SERIES_MIAS;
 }
        /// <summary>
        /// Updates the GUI data for a filter values selection screen which reflects the available filter values for
        /// the current base view specification of our <see cref="AbstractScreenData._navigationData"/>.
        /// </summary>
        protected async Task ReloadFilterValuesList(bool createNewList)
        {
            MediaLibraryQueryViewSpecification currentVS = _navigationData.BaseViewSpecification as MediaLibraryQueryViewSpecification;

            if (currentVS == null)
            { // Should never happen
                ServiceRegistration.Get <ILogger>().Error("FilterScreenData: Wrong type of media library view '{0}'", _navigationData.BaseViewSpecification);
                return;
            }
            // Control other threads reentering this method
            lock (_syncObj)
            {
                if (_buildingList)
                { // Another thread is already building the items list - mark it as dirty and let the other thread
                  // rebuild it.
                    _listDirty = true;
                    return;
                }
                // Mark the list as being built
                _buildingList = true;
                _listDirty    = false;
            }
            try
            {
                ItemsList items;
                if (createNewList)
                {
                    items = new ItemsList();
                }
                else
                {
                    items = _items;
                    items.Clear();
                }

                try
                {
                    Display_ListBeingBuilt();
                    IFilter            filter        = currentVS.FilterTree.BuildFilter(_filterPath);
                    ICollection <Guid> necessaryMIAs = _necessaryFilteredMIATypeIds ?? currentVS.NecessaryMIATypeIds;

                    // If the number of values to create exceeds MAX_NUM_ITEMS_VISIBLE we need to try and group the items.
                    // We request all values first, rather than groups, on the assumption that most of the time the limit
                    // shouldn't be reached given that we are filtering the values.
                    bool grouping = false;
                    ICollection <FilterValue> fv = await _filterCriterion.GetAvailableValuesAsync(necessaryMIAs, _clusterFilter, filter).ConfigureAwait(false);

                    if (fv.Count > Consts.MAX_NUM_ITEMS_VISIBLE && _clusterFilter == null)
                    {
                        ICollection <FilterValue> groupValues = await _filterCriterion.GroupValuesAsync(necessaryMIAs, _clusterFilter, filter).ConfigureAwait(false);

                        if (groupValues != null && groupValues.Count > 0)
                        {
                            fv       = groupValues;
                            grouping = true;
                        }
                    }
                    if (fv.Count > Consts.MAX_NUM_ITEMS_VISIBLE)
                    {
                        Display_TooManyItems(fv.Count);
                    }
                    else
                    {
                        bool dirty;
                        lock (_syncObj)
                            dirty = _listDirty;
                        if (dirty)
                        {
                            UpdateOrRebuildView(items, createNewList);
                            return;
                        }

                        _sortable = true;
                        int totalNumItems           = 0;
                        List <FilterItem> itemsList = new List <FilterItem>();
                        // Build collection of available (filter/display) screens which will remain in the next view - that is all currently
                        // available screens without the screen which equals this current screen. But we cannot simply remove "this"
                        // from the collection, because "this" could be a derived screen (in case our base screen showed groups).
                        // So we need an equality criterion when the screen to be removed is equal to this screen in terms of its
                        // filter criterion. But with the given data, we actually cannot derive that equality.
                        // So we simply use the MenuItemLabel, which should be the same in this and the base screen of the same filter.
                        foreach (FilterValue f in fv)
                        {
                            //Used for enclosure
                            FilterValue filterValue = f;
                            _sortable &= filterValue.Item != null;
                            string  filterTitle                      = filterValue.Title;
                            IFilter selectAttributeFilter            = filterValue.SelectAttributeFilter;
                            MediaLibraryQueryViewSpecification subVS = currentVS.CreateSubViewSpecification(filterTitle,
                                                                                                            FilterTreePath.Combine(_filterPath, filterValue.RelativeFilterPath), filterValue.Filter, filterValue.LinkedId);
                            T filterValueItem = new T
                            {
                                // Support non-playable MediaItems (i.e. Series, Seasons)
                                MediaItem   = filterValue.Item,
                                SimpleTitle = filterTitle,
                                NumItems    = filterValue.NumItems,
                                Id          = filterValue.Id,
                                Command     = new MethodDelegateCommand(() =>
                                {
                                    if (grouping)
                                    {
                                        NavigateToGroup(subVS, selectAttributeFilter);
                                    }
                                    else
                                    {
                                        NavigateToSubView(subVS);
                                    }
                                }),
                                View = subVS.BuildView()
                            };
                            itemsList.Add(filterValueItem);
                            if (filterValue.NumItems.HasValue)
                            {
                                totalNumItems += filterValue.NumItems.Value;
                            }
                        }
                        if (_sortable)
                        {
                            Sorting.Sorting sorting = CurrentSorting;
                            if (sorting != null)
                            {
                                itemsList.Sort((i1, i2) => sorting.Compare(i1.MediaItem, i2.MediaItem));
                            }
                        }
                        // Derived classes can implement special initial selection handling here,
                        // e.g. the first unwatched episode could be selected from a list of episodes
                        SetSelectedItem(itemsList);
                        CollectionUtils.AddAll(items, itemsList);
                        Display_Normal(items.Count, totalNumItems == 0 ? new int?() : totalNumItems);
                    }
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("AbstractFiltersScreenData: Error creating filter values list", e);
                    Display_ItemsInvalid();
                }
                UpdateOrRebuildView(items, createNewList);
            }
            finally
            {
                lock (_syncObj)
                    _buildingList = false;
            }
        }
示例#5
0
        public MediaLibraryQueryViewSpecification CreateSubViewSpecification(string viewDisplayName, FilterTreePath filterPath, IFilter filter, Guid?linkedId)
        {
            IFilterTree newFilterTree = _filterTree.DeepCopy();

            if (linkedId.HasValue)
            {
                newFilterTree.AddLinkedId(linkedId.Value, filterPath);
            }
            else if (filter != null)
            {
                newFilterTree.AddFilter(filter, filterPath);
            }

            return(new MediaLibraryQueryViewSpecification(viewDisplayName, newFilterTree, _necessaryMIATypeIds, _optionalMIATypeIds, _onlyOnline)
            {
                MaxNumItems = _maxNumItems,
                FilterPath = filterPath
            });
        }