Cancel contact info tasks

pull/172/head
M66B 6 years ago
parent c7cf17bac2
commit 80e5267baa

@ -388,6 +388,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private ScaleGestureDetector gestureDetector; private ScaleGestureDetector gestureDetector;
private SimpleTask taskContactInfo;
ViewHolder(final View itemView, long viewType) { ViewHolder(final View itemView, long viewType) {
super(itemView); super(itemView);
@ -953,12 +955,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
// Contact info // Contact info
ContactInfo info = ContactInfo.get(context, message.account, addresses, true); ContactInfo info = ContactInfo.get(context, message.account, addresses, true);
if (info == null) { if (info == null) {
if (taskContactInfo != null)
taskContactInfo.cancel(context);
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putLong("id", message.id); aargs.putLong("id", message.id);
aargs.putLong("account", message.account); aargs.putLong("account", message.account);
aargs.putSerializable("addresses", addresses); aargs.putSerializable("addresses", addresses);
new SimpleTask<ContactInfo>() { taskContactInfo = new SimpleTask<ContactInfo>() {
@Override @Override
protected ContactInfo onExecute(Context context, Bundle args) { protected ContactInfo onExecute(Context context, Bundle args) {
long account = args.getLong("account"); long account = args.getLong("account");
@ -969,6 +974,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override @Override
protected void onExecuted(Bundle args, ContactInfo info) { protected void onExecuted(Bundle args, ContactInfo info) {
taskContactInfo = null;
long id = args.getLong("id"); long id = args.getLong("id");
TupleMessageEx amessage = getMessage(); TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(id)) if (amessage == null || !amessage.id.equals(id))
@ -981,7 +988,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
} }
}.setLog(false).execute(context, owner, aargs, "message:avatar"); }.setLog(false);
taskContactInfo.execute(context, owner, aargs, "message:avatar");
} else } else
bindContactInfo(info, addresses, name_email); bindContactInfo(info, addresses, name_email);

Loading…
Cancel
Save