use of eu.siacs.conversations.ui.ConversationActivity in project Conversations by siacs.
the class ConversationAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.conversation_list_row, parent, false);
}
Conversation conversation = getItem(position);
if (this.activity instanceof ConversationActivity) {
View swipeableItem = view.findViewById(R.id.swipeable_item);
ConversationActivity a = (ConversationActivity) this.activity;
int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
swipeableItem.setBackgroundColor(c);
}
TextView convName = (TextView) view.findViewById(R.id.conversation_name);
if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
convName.setText(conversation.getName());
} else {
convName.setText(conversation.getJid().toBareJid().toString());
}
TextView mLastMessage = (TextView) view.findViewById(R.id.conversation_lastmsg);
TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate);
TextView mSenderName = (TextView) view.findViewById(R.id.sender_name);
ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage);
ImageView notificationStatus = (ImageView) view.findViewById(R.id.notification_status);
UnreadCountCustomView unreadCountCustomView = (UnreadCountCustomView) view.findViewById(R.id.unread_count);
Message message = conversation.getLatestMessage();
int unreadCount = conversation.unreadCount();
if (unreadCount > 0) {
unreadCountCustomView.setVisibility(View.VISIBLE);
unreadCountCustomView.setUnreadCount(unreadCount);
} else {
unreadCountCustomView.setVisibility(View.GONE);
}
if (!conversation.isRead()) {
convName.setTypeface(null, Typeface.BOLD);
} else {
convName.setTypeface(null, Typeface.NORMAL);
}
if (message.getFileParams().width > 0 && (message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED)) {
mSenderName.setVisibility(View.GONE);
mLastMessage.setVisibility(View.GONE);
imagePreview.setVisibility(View.VISIBLE);
activity.loadBitmap(message, imagePreview);
} else {
Pair<String, Boolean> preview = UIHelper.getMessagePreview(activity, message);
mLastMessage.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE);
mLastMessage.setText(preview.first);
if (preview.second) {
if (conversation.isRead()) {
mLastMessage.setTypeface(null, Typeface.ITALIC);
mSenderName.setTypeface(null, Typeface.NORMAL);
} else {
mLastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
mSenderName.setTypeface(null, Typeface.BOLD);
}
} else {
if (conversation.isRead()) {
mLastMessage.setTypeface(null, Typeface.NORMAL);
mSenderName.setTypeface(null, Typeface.NORMAL);
} else {
mLastMessage.setTypeface(null, Typeface.BOLD);
mSenderName.setTypeface(null, Typeface.BOLD);
}
}
if (message.getStatus() == Message.STATUS_RECEIVED) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
mSenderName.setVisibility(View.VISIBLE);
mSenderName.setText(UIHelper.getMessageDisplayName(message).split("\\s+")[0] + ':');
} else {
mSenderName.setVisibility(View.GONE);
}
} else if (message.getType() != Message.TYPE_STATUS) {
mSenderName.setVisibility(View.VISIBLE);
mSenderName.setText(activity.getString(R.string.me) + ':');
} else {
mSenderName.setVisibility(View.GONE);
}
}
long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
if (muted_till == Long.MAX_VALUE) {
notificationStatus.setVisibility(View.VISIBLE);
int ic_notifications_off = activity.getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black54_24dp);
notificationStatus.setImageResource(ic_notifications_off);
} else if (muted_till >= System.currentTimeMillis()) {
notificationStatus.setVisibility(View.VISIBLE);
int ic_notifications_paused = activity.getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black54_24dp);
notificationStatus.setImageResource(ic_notifications_paused);
} else if (conversation.alwaysNotify()) {
notificationStatus.setVisibility(View.GONE);
} else {
notificationStatus.setVisibility(View.VISIBLE);
int ic_notifications_none = activity.getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black54_24dp);
notificationStatus.setImageResource(ic_notifications_none);
}
mTimestamp.setText(UIHelper.readableTimeDifference(activity, conversation.getLatestMessage().getTimeSent()));
ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image);
loadAvatar(conversation, profilePicture);
return view;
}
Aggregations