public static Task <IImageSourceServiceResult <Drawable>?> UpdateSourceAsync(
     this ImageView imageView,
     IImageSourcePart image,
     IImageSourceServiceProvider services,
     CancellationToken cancellationToken = default)
 {
     imageView.Clear();
     return(image.UpdateSourceAsync(imageView, services, (d) => imageView.SetImageDrawable(d), cancellationToken));
 }
        public static IImageSourceService GetRequiredImageSourceService(this IImageSourceServiceProvider provider, Type imageSourceType)
        {
            var service = provider.GetImageSourceService(imageSourceType);

            if (service != null)
            {
                return(service);
            }

            throw new InvalidOperationException($"Unable to find a image source service for {provider.GetImageSourceType(imageSourceType)}.");
        }
Exemple #3
0
 public static Task <IImageSourceServiceResult <UIImage>?> UpdateSourceAsync(
     this UIImageView imageView,
     IImageSourcePart image,
     IImageSourceServiceProvider services,
     CancellationToken cancellationToken = default)
 {
     imageView.Clear();
     return(image.UpdateSourceAsync(imageView, services, (uiImage) =>
     {
         imageView.Image = uiImage;
     }, cancellationToken));
 }
 public static IImageSourceService?GetImageSourceService(this IImageSourceServiceProvider provider, IImageSource imageSource) =>
 provider.GetImageSourceService(imageSource.GetType());
 public static IImageSourceService GetRequiredImageSourceService <T>(this IImageSourceServiceProvider provider)
     where T : IImageSource =>
 provider.GetRequiredImageSourceService(typeof(T));
Exemple #6
0
 WpfTextViewCreationListener(IImageSourceServiceProvider imageSourceServiceProvider)
 {
     this.imageSourceServiceProvider = imageSourceServiceProvider;
 }
		WpfTextViewCreationListener(IImageSourceServiceProvider imageSourceServiceProvider) {
			this.imageSourceServiceProvider = imageSourceServiceProvider;
		}
Exemple #8
0
        public static async Task <IImageSourceServiceResult <WImageSource>?> UpdateSourceAsync(
            this IImageSourcePart image,
            FrameworkElement destinationContext,
            IImageSourceServiceProvider services,
            Action <WImageSource?> setImage,
            CancellationToken cancellationToken = default)
        {
            image.UpdateIsLoading(false);

            var imageSource = image.Source;

            if (imageSource == null)
            {
                return(null);
            }

            var events = image as IImageSourcePartEvents;

            events?.LoadingStarted();
            image.UpdateIsLoading(true);

            try
            {
                var service = services.GetRequiredImageSourceService(imageSource);

                var scale  = destinationContext.XamlRoot?.RasterizationScale ?? 1;
                var result = await service.GetImageSourceAsync(imageSource, (float)scale, cancellationToken);

                var uiImage = result?.Value;

                var applied = !cancellationToken.IsCancellationRequested && imageSource == image.Source;

                // only set the image if we are still on the same one
                if (applied)
                {
                    setImage(uiImage);
                    if (destinationContext is WImage imageView)
                    {
                        imageView.UpdateIsAnimationPlaying(image);
                    }
                }

                events?.LoadingCompleted(applied);

                return(result);
            }
            catch (OperationCanceledException)
            {
                // no-op
                events?.LoadingCompleted(false);
            }
            catch (Exception ex)
            {
                events?.LoadingFailed(ex);
            }
            finally
            {
                // only mark as finished if we are still working on the same image
                if (imageSource == image.Source)
                {
                    image.UpdateIsLoading(false);
                }
            }

            return(null);
        }
        public static async Task UpdateThumbImageSourceAsync(this UISlider uiSlider, ISlider slider, IImageSourceServiceProvider provider)
        {
            var thumbImageSource = slider.ThumbImageSource;

            if (thumbImageSource != null)
            {
                var service = provider.GetRequiredImageSourceService(thumbImageSource);
                var result  = await service.GetImageAsync(thumbImageSource);

                var thumbImage = result?.Value;

                uiSlider.SetThumbImage(thumbImage, UIControlState.Normal);
            }
        }
Exemple #10
0
 WpfHexViewCreationListenerImpl(IImageSourceServiceProvider imageSourceServiceProvider) => this.imageSourceServiceProvider = imageSourceServiceProvider;
        public static async Task <IImageSourceServiceResult?> UpdateSourceAsync(
            this IImageSourcePart image,
            View destinationContext,
            IImageSourceServiceProvider services,
            Action <Drawable?> setImage,
            CancellationToken cancellationToken = default)
        {
            image.UpdateIsLoading(false);

            var context = destinationContext.Context;

            if (context == null)
            {
                return(null);
            }

            var destinationImageView = destinationContext as Android.Widget.ImageView;

            if (destinationImageView is null && setImage is null)
            {
                return(null);
            }

            var imageSource = image.Source;

            if (imageSource == null)
            {
                return(null);
            }

            var events = image as IImageSourcePartEvents;

            events?.LoadingStarted();
            image.UpdateIsLoading(true);

            try
            {
                var service = services.GetRequiredImageSourceService(imageSource);

                var applied = !cancellationToken.IsCancellationRequested && destinationContext.IsAlive() && imageSource == image.Source;

                IImageSourceServiceResult?result = null;

                if (applied)
                {
                    if (destinationImageView is not null)
                    {
                        result = await service.LoadDrawableAsync(imageSource, destinationImageView, cancellationToken);
                    }
                    else
                    {
                        result = await service.GetDrawableAsync(imageSource, context, cancellationToken);

                        if (setImage is not null && result is IImageSourceServiceResult <Drawable> drawableResult)
                        {
                            setImage.Invoke(drawableResult.Value);
                        }
                    }

                    if (result is null)
                    {
                        throw new InvalidOperationException("Glide failed to load image");
                    }
                }

                events?.LoadingCompleted(applied);
                return(result);
            }
            catch (OperationCanceledException)
            {
                // no-op
                events?.LoadingCompleted(false);
            }
            catch (Exception ex)
            {
                events?.LoadingFailed(ex);
            }
            finally
            {
                // only mark as finished if we are still working on the same image
                if (imageSource == image.Source)
                {
                    image.UpdateIsLoading(false);
                }
            }

            return(null);
        }
		WpfHexViewCreationListenerImpl(IImageSourceServiceProvider imageSourceServiceProvider) {
			this.imageSourceServiceProvider = imageSourceServiceProvider;
		}
        public static async Task UpdateThumbImageSourceAsync(this SeekBar seekBar, ISlider slider, IImageSourceServiceProvider provider, Drawable?defaultThumb)
        {
            var context = seekBar.Context;

            if (context == null)
            {
                return;
            }

            var thumbImageSource = slider.ThumbImageSource;

            if (thumbImageSource != null)
            {
                var service = provider.GetRequiredImageSourceService(thumbImageSource);
                var result  = await service.GetDrawableAsync(thumbImageSource, context);

                Drawable?thumbDrawable = result?.Value;

                if (seekBar.IsAlive())
                {
                    seekBar.SetThumb(thumbDrawable ?? defaultThumb);
                }
            }
        }
        public static async Task <IImageSourceServiceResult <Drawable>?> UpdateSourceAsync(
            this IImageSourcePart image,
            View destinationContext,
            IImageSourceServiceProvider services,
            Action <Drawable?> setDrawable,
            CancellationToken cancellationToken = default)
        {
            image.UpdateIsLoading(false);

            var context = destinationContext.Context;

            if (context == null)
            {
                return(null);
            }

            var imageSource = image.Source;

            if (imageSource == null)
            {
                return(null);
            }

            var events = image as IImageSourcePartEvents;

            events?.LoadingStarted();
            image.UpdateIsLoading(true);

            try
            {
                var service = services.GetRequiredImageSourceService(imageSource);

                var result = await service.GetDrawableAsync(imageSource, context, cancellationToken);

                var drawable = result?.Value;

                var applied = !cancellationToken.IsCancellationRequested && destinationContext.IsAlive() && imageSource == image.Source;

                // only set the image if we are still on the same one
                if (applied)
                {
                    setDrawable(drawable);
                    drawable.UpdateIsAnimationPlaying(image);
                }

                events?.LoadingCompleted(applied);

                return(result);
            }
            catch (OperationCanceledException)
            {
                // no-op
                events?.LoadingCompleted(false);
            }
            catch (Exception ex)
            {
                events?.LoadingFailed(ex);
            }
            finally
            {
                // only mark as finished if we are still working on the same image
                if (imageSource == image.Source)
                {
                    image.UpdateIsLoading(false);
                }
            }

            return(null);
        }