Esempio n. 1
0
        void RefreshItems()
        {
            if (Playlist != null)
            {
                WeakReferenceMessenger.Default.Register <PlaylistItemRemovedMessage, PlaylistId>(this, Playlist.PlaylistId, (r, m) =>
                {
                    var args = m.Value;
                    foreach (var video in args.RemovedItems)
                    {
                        var removedItem = ItemsView.Cast <VideoListItemControlViewModel>().FirstOrDefault(x => x.VideoId == video.VideoId);
                        if (removedItem != null)
                        {
                            ItemsView.Remove(removedItem);
                        }
                    }

                    PlaylistPlayAllCommand.NotifyCanExecuteChanged();
                });

                WeakReferenceMessenger.Default.Register <PlaylistItemAddedMessage, PlaylistId>(this, Playlist.PlaylistId, (r, m) =>
                {
                    var args  = m.Value;
                    int index = ItemsView.Count;
                    foreach (var video in args.AddedItems)
                    {
                        var nicoVideo = _nicoVideoProvider.GetCachedVideoInfo(video.VideoId);
                        ItemsView.Add(new VideoListItemControlViewModel(nicoVideo)
                        {
                            PlaylistItemToken = new PlaylistItemToken(Playlist, SelectedSortOptionItem, video)
                        });
                    }

                    PlaylistPlayAllCommand.NotifyCanExecuteChanged();
                });

                _localMylistManager.LocalPlaylists.ObserveRemoveChanged()
                .Subscribe(removed =>
                {
                    if (Playlist.PlaylistId == removed.PlaylistId)
                    {
                        _pageManager.ForgetLastPage();
                        _pageManager.OpenPage(HohoemaPageType.UserMylist);
                    }
                })
                .AddTo(_navigationDisposables);
            }
        }