using System; using System.Collections.Generic; using System.Linq; using Unity.UIWidgets.foundation; using Unity.UIWidgets.widgets; namespace UIWidgetsGallery.gallery { public class GalleryDemoCategory { public GalleryDemoCategory( string name, IconData icon) { this.name = name; this.icon = icon; } public readonly string name; public readonly IconData icon; public bool Equals(GalleryDemoCategory other) { if (ReferenceEquals(this, other)) { return true; } if (ReferenceEquals(other, null)) { return false; } return this.icon.Equals(other.icon) && this.name == other.name; } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return true; } if (ReferenceEquals(obj, null)) { return false; } if (obj.GetType() != GetType()) { return false; } return Equals((GalleryDemoCategory)obj); } public static bool operator==(GalleryDemoCategory left, GalleryDemoCategory right) { return Equals(left, right); } public static bool operator !=(GalleryDemoCategory left, GalleryDemoCategory right) { return !Equals(left, right); } public override int GetHashCode() { unchecked { return ((icon?.GetHashCode() ?? 0) * 397) ^ (name?.GetHashCode() ?? 0); } } public override string ToString() { return $"{GetType()}{name}"; } public static readonly GalleryDemoCategory _kDemos = new GalleryDemoCategory( name: "Studies", icon: GalleryIcons.animation ); public static readonly GalleryDemoCategory _kStyle = new GalleryDemoCategory( name: "Style", icon: GalleryIcons.custom_typography ); public static readonly GalleryDemoCategory _kMaterialComponents = new GalleryDemoCategory( name: "Material", icon: GalleryIcons.category_mdc ); public static readonly GalleryDemoCategory _kCupertinoComponents = new GalleryDemoCategory( name: "Cupertino", icon: GalleryIcons.phone_iphone ); public static readonly GalleryDemoCategory _kMedia = new GalleryDemoCategory( name: "Media", icon: GalleryIcons.drive_video ); } class GalleryDemo { public GalleryDemo( string title = null, IconData icon = null, string subtitle = null, GalleryDemoCategory category = null, string routeName = null, string documentationUrl = null, WidgetBuilder buildRoute = null ) { D.assert(title != null); D.assert(category != null); D.assert(routeName != null); D.assert(buildRoute != null); this.title = title; this.icon = icon; this.subtitle = subtitle; this.category = category; this.routeName = routeName; this.documentationUrl = documentationUrl; this.buildRoute = buildRoute; } public readonly string title; public readonly IconData icon; public readonly string subtitle; public readonly GalleryDemoCategory category; public readonly string routeName; public readonly WidgetBuilder buildRoute; public readonly string documentationUrl; public override string ToString() { return $"{GetType()}({title} {routeName})"; } public static List _buildGalleryDemos() { List galleryDemos = new List { }; return galleryDemos; } public static readonly List kAllGalleryDemos = _buildGalleryDemos(); public static readonly List kAllGalleryDemoCategories = kAllGalleryDemos.Select((GalleryDemo demo) => demo.category).ToList(); static Dictionary> _generateCategoryToDemos() { Dictionary> result = new Dictionary>(); foreach (var category in kAllGalleryDemoCategories) { result.Add(category, kAllGalleryDemos.Where((GalleryDemo demo) => { return demo.category == category; }).ToList()); } return result; } public static readonly Dictionary> kGalleryCategoryToDemos = _generateCategoryToDemos(); static Dictionary _generateDemoDocumentationUrls() { Dictionary result = new Dictionary(); foreach (var demo in kAllGalleryDemos) { if (demo.documentationUrl != null) { result.Add(demo.routeName, demo.documentationUrl); } } return result; } public static readonly Dictionary kDemoDocumentationUrl = _generateDemoDocumentationUrls(); } }