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 void SetItem(ImageView IvItem, ITEM Item)
	{
		if (Item != null && 0 < Item.m_nItemUnique)
		{
			IvItem.Visible = true;
			ImageSlot slot = new ImageSlot();
			ReforgeMainDlg.SetImageSlotFromItem(ref slot, Item, 0);
			IvItem.Clear();
			IvItem.SetImageSlot(0, slot, null, null, null, null);
			IvItem.RepositionItems();
		}
		else
		{
			IvItem.Visible = false;
		}
	}
Exemple #3
0
        public static async Task <IImageSourceServiceResult <Drawable>?> UpdateSourceAsync(this ImageView imageView, IImageSourcePart image, IImageSourceServiceProvider services, CancellationToken cancellationToken = default)
        {
            imageView.Clear();

            image.UpdateIsLoading(false);

            var context = imageView.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 && imageView.IsAlive() && imageSource == image.Source;

                // only set the image if we are still on the same one
                if (applied)
                {
                    imageView.SetImageDrawable(drawable);

                    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);
        }