2014-02-28 06:44:02 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2014 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.widget.RelativeLayout;
|
2015-01-23 21:58:08 +00:00
|
|
|
|
2015-05-04 18:36:18 +00:00
|
|
|
import org.thoughtcrime.securesms.components.AvatarImageView;
|
|
|
|
import org.thoughtcrime.securesms.components.FromTextView;
|
2014-02-28 06:44:02 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple view to show the recipients of an open conversation
|
|
|
|
*
|
|
|
|
* @author Jake McGinty
|
|
|
|
*/
|
|
|
|
public class ShareListItem extends RelativeLayout
|
2015-01-15 21:35:35 +00:00
|
|
|
implements Recipient.RecipientModifiedListener
|
2014-02-28 06:44:02 +00:00
|
|
|
{
|
|
|
|
private final static String TAG = ShareListItem.class.getSimpleName();
|
|
|
|
|
2015-05-04 18:36:18 +00:00
|
|
|
private Context context;
|
|
|
|
private Recipients recipients;
|
|
|
|
private long threadId;
|
|
|
|
private FromTextView fromView;
|
2014-02-28 06:44:02 +00:00
|
|
|
|
2015-05-04 18:36:18 +00:00
|
|
|
private AvatarImageView contactPhotoImage;
|
2014-02-28 06:44:02 +00:00
|
|
|
|
|
|
|
private final Handler handler = new Handler();
|
|
|
|
private int distributionType;
|
|
|
|
|
|
|
|
public ShareListItem(Context context) {
|
|
|
|
super(context);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ShareListItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onFinishInflate() {
|
2015-05-04 18:36:18 +00:00
|
|
|
this.fromView = (FromTextView) findViewById(R.id.from);
|
|
|
|
this.contactPhotoImage = (AvatarImageView) findViewById(R.id.contact_photo_image);
|
2014-02-28 06:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void set(ThreadRecord thread) {
|
|
|
|
this.recipients = thread.getRecipients();
|
|
|
|
this.threadId = thread.getThreadId();
|
|
|
|
this.distributionType = thread.getDistributionType();
|
|
|
|
|
|
|
|
this.recipients.addListener(this);
|
2015-05-04 18:36:18 +00:00
|
|
|
this.fromView.setText(recipients);
|
2014-02-28 06:44:02 +00:00
|
|
|
|
|
|
|
setBackground();
|
2015-05-04 18:36:18 +00:00
|
|
|
this.contactPhotoImage.setAvatar(this.recipients.getPrimaryRecipient(), false);
|
2014-02-28 06:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void unbind() {
|
|
|
|
if (this.recipients != null) this.recipients.removeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setBackground() {
|
|
|
|
int[] attributes = new int[]{R.attr.conversation_list_item_background_read};
|
|
|
|
TypedArray drawables = context.obtainStyledAttributes(attributes);
|
|
|
|
|
|
|
|
setBackgroundDrawable(drawables.getDrawable(0));
|
|
|
|
|
|
|
|
drawables.recycle();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Recipients getRecipients() {
|
|
|
|
return recipients;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getThreadId() {
|
|
|
|
return threadId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDistributionType() {
|
|
|
|
return distributionType;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onModified(Recipient recipient) {
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-04 18:36:18 +00:00
|
|
|
fromView.setText(recipients);
|
|
|
|
contactPhotoImage.setAvatar(recipients.getPrimaryRecipient(), false);
|
2014-02-28 06:44:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|