fixed some rare crashes caused by race conditions

This commit is contained in:
Daniel Gultsch 2018-12-17 19:35:08 +01:00
parent 30d5c08c35
commit 5c920a9362
2 changed files with 6 additions and 6 deletions

View file

@ -1773,7 +1773,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (scrollState != null) {
outState.putParcelable(STATE_SCROLL_POSITION, scrollState);
}
final ArrayList<Attachment> attachments = mediaPreviewAdapter.getAttachments();
final ArrayList<Attachment> attachments = mediaPreviewAdapter == null ? new ArrayList<>() : mediaPreviewAdapter.getAttachments();
if (attachments.size() > 0) {
outState.putParcelableArrayList(STATE_MEDIA_PREVIEWS, attachments);
}

View file

@ -214,9 +214,10 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.edit_indicator.setVisibility(View.GONE);
}
}
final Transferable transferable = message.getTransferable();
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || transferable != null) {
FileParams params = message.getFileParams();
if (params.size > (1.5 * 1024 * 1024)) {
filesize = Math.round(params.size * 1f / (1024 * 1024)) + " MiB";
@ -225,7 +226,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} else if (params.size > 0) {
filesize = params.size + " B";
}
if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) {
if (transferable != null && transferable.getStatus() == Transferable.STATUS_FAILED) {
error = true;
}
}
@ -234,9 +235,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
info = getContext().getString(R.string.waiting);
break;
case Message.STATUS_UNSEND:
Transferable d = message.getTransferable();
if (d != null) {
info = getContext().getString(R.string.sending_file, d.getProgress());
if (transferable != null) {
info = getContext().getString(R.string.sending_file, transferable.getProgress());
} else {
info = getContext().getString(R.string.sending);
}