public YoutubeCollectionView(MediaState mediaState) :
            base(mediaState)
        {
            Filter = filterFunc;

            InfoIconsCache = InfoIconsCacheStatic;

            FilterModes = new System.Windows.Data.ListCollectionView(Enum.GetValues(typeof(FilterMode)));

            FilterModes.CurrentChanged += (s, e) =>
            {
                refresh();
            };

            SortItemCollection <SortItem, SortMode> sortItems = new SortItemCollection <SortItem, SortMode>();

            foreach (SortMode mode in Enum.GetValues(typeof(SortMode)))
            {
                sortItems.Add(new SortItem(mode));
            }

            sortItems.ItemSortDirectionChanged += sortItems_ItemSortDirectionChanged;

            SortModes = new System.Windows.Data.ListCollectionView(sortItems);

            SortModes.CurrentChanged += (s, e) =>
            {
                SortItem item = (SortItem)SortModes.CurrentItem;

                switch (item.SortMode)
                {
                case SortMode.Relevance:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        YoutubeItem itemA = (YoutubeItem)a.Item;
                        YoutubeItem itemB = (YoutubeItem)b.Item;

                        return(itemA.Relevance.CompareTo(itemB.Relevance));
                    });
                    break;

                case SortMode.Width:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(Nullable.Compare <int>(metaA.Width, metaB.Width));
                    });
                    break;

                case SortMode.Height:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(Nullable.Compare <int>(metaA.Height, metaB.Height));
                    });
                    break;

                case SortMode.Duration:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(Nullable.Compare <long>(metaA.DurationSeconds, metaB.DurationSeconds));
                    });
                    break;

                case SortMode.MimeType:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(String.Compare(metaA.MimeType, metaB.MimeType));
                    });
                    break;

                case SortMode.Author:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(String.Compare(metaA.Author, metaB.Author));
                    });
                    break;

                case SortMode.PublishedAt:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(Nullable.Compare <DateTime>(metaA.CreationDate, metaB.CreationDate));
                    });
                    break;

                case SortMode.ViewCount:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(Nullable.Compare <long>(metaA.ViewCount, metaB.ViewCount));
                    });
                    break;

                case SortMode.Rating:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(Nullable.Compare <double>(metaA.Rating, metaB.Rating));
                    });
                    break;

                case SortMode.FramesPerSecond:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        int result = hasMediaTest(a, b);
                        if (result != 0)
                        {
                            return(result);
                        }

                        YoutubeItemMetadata metaA = (YoutubeItemMetadata)a.Item.Metadata;
                        YoutubeItemMetadata metaB = (YoutubeItemMetadata)b.Item.Metadata;

                        return(Nullable.Compare <double>(metaA.Rating, metaB.Rating));
                    });
                    break;

                default:
                    break;
                }

                SortDirection = item.SortDirection;

                refresh();
            };
        }
Example #2
0
        public MediaFileStateCollectionView(MediaFileState mediaState = null) :
            base(mediaState)
        {
            Filter         = filterFunc;
            InfoIconsCache = InfoIconsCacheStatic;

            MediaFilter = MediaFilterMode.None;

            SortFunc = MediaFileSortFunctions.getSortFunction(MediaFileSortMode.Name);
            SortMode = MediaFileSortMode.Name;

            FilterModes = new ListCollectionView(Enum.GetValues(typeof(MediaFilterMode)));

            SortItemCollection <MediaFileSortItem, MediaFileSortMode> mediaFileSortItemCollection = new SortItemCollection <MediaFileSortItem, MediaFileSortMode>();

            mediaFileSortItemCollection.ItemSortDirectionChanged += mediaFileSortItemCollection_ItemSortDirectionChanged;

            foreach (MediaFileSortMode mode in Enum.GetValues(typeof(MediaFileSortMode)))
            {
                mediaFileSortItemCollection.Add(new MediaFileSortItem(mode));
            }

            SortModes = new ListCollectionView(mediaFileSortItemCollection);

            SortModes.CurrentChanged += (s, e) =>
            {
                MediaFileSortItem sortItem = (MediaFileSortItem)SortModes.CurrentItem;

                SortMode      = sortItem.SortMode;
                SortDirection = sortItem.SortDirection;

                SortFunc = MediaFileSortFunctions.getSortFunction(SortMode);

                refresh();
            };

            SortModes.Filter = mediaStateSortModeCollectionViewFilter;

            FilterModes.CurrentChanged += (s, e) =>
            {
                MediaFilter = (MediaFilterMode)FilterModes.CurrentItem;

                SortModes.Refresh();

                bool isRefreshed = false;

                switch (MediaFilter)
                {
                case MediaFilterMode.None:
                    if (!MediaFileSortFunctions.isAllSortMode(SortMode))
                    {
                        SortModes.MoveCurrentToFirst();
                        isRefreshed = true;
                    }
                    break;

                case MediaFilterMode.Video:
                    if (!MediaFileSortFunctions.isVideoSortMode(SortMode))
                    {
                        SortModes.MoveCurrentToFirst();
                        isRefreshed = true;
                    }
                    break;

                case MediaFilterMode.Images:
                    if (!MediaFileSortFunctions.isImageSortMode(SortMode))
                    {
                        SortModes.MoveCurrentToFirst();
                        isRefreshed = true;
                    }
                    break;

                case MediaFilterMode.Audio:
                    if (!MediaFileSortFunctions.isAudioSortMode(SortMode))
                    {
                        SortModes.MoveCurrentToFirst();
                        isRefreshed = true;
                    }
                    break;

                default:
                    break;
                }

                if (!isRefreshed)
                {
                    refresh();
                }
            };

            FilterModes.MoveCurrentTo(MediaFilterMode.None);
        }
        public ImageResultCollectionView(MediaState mediaState)
            : base(mediaState)
        {
            SortItemCollection <SortItem, SortMode> sortItems = new SortItemCollection <SortItem, SortMode>();

            foreach (SortMode mode in Enum.GetValues(typeof(SortMode)))
            {
                sortItems.Add(new SortItem(mode));
            }

            sortItems.ItemSortDirectionChanged += sortItems_ItemSortDirectionChanged;

            SortModes = new System.Windows.Data.ListCollectionView(sortItems);

            SortModes.CurrentChanged += (s, e) => {
                SortItem sortItem = (SortItem)SortModes.CurrentItem;

                switch (sortItem.SortMode)
                {
                case SortMode.Relevance:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        ImageResultItem itemA = (ImageResultItem)a.Item;
                        ImageResultItem itemB = (ImageResultItem)b.Item;

                        return(itemA.Relevance.CompareTo(itemB.Relevance));
                    });
                    break;

                case SortMode.Location:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        ImageResultItem itemA = (ImageResultItem)a.Item;
                        ImageResultItem itemB = (ImageResultItem)b.Item;

                        return(itemA.ImageInfo.SourceUrl.CompareTo(itemB.ImageInfo.SourceUrl));
                    });
                    break;

                case SortMode.Width:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        ImageResultItem itemA = (ImageResultItem)a.Item;
                        ImageResultItem itemB = (ImageResultItem)b.Item;

                        return(Nullable.Compare(itemA.ImageInfo.Width, itemB.ImageInfo.Width));
                    });
                    break;

                case SortMode.Height:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        ImageResultItem itemA = (ImageResultItem)a.Item;
                        ImageResultItem itemB = (ImageResultItem)b.Item;

                        return(Nullable.Compare(itemA.ImageInfo.Height, itemB.ImageInfo.Height));
                    });
                    break;

                case SortMode.Size:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        ImageResultItem itemA = (ImageResultItem)a.Item;
                        ImageResultItem itemB = (ImageResultItem)b.Item;

                        return(Nullable.Compare(itemA.ImageInfo.FileSize, itemB.ImageInfo.FileSize));
                    });
                    break;

                case SortMode.MimeType:
                    SortFunc = new Func <SelectableMediaItem, SelectableMediaItem, int>((a, b) =>
                    {
                        ImageResultItem itemA = (ImageResultItem)a.Item;
                        ImageResultItem itemB = (ImageResultItem)b.Item;

                        return(itemA.ImageInfo.ContentType.CompareTo(itemB.ImageInfo.ContentType));
                    });
                    break;

                default:
                    break;
                }

                SortDirection = sortItem.SortDirection;

                refresh();
            };
        }
        public MediaFileStateCollectionView(MediaFileState mediaState = null) :
            base(mediaState)
        {           
            Filter = filterFunc;
            InfoIconsCache = InfoIconsCacheStatic;

            MediaFilter = MediaFilterMode.None;           

            SortFunc = MediaFileSortFunctions.getSortFunction(MediaFileSortMode.Name);
            SortMode = MediaFileSortMode.Name;
            
            FilterModes = new ListCollectionView(Enum.GetValues(typeof(MediaFilterMode)));

            SortItemCollection<MediaFileSortItem, MediaFileSortMode> mediaFileSortItemCollection = new SortItemCollection<MediaFileSortItem,MediaFileSortMode>();
            mediaFileSortItemCollection.ItemSortDirectionChanged += mediaFileSortItemCollection_ItemSortDirectionChanged;

            foreach(MediaFileSortMode mode in Enum.GetValues(typeof(MediaFileSortMode))) {

                mediaFileSortItemCollection.Add(new MediaFileSortItem(mode));
            }

            SortModes = new ListCollectionView(mediaFileSortItemCollection);
         
            SortModes.CurrentChanged += (s, e) =>
            {
                MediaFileSortItem sortItem = (MediaFileSortItem)SortModes.CurrentItem;

                SortMode = sortItem.SortMode;
                SortDirection = sortItem.SortDirection;

                SortFunc = MediaFileSortFunctions.getSortFunction(SortMode);

                refresh();
            };

            SortModes.Filter = mediaStateSortModeCollectionViewFilter;

            FilterModes.CurrentChanged += (s, e) =>
            {
                MediaFilter = (MediaFilterMode)FilterModes.CurrentItem;
                              
                SortModes.Refresh();

                bool isRefreshed = false;

                switch (MediaFilter)
                {
                    case MediaFilterMode.None:
                        if (!MediaFileSortFunctions.isAllSortMode(SortMode))
                        {
                            SortModes.MoveCurrentToFirst();
                            isRefreshed = true;
                        }
                        break;
                    case MediaFilterMode.Video:
                        if (!MediaFileSortFunctions.isVideoSortMode(SortMode))
                        {
                            SortModes.MoveCurrentToFirst();
                            isRefreshed = true;
                        }
                        break;
                    case MediaFilterMode.Images:
                        if (!MediaFileSortFunctions.isImageSortMode(SortMode))
                        {
                            SortModes.MoveCurrentToFirst();
                            isRefreshed = true;
                        }
                        break;
                    case MediaFilterMode.Audio:
                        if (!MediaFileSortFunctions.isAudioSortMode(SortMode))
                        {
                            SortModes.MoveCurrentToFirst();
                            isRefreshed = true;
                        }
                        break;
                    default:
                        break;
                }

                if (!isRefreshed)
                {
                    refresh();
                }
       
            };
                                    
            FilterModes.MoveCurrentTo(MediaFilterMode.None);
            
        }