Commit 62f2ebc2 authored by Adrien Béraud's avatar Adrien Béraud

conversation: avoid race-condition during file transfer

Change-Id: I7a22363e61a0158dc043bce5f5f0175c868b12f1
parent c2d4ea05
...@@ -580,7 +580,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -580,7 +580,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
@NonNull final Interaction interaction, int position) { @NonNull final Interaction interaction, int position) {
DataTransfer file = (DataTransfer) interaction; DataTransfer file = (DataTransfer) interaction;
File path = presenter.getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath()); File path = presenter.getDeviceRuntimeService().getConversationPath(file.getPeerId(), file.getStoragePath());
file.setSize(path.length()); if (file.isComplete())
file.setSize(path.length());
String timeString = timestampToDetailString(viewHolder.itemView.getContext(), file.getTimestamp()); String timeString = timestampToDetailString(viewHolder.itemView.getContext(), file.getTimestamp());
viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(t -> { viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(t -> {
...@@ -594,21 +595,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -594,21 +595,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
} }
})); }));
TransferMsgType type; TransferMsgType type = viewHolder.type.getTransferType();
if (!file.isComplete()) {
type = TransferMsgType.FILE;
} else if (file.isPicture()) {
type = TransferMsgType.IMAGE;
} else if (file.isAudio()) {
type = TransferMsgType.AUDIO;
} else if (file.isVideo()) {
type = TransferMsgType.VIDEO;
} else {
type = TransferMsgType.FILE;
}
viewHolder.compositeDisposable.clear(); viewHolder.compositeDisposable.clear();
if (hasPermanentTimeString(file, position)) { if (hasPermanentTimeString(file, position)) {
viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(t -> { viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(t -> {
String timeSeparationString = timestampToDetailString(viewHolder.itemView.getContext(), file.getTimestamp()); String timeSeparationString = timestampToDetailString(viewHolder.itemView.getContext(), file.getTimestamp());
...@@ -651,6 +639,9 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -651,6 +639,9 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
viewHolder.mImage : (type == TransferMsgType.VIDEO) ? viewHolder.mImage : (type == TransferMsgType.VIDEO) ?
viewHolder.video : (type == TransferMsgType.AUDIO) ? viewHolder.video : (type == TransferMsgType.AUDIO) ?
viewHolder.mAudioInfoLayout : viewHolder.mFileInfoLayout; viewHolder.mAudioInfoLayout : viewHolder.mFileInfoLayout;
if (longPressView == null) {
return;
}
if (type == TransferMsgType.AUDIO || type == TransferMsgType.FILE) { if (type == TransferMsgType.AUDIO || type == TransferMsgType.FILE) {
longPressView.getBackground().setTintList(null); longPressView.getBackground().setTintList(null);
} }
...@@ -1163,6 +1154,12 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -1163,6 +1154,12 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
SINGLE; SINGLE;
} }
private enum TransferMsgType {
FILE,
IMAGE,
AUDIO,
VIDEO;
}
public enum MessageType { public enum MessageType {
INCOMING_FILE(R.layout.item_conv_file_peer), INCOMING_FILE(R.layout.item_conv_file_peer),
INCOMING_IMAGE(R.layout.item_conv_image_peer), INCOMING_IMAGE(R.layout.item_conv_image_peer),
...@@ -1183,12 +1180,26 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -1183,12 +1180,26 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
MessageType(int l) { MessageType(int l) {
layout = l; layout = l;
} }
}
private enum TransferMsgType { boolean isFile() {
FILE, return this == INCOMING_FILE || this == OUTGOING_FILE;
IMAGE, }
AUDIO, boolean isAudio() {
VIDEO; return this == INCOMING_AUDIO || this == OUTGOING_AUDIO;
}
boolean isVideo() {
return this == INCOMING_VIDEO || this == OUTGOING_VIDEO;
}
boolean isImage() {
return this == INCOMING_IMAGE || this == OUTGOING_IMAGE;
}
public TransferMsgType getTransferType() {
return isFile() ? TransferMsgType.FILE
: (isImage() ? TransferMsgType.IMAGE
: (isAudio() ? TransferMsgType.AUDIO
: (isVideo() ? TransferMsgType.VIDEO : TransferMsgType.FILE)));
}
} }
} }
...@@ -39,6 +39,7 @@ import cx.ring.utils.UiUpdater; ...@@ -39,6 +39,7 @@ import cx.ring.utils.UiUpdater;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
public class ConversationViewHolder extends RecyclerView.ViewHolder { public class ConversationViewHolder extends RecyclerView.ViewHolder {
public ConversationAdapter.MessageType type;
public View mItem; public View mItem;
public TextView mMsgTxt; public TextView mMsgTxt;
public TextView mMsgDetailTxt; public TextView mMsgDetailTxt;
...@@ -66,6 +67,7 @@ public class ConversationViewHolder extends RecyclerView.ViewHolder { ...@@ -66,6 +67,7 @@ public class ConversationViewHolder extends RecyclerView.ViewHolder {
public ConversationViewHolder(ViewGroup v, ConversationAdapter.MessageType type) { public ConversationViewHolder(ViewGroup v, ConversationAdapter.MessageType type) {
super(v); super(v);
this.type = type;
if (type == ConversationAdapter.MessageType.CONTACT_EVENT) { if (type == ConversationAdapter.MessageType.CONTACT_EVENT) {
mMsgTxt = v.findViewById(R.id.contact_event_txt); mMsgTxt = v.findViewById(R.id.contact_event_txt);
mMsgDetailTxt = v.findViewById(R.id.contact_event_details_txt); mMsgDetailTxt = v.findViewById(R.id.contact_event_details_txt);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment