private async void Comics_ComicsChanged(ComicView sender, ComicsChangedEventArgs e) { switch (e.Type) { case ComicChangeType.ItemsChanged: if (this.Comics.Any() && this.Comics.First() != this.thumbnailComic) { this.thumbnailComic = this.Comics.First(); this.ThumbnailImageSource = new Uri(Thumbnail.ThumbnailPath(this.thumbnailComic)); this.OnPropertyChanged(nameof(this.ThumbnailImageSource)); } this.OnPropertyChanged(nameof(this.Subtitle)); // note: title cannot be changed. Changing title means removing this item and adding a new one. break; case ComicChangeType.ThumbnailChanged: if (this.thumbnailComic is not null && e.Modified.Contains(this.thumbnailComic)) { await this.RefreshImageSourceAsync(); } break; case ComicChangeType.Refresh: // the parent's job, not ours break; default: throw new ProgrammerError($"{nameof(this.Comics_ComicsChanged)}: unhandled switch case"); } }
public ComicNavigationItem(string name, ComicView comics) { this.Title = name; this.Comics = comics; if (comics.Any()) { var thumbnailComic = comics.First(); this.ThumbnailImageSource = new Uri(Thumbnail.ThumbnailPath(thumbnailComic)); } comics.ComicsChanged += this.Comics_ComicsChanged; }
private async void View_ComicsChanged(ComicView sender, ComicsChangedEventArgs e) { switch (e.Type) // switch ChangeType { case ComicChangeType.ItemsChanged: // Added: handled by ComicItemGrid if (e.Modified.Any()) { var match = e.Modified.Where(comic => comic.IsSame(this.Comic)).FirstOrNull(); if (match is { } comic) { this.Comic = comic; this.OnPropertyChanged(""); // an item can't be modified and removed at the same time return; } } if (!e.Removed.Contains(this.Comic)) { return; } this.owner.ComicsChanged -= this.View_ComicsChanged; this.RequestingRefresh(this, RequestingRefreshType.Remove); return; case ComicChangeType.Refresh: // the parent will have called refresh, so we don't need to do anything. return; case ComicChangeType.ThumbnailChanged: if (!e.Modified.Contains(this.Comic)) { return; } await this.RefreshImageSourceAsync(); return; default: throw new ProgrammerError($"{nameof(this.View_ComicsChanged)}: unhandled switch case"); } }
public ComicWorkItemGridViewModel( IMainPageContent parent, MainViewModel mainViewModel, ComicView comics, ComicItemGridViewModelProperties?properties = null, ComicItemGridState?savedState = null ) : base(parent, mainViewModel) { this.Properties = properties ?? new ComicItemGridViewModelProperties(); this.comics = comics.Sorted(this.SelectedSortSelector); this.comics.ComicsChanged += this.Comics_ComicsChanged; if (savedState?.LastModified is { } lastModified&& lastModified == mainViewModel.LastModified) { this.SetComicItems(savedState.Items); }