cancel potential tasks when receiving image preview from cache
This commit is contained in:
parent
51753a1d39
commit
1d2e2f71c2
|
@ -1146,6 +1146,9 @@ public abstract class XmppActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Bitmap doInBackground(Message... params) {
|
protected Bitmap doInBackground(Message... params) {
|
||||||
|
if (isCancelled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
message = params[0];
|
message = params[0];
|
||||||
try {
|
try {
|
||||||
return xmppConnectionService.getFileBackend().getThumbnail(
|
return xmppConnectionService.getFileBackend().getThumbnail(
|
||||||
|
@ -1157,7 +1160,7 @@ public abstract class XmppActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Bitmap bitmap) {
|
protected void onPostExecute(Bitmap bitmap) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null && !isCancelled()) {
|
||||||
final ImageView imageView = imageViewReference.get();
|
final ImageView imageView = imageViewReference.get();
|
||||||
if (imageView != null) {
|
if (imageView != null) {
|
||||||
imageView.setImageBitmap(bitmap);
|
imageView.setImageBitmap(bitmap);
|
||||||
|
@ -1176,6 +1179,7 @@ public abstract class XmppActivity extends Activity {
|
||||||
bm = null;
|
bm = null;
|
||||||
}
|
}
|
||||||
if (bm != null) {
|
if (bm != null) {
|
||||||
|
cancelPotentialWork(message, imageView);
|
||||||
imageView.setImageBitmap(bm);
|
imageView.setImageBitmap(bm);
|
||||||
imageView.setBackgroundColor(0x00000000);
|
imageView.setBackgroundColor(0x00000000);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1189,13 +1193,13 @@ public abstract class XmppActivity extends Activity {
|
||||||
try {
|
try {
|
||||||
task.execute(message);
|
task.execute(message);
|
||||||
} catch (final RejectedExecutionException ignored) {
|
} catch (final RejectedExecutionException ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean cancelPotentialWork(Message message,
|
public static boolean cancelPotentialWork(Message message, ImageView imageView) {
|
||||||
ImageView imageView) {
|
|
||||||
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
|
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
|
||||||
|
|
||||||
if (bitmapWorkerTask != null) {
|
if (bitmapWorkerTask != null) {
|
||||||
|
|
Loading…
Reference in a new issue