Пример #1
0
        private void CreateTexture(IImageAsset imageAsset)
        {
            var image   = new Veldrid.ImageSharp.ImageSharpTexture(imageAsset.OpenAsync().Result);
            var texture = image.CreateDeviceTexture(_veldrid.GraphicsDevice, _veldrid.ResourceFactory);

            _textures[imageAsset] = texture;
        }
Пример #2
0
        public async Task CommentOnAsset(IImageAsset asset, string comment)
        {
            try
            {
                var request = new HttpRequestMessage(HttpMethod.Post, $"3/comment")
                {
                    Headers = { Authorization = AuthenticationHeaderValue.Parse($"{IdentityProvider.GetAuthenticationHeader()}") },
                    Content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("image_id", asset.Id),
                        new KeyValuePair <string, string>("comment", comment),
                    })
                };

                var response = await Client.SendAsync(request);

                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    await IdentityProvider.ReAuthorize();
                }
                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw new Exception("Unable to comment this image");
            }
        }
Пример #3
0
 public IImageAsset Map(IImageAsset mesh)
 {
     if (_images.TryGetValue(mesh, out var result))
     {
         return(result);
     }
     return(null);
 }
Пример #4
0
 public Task <List <IAssetComment> > GetGalleryAssetComments(IImageAsset asset)
 => Execute <JObject, List <IAssetComment> >(HttpMethod.Get, "flickr.photos.comments.getList",
                                             new Dictionary <string, string> {
     { "photo_id", asset.Id }
 }, "comment", arg =>
 {
     var ret = arg.Data.Last.First.ToObject <List <FlickrComment> >();
     return(new List <IAssetComment>(ret));
 });
Пример #5
0
        private RelativeLayout GetImage(IImageAsset asset)
        {
            var image = new Image
            {
                Aspect          = Aspect.AspectFit,
                BackgroundColor = Color.Accent
            };

            var titleFrame = new StackLayout
            {
                Children =
                {
                    new Label
                    {
                        Text      = asset.Title,
                        TextColor = Color.White
                    }
                },
                Orientation     = StackOrientation.Horizontal,
                Margin          = new Thickness(0),
                Padding         = new Thickness(10),
                BackgroundColor = Color.Black.MultiplyAlpha(0.7),
                VerticalOptions = LayoutOptions.Start
            };

            var heigh = asset.Ratio > 0 ? Bounds.Width / asset.Ratio : Bounds.Width * asset.Ratio;
            var frame = new RelativeLayout
            {
                Margin            = new Thickness(0),
                BindingContext    = asset,
                HeightRequest     = heigh,
                WidthRequest      = Bounds.Width,
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Children          =
                {
                    { image,      () => new Rectangle(0, 0, Bounds.Width, asset.Ratio > 0 ? Bounds.Width / asset.Ratio : Bounds.Width * asset.Ratio) },
                    { titleFrame, () => new Rectangle(0, 0, image.Width,  image.Height / 0.33)                                                       }
                }
            };

            image.SizeChanged += (sender, args) =>
            {
                var newheigh = asset.Ratio > 0 ? Bounds.Width / asset.Ratio : Bounds.Width * asset.Ratio;
                frame.HeightRequest = newheigh;
                frame.WidthRequest  = Bounds.Width;
            };

            frame.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(async() => await Navigation.PushAsync(new ImageDetailView <TService>(((IImageAsset)frame.BindingContext).Id)))
            });
            return(frame);
        }
Пример #6
0
 public Task <string> FavoriteImage(IImageAsset asset)
 {
     if (asset.Favorite)
     {
         return(ExecuteNoReturn(HttpMethod.Get, "flickr.favorites.remove", new Dictionary <string, string> {
             { "photo_id", asset.Id }
         }, "comment",
                                arg => "unfavorited"));
     }
     return(ExecuteNoReturn(HttpMethod.Get, "flickr.favorites.add", new Dictionary <string, string> {
         { "photo_id", asset.Id }
     }, "comment",
                            arg => "favorited"));
 }
Пример #7
0
 public Task <string> FavoriteImage(IImageAsset asset)
 => Execute <ImgurApiResponse <string>, string>(HttpMethod.Post, $"3/image/{asset.Id}/favorite", arg => arg.Data);
Пример #8
0
 public Task <List <IAssetComment> > GetGalleryAssetComments(IImageAsset asset)
 =>
 Execute <ImgurApiResponse <List <ImgurComment> >, List <IAssetComment> >(HttpMethod.Get, $"3/gallery/image/{asset.Id}/comments",
                                                                          arg => new List <IAssetComment>(arg.Data));
Пример #9
0
 public Task CommentOnAsset(IImageAsset asset, string comment) => Execute <JObject, bool>(HttpMethod.Post, "flickr.photos.comments.addComment",
                                                                                          new Dictionary <string, string> {
     { "photo_id", asset.Id }, { "comment_text", comment }
 }, "", (arg) => true);
Пример #10
0
 public virtual IImageAsset Apply(IImageAsset image)
 {
     return(image);
 }