2012-07-17 02:56:10 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-17 02:56:10 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* 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.
|
2012-07-17 02:56:10 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* 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;
|
2012-07-17 04:35:32 +00:00
|
|
|
import android.graphics.Typeface;
|
2012-12-24 16:40:37 +00:00
|
|
|
import android.os.Handler;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-05-04 18:36:18 +00:00
|
|
|
import org.thoughtcrime.securesms.components.AvatarImageView;
|
|
|
|
import org.thoughtcrime.securesms.components.FromTextView;
|
2012-10-28 23:04:24 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
2012-07-17 02:56:10 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2014-01-08 22:29:05 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DateUtils;
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2015-03-19 20:08:48 +00:00
|
|
|
import java.util.Locale;
|
2012-07-17 02:56:10 +00:00
|
|
|
import java.util.Set;
|
2015-02-06 02:35:13 +00:00
|
|
|
|
|
|
|
import static org.thoughtcrime.securesms.util.SpanUtil.color;
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* A view that displays the element in a list of multiple conversation threads.
|
|
|
|
* Used by SecureSMS's ListActivity via a ConversationListAdapter.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
|
|
|
|
2012-12-24 16:40:37 +00:00
|
|
|
public class ConversationListItem extends RelativeLayout
|
2015-06-09 14:37:20 +00:00
|
|
|
implements Recipients.RecipientsModifiedListener
|
2012-12-24 16:40:37 +00:00
|
|
|
{
|
2014-02-19 20:29:00 +00:00
|
|
|
private final static String TAG = ConversationListItem.class.getSimpleName();
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2015-02-06 02:35:13 +00:00
|
|
|
private final static Typeface BOLD_TYPEFACE = Typeface.create("sans-serif", Typeface.BOLD);
|
|
|
|
private final static Typeface LIGHT_TYPEFACE = Typeface.create("sans-serif-light", Typeface.NORMAL);
|
|
|
|
|
2015-05-04 18:36:18 +00:00
|
|
|
private Context context;
|
|
|
|
private Set<Long> selectedThreads;
|
|
|
|
private Recipients recipients;
|
|
|
|
private long threadId;
|
|
|
|
private TextView subjectView;
|
|
|
|
private FromTextView fromView;
|
|
|
|
private TextView dateView;
|
|
|
|
private boolean read;
|
|
|
|
private AvatarImageView contactPhotoImage;
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2012-12-24 16:40:37 +00:00
|
|
|
private final Handler handler = new Handler();
|
2013-04-26 01:59:49 +00:00
|
|
|
private int distributionType;
|
2012-12-24 16:40:37 +00:00
|
|
|
|
|
|
|
public ConversationListItem(Context context) {
|
2011-12-20 18:20:44 +00:00
|
|
|
super(context);
|
2012-12-24 16:40:37 +00:00
|
|
|
this.context = context;
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2012-12-24 16:40:37 +00:00
|
|
|
public ConversationListItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
this.context = context;
|
|
|
|
}
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2012-12-24 16:40:37 +00:00
|
|
|
@Override
|
|
|
|
protected void onFinishInflate() {
|
2015-06-09 14:37:20 +00:00
|
|
|
super.onFinishInflate();
|
2013-05-24 01:10:15 +00:00
|
|
|
this.subjectView = (TextView) findViewById(R.id.subject);
|
2015-05-04 18:36:18 +00:00
|
|
|
this.fromView = (FromTextView) findViewById(R.id.from);
|
2013-05-24 01:10:15 +00:00
|
|
|
this.dateView = (TextView) findViewById(R.id.date);
|
2015-05-04 18:36:18 +00:00
|
|
|
this.contactPhotoImage = (AvatarImageView) findViewById(R.id.contact_photo_image);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2015-03-19 20:08:48 +00:00
|
|
|
public void set(ThreadRecord thread, Locale locale, Set<Long> selectedThreads, boolean batchMode) {
|
2013-04-26 01:59:49 +00:00
|
|
|
this.selectedThreads = selectedThreads;
|
|
|
|
this.recipients = thread.getRecipients();
|
|
|
|
this.threadId = thread.getThreadId();
|
|
|
|
this.read = thread.isRead();
|
|
|
|
this.distributionType = thread.getDistributionType();
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2013-01-06 23:46:26 +00:00
|
|
|
this.recipients.addListener(this);
|
2015-05-04 18:36:18 +00:00
|
|
|
this.fromView.setText(recipients, read);
|
2014-02-14 23:59:57 +00:00
|
|
|
|
2015-05-06 20:53:55 +00:00
|
|
|
this.subjectView.setText(thread.getDisplayBody());
|
2015-02-06 02:35:13 +00:00
|
|
|
this.subjectView.setTypeface(read ? LIGHT_TYPEFACE : BOLD_TYPEFACE);
|
|
|
|
|
|
|
|
if (thread.getDate() > 0) {
|
2015-03-19 20:08:48 +00:00
|
|
|
CharSequence date = DateUtils.getBriefRelativeTimeSpanString(context, locale, thread.getDate());
|
2015-02-06 02:35:13 +00:00
|
|
|
dateView.setText(read ? date : color(getResources().getColor(R.color.textsecure_primary), date));
|
|
|
|
dateView.setTypeface(read ? LIGHT_TYPEFACE : BOLD_TYPEFACE);
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2015-06-01 23:51:14 +00:00
|
|
|
setBatchState(batchMode);
|
2015-05-04 18:36:18 +00:00
|
|
|
this.contactPhotoImage.setAvatar(recipients.getPrimaryRecipient(), true);
|
2013-01-06 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void unbind() {
|
2013-06-25 20:20:29 +00:00
|
|
|
if (this.recipients != null)
|
|
|
|
this.recipients.removeListener(this);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2015-06-01 23:51:14 +00:00
|
|
|
private void setBatchState(boolean batch) {
|
|
|
|
setSelected(batch && selectedThreads.contains(threadId));
|
2013-02-09 18:03:38 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public Recipients getRecipients() {
|
|
|
|
return recipients;
|
|
|
|
}
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public long getThreadId() {
|
|
|
|
return threadId;
|
|
|
|
}
|
2012-07-17 02:56:10 +00:00
|
|
|
|
2013-04-26 01:59:49 +00:00
|
|
|
public int getDistributionType() {
|
|
|
|
return distributionType;
|
|
|
|
}
|
|
|
|
|
2012-12-24 16:40:37 +00:00
|
|
|
@Override
|
2015-06-09 14:37:20 +00:00
|
|
|
public void onModified(final Recipients recipients) {
|
2012-12-24 16:40:37 +00:00
|
|
|
handler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-04 18:36:18 +00:00
|
|
|
fromView.setText(recipients, read);
|
|
|
|
contactPhotoImage.setAvatar(recipients.getPrimaryRecipient(), true);
|
2012-12-24 16:40:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|