mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 20:19:42 +01:00
Significantly improve last message display
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
0d6df931ea
commit
5cbb8c2e31
@ -42,6 +42,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.rooms.Conversation;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.TextMatchers;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -144,38 +145,45 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
||||
holder.dialogDate.setText(DateUtils.getRelativeTimeSpanString(conversation.getLastActivity() * 1000L,
|
||||
System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
|
||||
|
||||
if (conversation.getType() == Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL || !(TextUtils.isEmpty(conversation.getLastMessage().getSystemMessage()))) {
|
||||
if (!TextUtils.isEmpty(conversation.getLastMessage().getSystemMessage())) {
|
||||
holder.dialogLastMessageUserAvatar.setVisibility(View.GONE);
|
||||
holder.dialogLastMessage.setText(conversation.getLastMessage().getText());
|
||||
} else {
|
||||
holder.dialogLastMessageUserAvatar.setVisibility(View.VISIBLE);
|
||||
if (conversation.getLastMessage().getActorId().equals(userEntity.getUserId())) {
|
||||
authorDisplayName = context.getString(R.string.nc_chat_you) + ": ";
|
||||
authorDisplayName = context.getString(R.string.nc_chat_you);
|
||||
} else {
|
||||
if (!TextUtils.isEmpty(conversation.getLastMessage().getActorDisplayName())) {
|
||||
authorDisplayName = conversation.getLastMessage().getActorDisplayName() + ": ";
|
||||
authorDisplayName = conversation.getLastMessage().getActorDisplayName();
|
||||
} else {
|
||||
authorDisplayName = context.getString(R.string.nc_nick_guest) + ": ";
|
||||
authorDisplayName = context.getString(R.string.nc_nick_guest);
|
||||
}
|
||||
}
|
||||
|
||||
String fullString = authorDisplayName + conversation.getLastMessage().getText();
|
||||
if (conversation.getLastMessage().getSpecialURLType().equals(TextMatchers.SpecialURLType.NONE)) {
|
||||
authorDisplayName += ": ";
|
||||
} else {
|
||||
authorDisplayName += " ";
|
||||
}
|
||||
|
||||
String fullString = authorDisplayName + conversation.getLastMessage().getLastMessageDisplayText();
|
||||
Spannable spannableString = new SpannableString(fullString);
|
||||
final StyleSpan boldStyleSpan = new StyleSpan(Typeface.BOLD);
|
||||
spannableString.setSpan(boldStyleSpan, 0, fullString.indexOf(":") + 1, Spannable
|
||||
.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
spannableString.setSpan(boldStyleSpan, 0, fullString.indexOf(" "), Spannable
|
||||
.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
||||
holder.dialogLastMessage.setText(spannableString);
|
||||
holder.dialogLastMessageUserAvatar.setVisibility(View.VISIBLE);
|
||||
|
||||
int smallAvatarSize = Math.round(context.getResources().getDimension(R.dimen.small_item_height));
|
||||
|
||||
if (conversation.getLastMessage().getActorType().equals("guests")) {
|
||||
holder.dialogLastMessageUserAvatar.setVisibility(View.VISIBLE);
|
||||
TextDrawable drawable = TextDrawable.builder().beginConfig().bold()
|
||||
.endConfig().buildRound(String.valueOf(authorDisplayName.charAt(0)),
|
||||
context.getResources().getColor(R.color.nc_grey));
|
||||
holder.dialogLastMessageUserAvatar.setImageDrawable(drawable);
|
||||
} else {
|
||||
} else if (conversation.getLastMessage().getActorId().equals(userEntity.getUserId())
|
||||
|| !conversation.getType().equals(Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL)) {
|
||||
holder.dialogLastMessageUserAvatar.setVisibility(View.VISIBLE);
|
||||
GlideUrl glideUrl = new GlideUrl(ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
|
||||
conversation.getLastMessage().getActorId(), R.dimen.small_item_height), new LazyHeaders.Builder()
|
||||
.setHeader("Accept", "image/*")
|
||||
@ -190,6 +198,8 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
||||
.override(smallAvatarSize, smallAvatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(holder.dialogLastMessageUserAvatar);
|
||||
} else {
|
||||
holder.dialogLastMessageUserAvatar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonIgnore;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.models.json.converters.EnumSystemMessageTypeConverter;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.TextMatchers;
|
||||
@ -49,6 +50,19 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
|
||||
return TextMatchers.getSpecialUrlTypeMessage(getMessage());
|
||||
}
|
||||
|
||||
private boolean hasFileAttachment() {
|
||||
if (messageParameters != null && messageParameters.size() > 0) {
|
||||
for (String key : messageParameters.keySet()) {
|
||||
Map<String, String> individualHashMap = messageParameters.get(key);
|
||||
if (individualHashMap.get("type").equals("file")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getImageUrl() {
|
||||
@ -64,7 +78,8 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
|
||||
}
|
||||
}
|
||||
|
||||
if (getSpecialURLType() != TextMatchers.SpecialURLType.NONE) {
|
||||
if (!getSpecialURLType().equals(TextMatchers.SpecialURLType.NONE) &&
|
||||
!getSpecialURLType().equals(TextMatchers.SpecialURLType.REGULAR)) {
|
||||
return getMessage().trim();
|
||||
}
|
||||
|
||||
@ -148,6 +163,25 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
|
||||
return ChatUtils.getParsedMessage(getMessage(), getMessageParameters());
|
||||
}
|
||||
|
||||
public String getLastMessageDisplayText() {
|
||||
if (getSpecialURLType().equals(TextMatchers.SpecialURLType.NONE)) {
|
||||
return getText();
|
||||
} else {
|
||||
if (getSpecialURLType().equals(TextMatchers.SpecialURLType.GIPHY)
|
||||
|| getSpecialURLType().equals(TextMatchers.SpecialURLType.TENOR)) {
|
||||
return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_gif));
|
||||
} else if (getSpecialURLType().equals(TextMatchers.SpecialURLType.REGULAR)) {
|
||||
if (hasFileAttachment()) {
|
||||
return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_attachment));
|
||||
} else {
|
||||
return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_link));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUser getUser() {
|
||||
return new IUser() {
|
||||
|
@ -180,6 +180,9 @@
|
||||
<string name="nc_new_messages">New messages</string>
|
||||
<string name="nc_no_messages_yet">No messages yet</string>
|
||||
<string name="nc_chat_you">You</string>
|
||||
<string name="nc_sent_a_link">sent a link.</string>
|
||||
<string name="nc_sent_a_gif">sent a GIF.</string>
|
||||
<string name="nc_sent_an_attachment">sent an attachment.</string>
|
||||
|
||||
<!-- Contacts endless loading -->
|
||||
<string name="nc_no_more_load_retry">No more items to load. Refresh to retry.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user