diff --git a/ring-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.java b/ring-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.java index 8a0dcd3f48ebbc069537b2d0eb2f6909e6111b57..e880e2b9c0055c86691f58d60cb94ff748d39f4f 100644 --- a/ring-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.java +++ b/ring-android/app/src/main/java/cx/ring/adapters/ConversationAdapter.java @@ -580,7 +580,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo @NonNull final Interaction interaction, int position) { DataTransfer file = (DataTransfer) interaction; 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()); viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(t -> { @@ -594,21 +595,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo } })); - TransferMsgType type; - 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; - } - + TransferMsgType type = viewHolder.type.getTransferType(); viewHolder.compositeDisposable.clear(); - if (hasPermanentTimeString(file, position)) { viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(t -> { String timeSeparationString = timestampToDetailString(viewHolder.itemView.getContext(), file.getTimestamp()); @@ -651,6 +639,9 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo viewHolder.mImage : (type == TransferMsgType.VIDEO) ? viewHolder.video : (type == TransferMsgType.AUDIO) ? viewHolder.mAudioInfoLayout : viewHolder.mFileInfoLayout; + if (longPressView == null) { + return; + } if (type == TransferMsgType.AUDIO || type == TransferMsgType.FILE) { longPressView.getBackground().setTintList(null); } @@ -1163,6 +1154,12 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo SINGLE; } + private enum TransferMsgType { + FILE, + IMAGE, + AUDIO, + VIDEO; + } public enum MessageType { INCOMING_FILE(R.layout.item_conv_file_peer), INCOMING_IMAGE(R.layout.item_conv_image_peer), @@ -1183,12 +1180,26 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo MessageType(int l) { layout = l; } - } - private enum TransferMsgType { - FILE, - IMAGE, - AUDIO, - VIDEO; + boolean isFile() { + return this == INCOMING_FILE || this == OUTGOING_FILE; + } + boolean isAudio() { + 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))); + } } + } diff --git a/ring-android/app/src/main/java/cx/ring/views/ConversationViewHolder.java b/ring-android/app/src/main/java/cx/ring/views/ConversationViewHolder.java index 647eb9c211113209ef820195f0ab5576d53367e5..de764a619a60dc111067e07b9a3a56a8f8f54b2f 100644 --- a/ring-android/app/src/main/java/cx/ring/views/ConversationViewHolder.java +++ b/ring-android/app/src/main/java/cx/ring/views/ConversationViewHolder.java @@ -39,6 +39,7 @@ import cx.ring.utils.UiUpdater; import io.reactivex.disposables.CompositeDisposable; public class ConversationViewHolder extends RecyclerView.ViewHolder { + public ConversationAdapter.MessageType type; public View mItem; public TextView mMsgTxt; public TextView mMsgDetailTxt; @@ -66,6 +67,7 @@ public class ConversationViewHolder extends RecyclerView.ViewHolder { public ConversationViewHolder(ViewGroup v, ConversationAdapter.MessageType type) { super(v); + this.type = type; if (type == ConversationAdapter.MessageType.CONTACT_EVENT) { mMsgTxt = v.findViewById(R.id.contact_event_txt); mMsgDetailTxt = v.findViewById(R.id.contact_event_details_txt);