ConversationsAdapter: Do not show image preview. Show pictogram instead

This commit is contained in:
Daniel Gultsch 2017-12-05 14:14:52 +01:00
parent 9869310699
commit 614372dcbb
2 changed files with 61 additions and 67 deletions

View File

@ -74,32 +74,39 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
} }
final boolean fileAvailable = message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED; final boolean fileAvailable = message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED;
if (message.getFileParams().width > 0 && fileAvailable) {
viewHolder.sender.setVisibility(View.GONE);
viewHolder.lastMessage.setVisibility(View.GONE);
viewHolder.lastMessageIcon.setVisibility(View.GONE);
viewHolder.lastImage.setVisibility(View.VISIBLE);
activity.loadBitmap(message, viewHolder.lastImage);
} else {
final boolean showPreviewText; final boolean showPreviewText;
if (message.getType() == Message.TYPE_FILE && fileAvailable) { if (fileAvailable && (message.isFileOrImage() || message.treatAsDownloadable() || message.isGeoUri())) {
if (message.getFileParams().runtime > 0) { final int imageResource;
if (message.isGeoUri()) {
imageResource = activity.getThemeResource(R.attr.ic_attach_location, R.drawable.ic_attach_location);
showPreviewText = false; showPreviewText = false;
viewHolder.lastMessageIcon.setImageResource(activity.getThemeResource(R.attr.ic_attach_record, R.drawable.ic_attach_record));
} else { } else {
final String mime = message.getMimeType();
switch (mime == null ? "" : mime.split("/")[0]) {
case "image":
imageResource = activity.getThemeResource(R.attr.ic_attach_photo, R.drawable.ic_attach_photo);
showPreviewText = false;
break;
case "video":
imageResource = activity.getThemeResource(R.attr.ic_attach_videocam, R.drawable.ic_attach_videocam);
showPreviewText = false;
break;
case "audio":
imageResource = activity.getThemeResource(R.attr.ic_attach_record, R.drawable.ic_attach_record);
showPreviewText = false;
break;
default:
imageResource = activity.getThemeResource(R.attr.ic_attach_document, R.drawable.ic_attach_document);
showPreviewText = true; showPreviewText = true;
viewHolder.lastMessageIcon.setImageResource(activity.getThemeResource(R.attr.ic_attach_document, R.drawable.ic_attach_document)); break;
} }
viewHolder.lastMessageIcon.setVisibility(View.VISIBLE); }
} else if (message.isGeoUri()) { viewHolder.lastMessageIcon.setImageResource(imageResource);
showPreviewText = false;
viewHolder.lastMessageIcon.setImageResource(activity.getThemeResource(R.attr.ic_attach_location, R.drawable.ic_attach_location));
viewHolder.lastMessageIcon.setVisibility(View.VISIBLE); viewHolder.lastMessageIcon.setVisibility(View.VISIBLE);
} else { } else {
showPreviewText = true;
viewHolder.lastMessageIcon.setVisibility(View.GONE); viewHolder.lastMessageIcon.setVisibility(View.GONE);
showPreviewText = true;
} }
final Pair<String,Boolean> preview = UIHelper.getMessagePreview(activity,message); final Pair<String,Boolean> preview = UIHelper.getMessagePreview(activity,message);
if (showPreviewText) { if (showPreviewText) {
viewHolder.lastMessage.setText(EmojiWrapper.transform(preview.first)); viewHolder.lastMessage.setText(EmojiWrapper.transform(preview.first));
@ -107,7 +114,6 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
viewHolder.lastMessageIcon.setContentDescription(preview.first); viewHolder.lastMessageIcon.setContentDescription(preview.first);
} }
viewHolder.lastMessage.setVisibility(showPreviewText ? View.VISIBLE : View.GONE); viewHolder.lastMessage.setVisibility(showPreviewText ? View.VISIBLE : View.GONE);
viewHolder.lastImage.setVisibility(View.GONE);
if (preview.second) { if (preview.second) {
if (conversation.isRead()) { if (conversation.isRead()) {
viewHolder.lastMessage.setTypeface(null, Typeface.ITALIC); viewHolder.lastMessage.setTypeface(null, Typeface.ITALIC);
@ -138,7 +144,6 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
} else { } else {
viewHolder.sender.setVisibility(View.GONE); viewHolder.sender.setVisibility(View.GONE);
} }
}
long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0); long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0);
if (muted_till == Long.MAX_VALUE) { if (muted_till == Long.MAX_VALUE) {
@ -169,7 +174,6 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
private ImageView lastMessageIcon; private ImageView lastMessageIcon;
private TextView sender; private TextView sender;
private TextView timestamp; private TextView timestamp;
private ImageView lastImage;
private ImageView notificationIcon; private ImageView notificationIcon;
private UnreadCountCustomView unreadCount; private UnreadCountCustomView unreadCount;
private ImageView avatar; private ImageView avatar;
@ -187,7 +191,6 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
viewHolder.lastMessageIcon = layout.findViewById(R.id.conversation_lastmsg_img); viewHolder.lastMessageIcon = layout.findViewById(R.id.conversation_lastmsg_img);
viewHolder.timestamp = layout.findViewById(R.id.conversation_lastupdate); viewHolder.timestamp = layout.findViewById(R.id.conversation_lastupdate);
viewHolder.sender = layout.findViewById(R.id.sender_name); viewHolder.sender = layout.findViewById(R.id.sender_name);
viewHolder.lastImage = layout.findViewById(R.id.conversation_lastimage);
viewHolder.notificationIcon = layout.findViewById(R.id.notification_status); viewHolder.notificationIcon = layout.findViewById(R.id.notification_status);
viewHolder.unreadCount = layout.findViewById(R.id.unread_count); viewHolder.unreadCount = layout.findViewById(R.id.unread_count);
viewHolder.avatar = layout.findViewById(R.id.conversation_image); viewHolder.avatar = layout.findViewById(R.id.conversation_image);

View File

@ -96,15 +96,6 @@
android:ellipsize="end" android:ellipsize="end"
android:textColor="?attr/color_text_primary" android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/> android:textSize="?attr/TextSizeBody"/>
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/conversation_lastimage"
android:layout_width="fill_parent"
android:layout_height="36dp"
android:background="@color/black87"
android:scaleType="centerCrop"
android:visibility="gone"
app:riv_corner_radius="2dp"/>
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:visibility="visible" android:visibility="visible"