2015-09-17 02:31:24 +02:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2015-09-16 00:28:27 +02:00
|
|
|
import android.support.annotation.NonNull;
|
2015-09-17 02:31:24 +02:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-09-16 00:28:27 +02:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2015-09-17 02:31:24 +02:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2015-09-21 19:54:23 +02:00
|
|
|
import org.thoughtcrime.securesms.util.DateUtils;
|
2015-09-17 02:31:24 +02:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
2015-09-16 00:28:27 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2015-09-17 02:31:24 +02:00
|
|
|
public class ConversationUpdateItem extends LinearLayout
|
2015-09-16 00:28:27 +02:00
|
|
|
implements Recipients.RecipientsModifiedListener, Recipient.RecipientModifiedListener, BindableConversationItem, View.OnClickListener
|
2015-09-17 02:31:24 +02:00
|
|
|
{
|
|
|
|
private static final String TAG = ConversationUpdateItem.class.getSimpleName();
|
|
|
|
|
|
|
|
private ImageView icon;
|
|
|
|
private TextView body;
|
2015-09-21 19:54:23 +02:00
|
|
|
private TextView date;
|
2015-09-17 02:31:24 +02:00
|
|
|
private Recipient sender;
|
|
|
|
private MessageRecord messageRecord;
|
2015-09-21 19:54:23 +02:00
|
|
|
private Locale locale;
|
2015-09-17 02:31:24 +02:00
|
|
|
|
|
|
|
public ConversationUpdateItem(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConversationUpdateItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
|
|
|
this.icon = (ImageView)findViewById(R.id.conversation_update_icon);
|
|
|
|
this.body = (TextView)findViewById(R.id.conversation_update_body);
|
2015-09-21 19:54:23 +02:00
|
|
|
this.date = (TextView)findViewById(R.id.conversation_update_date);
|
2015-09-17 02:31:24 +02:00
|
|
|
|
|
|
|
setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:28:27 +02:00
|
|
|
@Override
|
|
|
|
public void bind(@NonNull MasterSecret masterSecret,
|
|
|
|
@NonNull MessageRecord messageRecord,
|
|
|
|
@NonNull Locale locale,
|
|
|
|
@NonNull Set<MessageRecord> batchSelected,
|
2015-10-22 00:32:29 +02:00
|
|
|
@NonNull Recipients conversationRecipients)
|
2015-09-16 00:28:27 +02:00
|
|
|
{
|
2015-09-21 19:54:23 +02:00
|
|
|
bind(messageRecord, locale);
|
2015-09-16 00:28:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-21 19:54:23 +02:00
|
|
|
private void bind(@NonNull MessageRecord messageRecord, @NonNull Locale locale) {
|
2015-09-17 02:31:24 +02:00
|
|
|
this.messageRecord = messageRecord;
|
|
|
|
this.sender = messageRecord.getIndividualRecipient();
|
2015-09-21 19:54:23 +02:00
|
|
|
this.locale = locale;
|
2015-09-17 02:31:24 +02:00
|
|
|
|
|
|
|
this.sender.addListener(this);
|
|
|
|
|
2015-09-21 19:54:23 +02:00
|
|
|
if (messageRecord.isGroupAction()) setGroupRecord(messageRecord);
|
|
|
|
else if (messageRecord.isCallLog()) setCallRecord(messageRecord);
|
2015-10-27 20:18:02 +01:00
|
|
|
else if (messageRecord.isJoined()) setJoinedRecord(messageRecord);
|
|
|
|
else throw new AssertionError("Neither group nor log nor joined.");
|
2015-09-21 19:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setCallRecord(MessageRecord messageRecord) {
|
|
|
|
if (messageRecord.isIncomingCall()) icon.setImageResource(R.drawable.ic_call_received_grey600_24dp);
|
|
|
|
else if (messageRecord.isOutgoingCall()) icon.setImageResource(R.drawable.ic_call_made_grey600_24dp);
|
|
|
|
else icon.setImageResource(R.drawable.ic_call_missed_grey600_24dp);
|
|
|
|
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setText(DateUtils.getExtendedRelativeTimeSpanString(getContext(), locale, messageRecord.getDateReceived()));
|
|
|
|
date.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setGroupRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
|
|
|
|
|
|
|
if (messageRecord.isGroupQuit() && messageRecord.isOutgoing()) {
|
|
|
|
body.setText(R.string.MessageRecord_left_group);
|
|
|
|
} else if (messageRecord.isGroupQuit()) {
|
|
|
|
body.setText(getContext().getString(R.string.ConversationItem_group_action_left, sender.toShortString()));
|
|
|
|
} else {
|
|
|
|
GroupUtil.GroupDescription description = GroupUtil.getDescription(getContext(), messageRecord.getBody().getBody());
|
|
|
|
description.addListener(this);
|
|
|
|
body.setText(description.toString());
|
2015-09-17 02:31:24 +02:00
|
|
|
}
|
2015-09-21 19:54:23 +02:00
|
|
|
|
|
|
|
date.setVisibility(View.GONE);
|
2015-09-17 02:31:24 +02:00
|
|
|
}
|
|
|
|
|
2015-10-27 20:18:02 +01:00
|
|
|
private void setJoinedRecord(MessageRecord messageRecord) {
|
|
|
|
icon.setImageResource(R.drawable.ic_favorite_grey600_24dp);
|
|
|
|
body.setText(messageRecord.getDisplayBody());
|
|
|
|
date.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2015-09-17 02:31:24 +02:00
|
|
|
@Override
|
|
|
|
public void onModified(Recipients recipients) {
|
|
|
|
onModified(recipients.getPrimaryRecipient());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onModified(Recipient recipient) {
|
|
|
|
Util.runOnMain(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-09-21 19:54:23 +02:00
|
|
|
bind(messageRecord, locale);
|
2015-09-17 02:31:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (messageRecord.isIdentityUpdate()) {
|
|
|
|
Intent intent = new Intent(getContext(), RecipientPreferenceActivity.class);
|
|
|
|
intent.putExtra(RecipientPreferenceActivity.RECIPIENTS_EXTRA,
|
|
|
|
new long[] {messageRecord.getIndividualRecipient().getRecipientId()});
|
|
|
|
|
|
|
|
getContext().startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unbind() {
|
|
|
|
if (sender != null) {
|
|
|
|
sender.removeListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|