using System; using System.Collections.Generic; using Gallery.Resources.UI; using Gallery.Util.Model; using Xamarin.Essentials; namespace Gallery.Services { public class GalleryCollection : List, ICollectionChanged { private static GalleryCollection empty; public static GalleryCollection Empty { get { if (empty == null) { empty = new GalleryCollection(); } return empty; } } public event EventHandler CollectionChanged; public bool Running { get; set; } public GalleryCollection() : base() { Running = true; } public GalleryCollection(IEnumerable gallery) : base(gallery) { Running = true; } public void AddRange(List items) { var e = new CollectionChangedEventArgs { NewStartingIndex = Count, NewItems = items }; base.AddRange(items); if (MainThread.IsMainThread) { CollectionChanged?.Invoke(this, e); } else { MainThread.BeginInvokeOnMainThread(() => CollectionChanged?.Invoke(this, e)); } } } }