Example #1
0
        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");
            }
        }
Example #2
0
        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");
            }
        }
Example #3
0
        private void ParentComicView_ComicsChanged(ComicView sender, ComicsChangedEventArgs __)
        {
            if (this.lastChange is not {
            } e)
            {
                return;
            }

            switch (e.Type)
            {
            case ComicChangeType.ItemsChanged:
                // here we get a list of added/removed/modified comics, and we need to create a list of
                // added/removed/modified properties.

                // note: we can do some proper deduction in terms of which properties are added/removed/modified,
                // but we're keeping it simple for now: basically, modified = removed + added
                var tryAddProperties    = e.Add.SelectMany(this.getProperties);
                var tryRemoveProperties = e.Remove.SelectMany(this.getProperties);

                var addedProperties   = new HashSet <string>();
                var removedProperties = new HashSet <string>();

                foreach (var property in tryRemoveProperties)
                {
                    if (this.Properties.Contains(property))
                    {
                        var propertyView = this.Properties.Remove(property);
                        _ = removedProperties.Add(property);

                        if (propertyView.Comics.Any())
                        {
                            this.Properties.Add(propertyView);
                            _ = addedProperties.Add(property);
                        }
                    }
                }

                foreach (var property in tryAddProperties)
                {
                    if (this.Properties.Contains(property))
                    {
                        _ = removedProperties.Add(property);
                    }
                    else
                    {
                        var view = this.parent.Filtered(comic => getProperties(comic).Contains(property));
                        this.Properties.Add(new ComicCollection(property, view));
                    }

                    _ = addedProperties.Add(property);
                }

                this.OnCollectionsChanged(new(CollectionsChangeType.ItemsChanged, addedProperties, removedProperties));

                break;

            case ComicChangeType.ThumbnailChanged:
                break;

            case ComicChangeType.Refresh:
                this.Properties.Clear();
                this.ReinitializeProperties();

                break;

            default:
                throw new ProgrammerError("unhandled switch case");
            }
        }