Propagate task cancellation
Cancel TaskCompletionSource when supplied CT is cancelled (ie download request is cancelled by Uno Image). This is because UIL seems to internally cancel previous downloads if a new URI is requested for the same ImageView (without raising IImageListener callbacks), leading to tasks that never return, but are still awaited for subsequent requests to the same URI thanks to the concurrency-management logic.
This commit is contained in:
Родитель
105e9346d7
Коммит
9d5c4cd91c
|
@ -98,54 +98,61 @@ namespace Com.Nostra13.Universalimageloader.Core
|
||||||
{
|
{
|
||||||
TaskCompletionSource<Android.Graphics.Bitmap> source = new TaskCompletionSource<Android.Graphics.Bitmap>();
|
TaskCompletionSource<Android.Graphics.Bitmap> source = new TaskCompletionSource<Android.Graphics.Bitmap>();
|
||||||
|
|
||||||
|
|
||||||
options = options ?? new DisplayImageOptions.Builder()
|
options = options ?? new DisplayImageOptions.Builder()
|
||||||
.CacheInMemory(true)
|
.CacheInMemory(true)
|
||||||
.CacheOnDisk(true)
|
.CacheOnDisk(true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
using (var aware =
|
// Propagate cancellation to the managed TCS, even though we don't propagate it to Universal Image Loader. This is because UIL has
|
||||||
imageView != null
|
// the air of cancelling downloads itself if another uri is requested for the same ImageView, leading us to wait on a task that
|
||||||
? new ImageViewAwareCancellable(imageView, ct)
|
// will never complete (thanks to the concurrency logic reusing existing tasks).
|
||||||
: null
|
using (ct.Register(() => source.TrySetCanceled()))
|
||||||
)
|
|
||||||
{
|
{
|
||||||
using (var listener = new ImageListener(source))
|
using (var aware =
|
||||||
|
imageView != null
|
||||||
|
? new ImageViewAwareCancellable(imageView, ct)
|
||||||
|
: null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (targetSize != null && imageView != null)
|
using (var listener = new ImageListener(source))
|
||||||
{
|
{
|
||||||
imageView.SetMaxHeight(targetSize.Value.Height);
|
if (targetSize != null && imageView != null)
|
||||||
imageView.SetMaxWidth(targetSize.Value.Width);
|
{
|
||||||
|
imageView.SetMaxHeight(targetSize.Value.Height);
|
||||||
|
imageView.SetMaxWidth(targetSize.Value.Width);
|
||||||
|
|
||||||
ImageLoader.Instance.DisplayImage(
|
ImageLoader.Instance.DisplayImage(
|
||||||
uri,
|
uri,
|
||||||
aware,
|
aware,
|
||||||
options,
|
options,
|
||||||
listener
|
listener
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
else if (targetSize != null && imageView == null)
|
||||||
|
{
|
||||||
|
var targetImageSize = new ImageSize(targetSize.Value.Width, targetSize.Value.Height);
|
||||||
|
|
||||||
|
ImageLoader.Instance.LoadImage(
|
||||||
|
uri,
|
||||||
|
targetImageSize,
|
||||||
|
options,
|
||||||
|
listener
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImageLoader.Instance.LoadImage(
|
||||||
|
uri,
|
||||||
|
options,
|
||||||
|
listener
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var target = await source.Task;
|
||||||
|
|
||||||
|
return target;
|
||||||
}
|
}
|
||||||
else if (targetSize != null && imageView == null)
|
|
||||||
{
|
|
||||||
var targetImageSize = new ImageSize(targetSize.Value.Width, targetSize.Value.Height);
|
|
||||||
|
|
||||||
ImageLoader.Instance.LoadImage(
|
|
||||||
uri,
|
|
||||||
targetImageSize,
|
|
||||||
options,
|
|
||||||
listener
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImageLoader.Instance.LoadImage(
|
|
||||||
uri,
|
|
||||||
options,
|
|
||||||
listener
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = await source.Task;
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,7 +232,7 @@ namespace Com.Nostra13.Universalimageloader.Core
|
||||||
|
|
||||||
public void OnLoadingCancelled(string p0, Android.Views.View p1)
|
public void OnLoadingCancelled(string p0, Android.Views.View p1)
|
||||||
{
|
{
|
||||||
_source.SetCanceled();
|
_source.TrySetCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnLoadingComplete(string p0, Android.Views.View p1, Android.Graphics.Bitmap bitmap)
|
public void OnLoadingComplete(string p0, Android.Views.View p1, Android.Graphics.Bitmap bitmap)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче