Example #1
0
        private void UpdateSeasons(object sender, NotifyCollectionChangedEventArgs e)
        {
            _dispatcher.Invoke(delegate
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    foreach (var newItem in e.NewItems)
                    {
                        var favSeasonData = newItem as FavSeasonData;
                        _lisSeasons.Add(new SeasonViewModel(favSeasonData));
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (var oldItem in e.OldItems)
                    {
                        var o = oldItem as FavShowData;
                        for (int i = _lisSeasons.Count - 1; i >= 0; i--)
                        {
                            if (_lisSeasons[i].Season == oldItem)
                            {
                                _lisSeasons.RemoveAt(i);
                                break;
                            }
                        }
                    }
                    break;

                case NotifyCollectionChangedAction.Reset:
                    _lisSeasons.Clear();
                    foreach (FavSeasonData favSeasonData in _show.Seasons)
                    {
                        var x = new SeasonViewModel(favSeasonData);
                        _lisSeasons.Add(x);
                    }
                    break;

                default:
                    throw new InvalidOperationException(e.Action.ToString());
                }
                _lisSeasons.Sort(SeasonComparer);
            });
        }
Example #2
0
        public ShowViewModel(FavShowData show)
        {
            _show       = show;
            _dispatcher = Dispatcher.CurrentDispatcher;
            show.Seasons.CollectionChanged    += UpdateSeasons;
            show.NonSeasons.CollectionChanged += UpdateNonSeasons;

            _lisSeasons    = new ObservableCollection <SeasonViewModel>();
            _lisNonSeasons = new ObservableCollection <DownloadData>();

            Cover       = !string.IsNullOrWhiteSpace(_show.Cover) ? new CachedImage(_show.Cover) : null;
            Description = (_show.Seasons.Any(s => s.Episodes.Any(e => e.Downloads.Any()))) ?
                          _show.Seasons.First(s => s.Episodes.Any(e => e.Downloads.Any())).Episodes.First(e => e.Downloads.Any()).Downloads.First().Upload.Season.Description : "";

            foreach (FavSeasonData favSeasonData in show.Seasons)
            {
                var x = new SeasonViewModel(favSeasonData);
                _lisSeasons.Add(x);
            }
            _lisSeasons.Sort(SeasonComparer);
            var first = _lisSeasons.FirstOrDefault();

            if (first != null)
            {
                first.IsExpanded = true;
            }

            foreach (DownloadData nonSeason in show.NonSeasons)
            {
                _lisNonSeasons.Add(nonSeason);
            }


            UnmarkAllCommand = new SimpleCommand <object, object>(o =>
            {
                foreach (var season in Show.Seasons)
                {
                    foreach (var episode in season.Episodes)
                    {
                        episode.Downloaded = false;
                        episode.Watched    = false;
                    }
                }
            });
            MarkAllDownloadedCommand = new SimpleCommand <object, object>(o =>
            {
                foreach (var season in Show.Seasons)
                {
                    foreach (var episode in season.Episodes)
                    {
                        episode.Downloaded = true;
                        //episode.Watched = false; //not sure here
                    }
                }
            });
            MarkAllWatchedCommand = new SimpleCommand <object, object>(o =>
            {
                foreach (var season in Show.Seasons)
                {
                    foreach (var episode in season.Episodes)
                    {
                        episode.Downloaded = true;
                        episode.Watched    = true;
                    }
                }
            });

            DownloadCommand = new SimpleCommand <object, String>(s =>
            {
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        Clipboard.SetText(s);
                        Clipboard.Flush();
                        return;
                    }
                    catch
                    {
                        //nah
                    }
                    Thread.Sleep(10);
                }
                MessageBox.Show("Couldn't Copy link to clipboard.\n" + s);
            });
        }