示例#1
0
        public override void WireMessages()
        {
            Messenger.Default.Register <NotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.ClearEpisodesMsg))
                {
                    Episodes.Clear();
                }

                if (m.Notification.Equals(Constants.Messages.RefreshResumeMsg))
                {
                    var id    = (string)m.Sender;
                    var ticks = (long)m.Target;
                    if (id == SelectedEpisode.Id)
                    {
                        if (SelectedEpisode.UserData == null)
                        {
                            SelectedEpisode.UserData = new UserItemDataDto();
                        }

                        SelectedEpisode.UserData.PlaybackPositionTicks = ticks;

                        SelectedEpisode.HasPlayed();

                        CanResume = SelectedEpisode.CanResume;
                    }
                }
            });

            Messenger.Default.Register <SyncNotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.SyncJobFinishedMsg))
                {
                    switch (m.ItemType.ToLower())
                    {
                    case "episode":
                        if (SelectedEpisode != null && SelectedEpisode.Id == m.ItemId)
                        {
                            SelectedEpisode.IsSynced = true;
                        }

                        if (!Episodes.IsNullOrEmpty())
                        {
                            var episode = Episodes.FirstOrDefault(x => x.Id == m.ItemId);
                            if (episode != null)
                            {
                                episode.IsSynced = true;
                            }
                        }
                        break;

                    case "season":
                        if (SelectedSeason != null)
                        {
                            SelectedSeason.IsSynced = true;
                        }

                        if (!Seasons.IsNullOrEmpty())
                        {
                            var season = Seasons.FirstOrDefault(x => x.Id == m.ItemId);
                            if (season != null)
                            {
                                season.IsSynced = true;
                            }
                        }
                        break;

                    case "series":
                        if (SelectedTvSeries != null)
                        {
                            SelectedTvSeries.IsSynced = true;
                        }
                        break;
                    }
                }
            });
        }