using System; using System.Text.Json.Serialization; using Xamarin.Forms; namespace Gallery.Util.Model { [JsonConverter(typeof(GalleryItemConverter))] public class GalleryItem : BindableObject { const double PREVIEW_WIDTH = 200.0; public static readonly BindableProperty TagDescriptionProperty = BindableProperty.Create(nameof(TagDescription), typeof(string), typeof(GalleryItem)); public static readonly BindableProperty PreviewImageProperty = BindableProperty.Create(nameof(PreviewImage), typeof(ImageSource), typeof(GalleryItem)); public static readonly BindableProperty UserNameProperty = BindableProperty.Create(nameof(UserName), typeof(string), typeof(GalleryItem)); public static readonly BindableProperty CreatedTimeProperty = BindableProperty.Create(nameof(CreatedTime), typeof(DateTime), typeof(GalleryItem)); public static readonly BindableProperty UpdatedTimeProperty = BindableProperty.Create(nameof(UpdatedTime), typeof(DateTime), typeof(GalleryItem)); public static readonly BindableProperty ImageHeightProperty = BindableProperty.Create(nameof(ImageHeight), typeof(GridLength), typeof(GalleryItem), GridLength.Auto); [JsonIgnore] public string TagDescription { get; set; } [JsonIgnore] public ImageSource PreviewImage { get; set; } [JsonIgnore] public GridLength ImageHeight { get; set; } public long Id { get; internal set; } private string[] tags; public string[] Tags { get => tags; set { tags = value; if (value != null) { TagDescription = string.Join(' ', tags); } else { TagDescription = null; } } } public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } public string UserId { get; set; } public string UserName { get; set; } public string Source { get; set; } public string PreviewUrl { get; set; } public string RawUrl { get; set; } private int width; private int height; public int Width { get => width; set { width = value; if (width > 0 && height > 0) { ImageHeight = new GridLength(PREVIEW_WIDTH * height / width); } } } public int Height { get => height; set { height = value; if (width > 0 && height > 0) { ImageHeight = new GridLength(PREVIEW_WIDTH * height / width); } } } } }