2015-05-19 21:00:54 +00:00
|
|
|
package org.thoughtcrime.securesms.contacts;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-07-21 20:30:29 +00:00
|
|
|
import android.text.TextUtils;
|
2015-05-19 21:00:54 +00:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.CheckBox;
|
2015-11-03 01:40:41 +00:00
|
|
|
import android.widget.LinearLayout;
|
2015-05-19 21:00:54 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2015-06-23 22:10:50 +00:00
|
|
|
import org.thoughtcrime.securesms.components.AvatarImageView;
|
2015-07-14 21:31:03 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-05-19 21:00:54 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
2015-06-23 22:10:50 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2015-05-19 21:00:54 +00:00
|
|
|
|
2015-11-03 01:40:41 +00:00
|
|
|
public class ContactSelectionListItem extends LinearLayout implements Recipients.RecipientsModifiedListener {
|
2015-05-19 21:00:54 +00:00
|
|
|
|
2015-06-23 22:10:50 +00:00
|
|
|
private AvatarImageView contactPhotoImage;
|
|
|
|
private TextView numberView;
|
|
|
|
private TextView nameView;
|
|
|
|
private TextView labelView;
|
|
|
|
private CheckBox checkBox;
|
2015-05-19 21:00:54 +00:00
|
|
|
|
2015-06-23 22:10:50 +00:00
|
|
|
private long id;
|
|
|
|
private String number;
|
|
|
|
private Recipients recipients;
|
2015-05-19 21:00:54 +00:00
|
|
|
|
|
|
|
public ContactSelectionListItem(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContactSelectionListItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onFinishInflate() {
|
2015-06-23 22:10:50 +00:00
|
|
|
super.onFinishInflate();
|
|
|
|
this.contactPhotoImage = (AvatarImageView) findViewById(R.id.contact_photo_image);
|
|
|
|
this.numberView = (TextView) findViewById(R.id.number);
|
|
|
|
this.labelView = (TextView) findViewById(R.id.label);
|
|
|
|
this.nameView = (TextView) findViewById(R.id.name);
|
|
|
|
this.checkBox = (CheckBox) findViewById(R.id.check_box);
|
2015-05-19 21:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void set(long id, int type, String name, String number, String label, int color, boolean multiSelect) {
|
|
|
|
this.id = id;
|
|
|
|
this.number = number;
|
|
|
|
|
2015-07-14 21:31:03 +00:00
|
|
|
if (type == ContactsDatabase.NEW_TYPE) {
|
|
|
|
this.recipients = null;
|
|
|
|
this.contactPhotoImage.setAvatar(Recipient.getUnknownRecipient(), false);
|
2015-07-21 20:30:29 +00:00
|
|
|
} else if (!TextUtils.isEmpty(number)) {
|
2015-06-23 22:10:50 +00:00
|
|
|
this.recipients = RecipientFactory.getRecipientsFromString(getContext(), number, true);
|
2015-07-21 20:30:29 +00:00
|
|
|
|
2015-11-05 19:03:05 +00:00
|
|
|
if (this.recipients.getPrimaryRecipient() != null &&
|
|
|
|
this.recipients.getPrimaryRecipient().getName() != null)
|
|
|
|
{
|
2015-07-21 20:30:29 +00:00
|
|
|
name = this.recipients.getPrimaryRecipient().getName();
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:10:50 +00:00
|
|
|
this.recipients.addListener(this);
|
2015-05-19 21:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.nameView.setTextColor(color);
|
|
|
|
this.numberView.setTextColor(color);
|
2015-06-23 22:10:50 +00:00
|
|
|
this.contactPhotoImage.setAvatar(recipients, false);
|
2015-05-19 21:00:54 +00:00
|
|
|
|
|
|
|
setText(type, name, number, label);
|
|
|
|
|
|
|
|
if (multiSelect) this.checkBox.setVisibility(View.VISIBLE);
|
|
|
|
else this.checkBox.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChecked(boolean selected) {
|
|
|
|
this.checkBox.setChecked(selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unbind() {
|
2015-06-23 22:10:50 +00:00
|
|
|
if (recipients != null) {
|
|
|
|
recipients.removeListener(this);
|
|
|
|
recipients = null;
|
2015-05-19 21:00:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setText(int type, String name, String number, String label) {
|
|
|
|
if (number == null || number.isEmpty()) {
|
|
|
|
this.nameView.setEnabled(false);
|
|
|
|
this.numberView.setText("");
|
|
|
|
this.labelView.setVisibility(View.GONE);
|
|
|
|
} else if (type == ContactsDatabase.PUSH_TYPE) {
|
|
|
|
this.numberView.setText(number);
|
|
|
|
this.nameView.setEnabled(true);
|
|
|
|
this.labelView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
this.numberView.setText(number);
|
|
|
|
this.nameView.setEnabled(true);
|
|
|
|
this.labelView.setText(label);
|
|
|
|
this.labelView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.nameView.setText(name);
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:10:50 +00:00
|
|
|
public long getContactId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNumber() {
|
|
|
|
return number;
|
2015-05-19 21:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-23 22:10:50 +00:00
|
|
|
public void onModified(final Recipients recipients) {
|
|
|
|
if (this.recipients == recipients) {
|
2015-05-19 21:00:54 +00:00
|
|
|
this.contactPhotoImage.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-06-23 22:10:50 +00:00
|
|
|
contactPhotoImage.setAvatar(recipients, false);
|
2015-07-21 20:30:29 +00:00
|
|
|
nameView.setText(recipients.toShortString());
|
2015-05-19 21:00:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|