use of com.yellowmessenger.sdk.models.MessageObject in project yellowmessenger-sdk by yellowmessenger.
the class ChatListAdapter method getOwnView.
/*
RENDERING OWN VIEW I.E; right side of the chat
*/
private View getOwnView(int position, View convertView, ViewGroup parent) {
final ChatMessage chatMessage = values.get(position);
View view = convertView;
ViewHolderOwn ownViewHolder = null;
if (view == null) {
view = inflater.inflate(R.layout.chat_list_item_own, parent, false);
ownViewHolder = new ViewHolderOwn();
ownViewHolder.message = (TextView) view.findViewById(R.id.message);
ownViewHolder.timestamp = (TextView) view.findViewById(R.id.timestamp);
ownViewHolder.messageHolder = view.findViewById(R.id.message_holder);
ownViewHolder.productLayout = view.findViewById(R.id.product_image_layout);
ownViewHolder.productImage = (ImageView) view.findViewById(R.id.product_image);
ownViewHolder.productTitle = (TextView) view.findViewById(R.id.product_title);
ownViewHolder.productPrice = (TextView) view.findViewById(R.id.product_price);
view.setTag(ownViewHolder);
} else {
ownViewHolder = (ViewHolderOwn) view.getTag();
}
ownViewHolder.messageHolder.setOnClickListener(messageSendListener);
if (chatMessage.getBitmap() != null) {
ownViewHolder.productLayout.setVisibility(View.VISIBLE);
ownViewHolder.message.setVisibility(GONE);
ownViewHolder.productPrice.setVisibility(GONE);
ownViewHolder.productTitle.setVisibility(GONE);
ownViewHolder.productImage.setVisibility(View.VISIBLE);
ownViewHolder.productImage.setImageBitmap(chatMessage.getBitmap());
ownViewHolder.productImage.setOnClickListener(null);
} else {
ownViewHolder.message.setVisibility(View.VISIBLE);
ownViewHolder.productLayout.setVisibility(GONE);
MessageObject messageObject = null;
try {
messageObject = gson.fromJson(chatMessage.getMessage(), MessageObject.class);
} catch (Exception e) {
// e.printStackTrace();
}
if (messageObject != null && (messageObject.getMessage() != null || messageObject.getImage() != null)) {
ownViewHolder.message.setVisibility(GONE);
String title = messageObject.getMessage();
if (title != null) {
ownViewHolder.productTitle.setText(title);
ownViewHolder.productTitle.setVisibility(View.VISIBLE);
} else {
ownViewHolder.productTitle.setVisibility(GONE);
}
if (messageObject.getPriceString() != null) {
ownViewHolder.productPrice.setText(messageObject.getPriceString());
ownViewHolder.productPrice.setVisibility(View.VISIBLE);
} else {
ownViewHolder.productPrice.setVisibility(GONE);
}
if (messageObject.getImage() != null) {
ownViewHolder.productImage.setVisibility(View.VISIBLE);
DrawableManager.getInstance(context).fetchDrawableOnThread(messageObject.getImage(), ownViewHolder.productImage);
final String imageUrl = messageObject.getImage();
ownViewHolder.productImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, ImageActivity.class);
Bundle bundle = new Bundle();
bundle.putStringArrayList("urls", new ArrayList<>(Collections.singletonList(imageUrl)));
intent.putExtras(bundle);
((Activity) context).startActivityForResult(intent, 0);
}
});
} else {
ownViewHolder.productImage.setVisibility(GONE);
}
ownViewHolder.productLayout.setVisibility(View.VISIBLE);
} else {
ownViewHolder.productLayout.setVisibility(GONE);
ownViewHolder.message.setVisibility(View.VISIBLE);
ownViewHolder.timestamp.setVisibility(View.VISIBLE);
ownViewHolder.message.setText(Html.fromHtml(chatMessage.getMessage()));
}
}
String timestampText = null;
try {
timestampText = DateUtils.getRelativeTimeSpanString(format.parse(values.get(position).getTimestamp()).getTime(), (new Date()).getTime(), DateUtils.FORMAT_ABBREV_RELATIVE).toString() + " - " + (chatMessage.getAcknowledged() ? "Sent" : "Sending..");
} catch (ParseException e) {
e.printStackTrace();
}
ownViewHolder.timestamp.setText(timestampText);
return view;
}
Aggregations