private async void UpdateGroup() { // only tracking need build group info. if (!this.Source.IsTracking) { return; } if (!this.Source.StartDate.HasValue) { this.SetCompareMode(ViewModelCompareMode.Unknown, $"{Resources.DayOfWeek_Unknown} (unknown start)"); return; } this.todayPlaying = null; var today = DateTime.Now.Date; var sunday = today.AddDays(-(int)today.DayOfWeek); // sunday var startDate = this.Source.StartDate.Value.ToLocalTime(); if (startDate < today) { if (this.Source.DayOfWeek == today.DayOfWeek) { this.compareMode = ViewModelCompareMode.Today; this.GroupTitle = $"{this.Source.DayOfWeek.GetLocalizeString()} ({Resources.DayOfWeek_Today})"; var episode = this.Source.GetTodayEpisode(today) + (this.Source.EpisodeOffset ?? 0); this.isDone = episode > this.Source.EpisodesCount; var playing = this.todayPlaying = new Playing(this.isDone ? (int?)null : episode); if (playing.Episode.HasValue) { var isWatched = await Task.Run(async() => { var manager = JryVideoCore.Current.CurrentDataCenter.VideoManager; var video = await manager.FindAsync(this.Source.Id); return(video?.Watcheds?.Contains(playing.Episode.Value)); }); if (isWatched != null && playing.IsWatched != isWatched.Value) { playing.IsWatched = !playing.IsWatched; //this.NotifyPropertyChanged(nameof(this.TodayPlaying)); this.NotifyPropertyChanged(nameof(this.IsTodayPlayAndNotEnd)); } } } else { this.SetCompareMode(ViewModelCompareMode.DayOfWeek, this.Source.DayOfWeek.GetLocalizeString()); } } else { if ((startDate - sunday).Days < 7) // this week { this.SetCompareMode(ViewModelCompareMode.DayOfWeek, this.Source.DayOfWeek.GetLocalizeString()); } else { var compared = startDate.DayOfYear - today.DayOfYear; if (compared <= 7) // next week { this.SetCompareMode(ViewModelCompareMode.NextWeek, string.Format(Resources.DateTime_Next, startDate.DayOfWeek.GetLocalizeString())); } else if (startDate.Month == today.Month) // in one month { var week = (compared / 7) + (compared % 7 == 0 ? 0 : 1); this.SetCompareMode(ViewModelCompareMode.FewWeek, string.Format(Resources.DateTime_AfterWeek, week)); } else { if (startDate.Year == today.Year) { this.SetCompareMode(ViewModelCompareMode.FewMonth, string.Format(Resources.DateTime_AfterMonth, startDate.Month - today.Month)); } else { this.SetCompareMode(ViewModelCompareMode.Future, Resources.DateTime_Future); } } } } }
private void SetCompareMode(ViewModelCompareMode mode, string groupTitle) { this.compareMode = mode; this.GroupTitle = groupTitle; }