using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading.Tasks; using Gallery.Util; using Gallery.Util.Interface; using Gallery.Util.Model; using Xamarin.Forms; namespace Gallery.Sources.Facets { public class GallerySource : GallerySourceBase { public override string Name => "FACETS"; public override string Route => "facets"; public override string FlyoutIconKey => "Facets"; public override string HomePage => "http://www.facets.la"; public override async Task> GetRecentItemsAsync(int page) { var offset = (page - 1) * 63; var url = $"http://www.facets.la/offset/{offset}/"; var (result, error) = await NetHelper.RequestObject(url, @return: content => ResolveGalleryItems(content)); if (result == null || !string.IsNullOrEmpty(error)) { Log.Error("facets.content.load", $"failed to load content array, error: {error}"); return null; } return result; } private GalleryItem[] ResolveGalleryItems(string content) { var regex = new Regex( @"
]+?>([^<]+?)", RegexOptions.Multiline); var matches = regex.Matches(content); var items = new GalleryItem[matches.Count]; for (var i = 0; i < items.Length; i++) { var g = matches[i].Groups; items[i] = new GalleryItem(int.Parse(g[1].Value)) { Tags = new[] { g[6].Value }, //Width = int.Parse(g[4].Value), Source = Route, RawUrl = g[3].Value, PreviewUrl = g[3].Value }; } return items; } public override void InitDynamicResources(string family, ResourceDictionary light, ResourceDictionary dark) { var icon = new FontImageSource { FontFamily = family, Glyph = "\uf302", Size = 18.0 }; light.Add(FlyoutIconKey, icon); dark.Add(FlyoutIconKey, icon); } public override void SetCookie() { throw new NotImplementedException(); } } }