The <= GB QuickContactBadge is ugly. Let's do something nicer for them.

Unfortunately GB is 50% of the TS userbase, best not to neglect them.
This commit is contained in:
Moxie Marlinspike 2012-11-20 20:14:30 -08:00
parent 80a6c65790
commit 9bf434cb3b
2 changed files with 75 additions and 26 deletions

View File

@ -1,15 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.ConversationListItem xmlns:android="http://schemas.android.com/apk/res/android" <org.thoughtcrime.securesms.ConversationListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight" android:layout_height="wrap_content"
android:paddingRight="10dip" android:paddingRight="10dip"
> >
<QuickContactBadge android:id="@+id/contact_photo" <FrameLayout android:id="@+id/contact_photo_frame"
style="?android:attr/quickContactBadgeStyleWindowLarge" android:layout_width="wrap_content"
android:layout_centerVertical="true" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" /> android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:visibility="visible">
<QuickContactBadge android:id="@+id/contact_photo_badge"
style="?android:attr/quickContactBadgeStyleWindowLarge"
android:visibility="gone" />
<ImageView android:id="@+id/contact_photo_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:cropToPadding="true"
android:scaleType="centerCrop"
android:visibility="gone" />
</FrameLayout>
<CheckBox android:id="@+id/checkbox" <CheckBox android:id="@+id/checkbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -25,8 +38,8 @@
android:layout_marginTop="6dip" android:layout_marginTop="6dip"
android:layout_marginRight="5dip" android:layout_marginRight="5dip"
android:layout_marginLeft="5dip" android:layout_marginLeft="5dip"
android:layout_alignTop="@id/contact_photo" android:layout_alignTop="@id/contact_photo_frame"
android:layout_toRightOf="@id/contact_photo" android:layout_toRightOf="@id/contact_photo_frame"
android:layout_toLeftOf="@id/checkbox" android:layout_toLeftOf="@id/checkbox"
android:layout_alignWithParentIfMissing="true" android:layout_alignWithParentIfMissing="true"
android:ellipsize="marquee" android:ellipsize="marquee"
@ -69,8 +82,8 @@
android:singleLine="true" android:singleLine="true"
android:layout_marginBottom="10dip" android:layout_marginBottom="10dip"
android:layout_marginLeft="5dip" android:layout_marginLeft="5dip"
android:layout_alignBottom="@id/contact_photo" android:layout_alignBottom="@id/contact_photo_frame"
android:layout_toRightOf="@id/contact_photo" android:layout_toRightOf="@id/contact_photo_frame"
android:layout_toLeftOf="@id/date" android:layout_toLeftOf="@id/date"
android:ellipsize="end" /> android:ellipsize="end" />

View File

@ -17,8 +17,13 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.provider.Contacts.Intents;
import android.provider.ContactsContract.QuickContact;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.format.DateUtils; import android.text.format.DateUtils;
@ -29,11 +34,13 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.QuickContactBadge; import android.widget.QuickContactBadge;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.database.model.ThreadRecord;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.recipients.Recipients;
import java.util.Set; import java.util.Set;
@ -47,22 +54,17 @@ import java.util.Set;
public class ConversationListItem extends RelativeLayout { public class ConversationListItem extends RelativeLayout {
private Context context;
private Set<Long> selectedThreads; private Set<Long> selectedThreads;
private Recipients recipients; private Recipients recipients;
private long threadId; private long threadId;
private boolean first;
private TextView subjectView; private TextView subjectView;
private TextView fromView; private TextView fromView;
private TextView dateView; private TextView dateView;
private CheckBox checkbox; private CheckBox checkbox;
private QuickContactBadge contactPhoto;
public ConversationListItem(Context context, boolean first) { private ImageView contactPhotoImage;
this(context, (Set<Long>)null); private QuickContactBadge contactPhotoBadge;
this.first = true;
contactPhoto.setVisibility(View.GONE);
}
public ConversationListItem(Context context, Set<Long> selectedThreads) { public ConversationListItem(Context context, Set<Long> selectedThreads) {
super(context); super(context);
@ -70,13 +72,17 @@ public class ConversationListItem extends RelativeLayout {
LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.conversation_list_item_view, this, true); li.inflate(R.layout.conversation_list_item_view, this, true);
this.context = context;
this.selectedThreads = selectedThreads; this.selectedThreads = selectedThreads;
this.subjectView = (TextView)findViewById(R.id.subject); this.subjectView = (TextView)findViewById(R.id.subject);
this.fromView = (TextView)findViewById(R.id.from); this.fromView = (TextView)findViewById(R.id.from);
this.dateView = (TextView)findViewById(R.id.date); this.dateView = (TextView)findViewById(R.id.date);
this.contactPhoto = (QuickContactBadge)findViewById(R.id.contact_photo);
this.checkbox = (CheckBox)findViewById(R.id.checkbox); this.checkbox = (CheckBox)findViewById(R.id.checkbox);
this.contactPhotoBadge = (QuickContactBadge)findViewById(R.id.contact_photo_badge);
this.contactPhotoImage = (ImageView)findViewById(R.id.contact_photo_image);
initializeContactWidgetVisibility();
intializeListeners(); intializeListeners();
} }
@ -104,20 +110,50 @@ public class ConversationListItem extends RelativeLayout {
if (selectedThreads != null) if (selectedThreads != null)
this.checkbox.setChecked(selectedThreads.contains(threadId)); this.checkbox.setChecked(selectedThreads.contains(threadId));
if (!first) { if (batchMode) checkbox.setVisibility(View.VISIBLE);
if (batchMode) checkbox.setVisibility(View.VISIBLE); else checkbox.setVisibility(View.GONE);
else checkbox.setVisibility(View.GONE);
contactPhoto.setImageBitmap(this.recipients.getPrimaryRecipient().getContactPhoto()); setContactPhoto(this.recipients.getPrimaryRecipient());
contactPhoto.assignContactFromPhone(this.recipients.getPrimaryRecipient().getNumber(), true);
contactPhoto.setVisibility(View.VISIBLE);
}
} }
private void intializeListeners() { private void intializeListeners() {
checkbox.setOnCheckedChangeListener(new CheckedChangedListener()); checkbox.setOnCheckedChangeListener(new CheckedChangedListener());
} }
private void initializeContactWidgetVisibility() {
if (isBadgeEnabled()) {
contactPhotoBadge.setVisibility(View.VISIBLE);
contactPhotoImage.setVisibility(View.GONE);
} else {
contactPhotoBadge.setVisibility(View.GONE);
contactPhotoImage.setVisibility(View.VISIBLE);
}
}
private void setContactPhoto(final Recipient recipient) {
if (isBadgeEnabled()) {
contactPhotoBadge.setImageBitmap(recipient.getContactPhoto());
contactPhotoBadge.assignContactFromPhone(recipient.getNumber(), true);
} else {
contactPhotoImage.setImageBitmap(recipient.getContactPhoto());
contactPhotoImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (recipient.getContactUri() != null) {
QuickContact.showQuickContact(context, contactPhotoImage, recipient.getContactUri(), QuickContact.MODE_LARGE, null);
} else {
Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, Uri.fromParts("tel", recipient.getNumber(), null));
context.startActivity(intent);
}
}
});
}
}
private boolean isBadgeEnabled() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
private CharSequence formatFrom(Recipients from, long count, boolean read) { private CharSequence formatFrom(Recipients from, long count, boolean read) {
SpannableStringBuilder builder = new SpannableStringBuilder(from.toShortString()); SpannableStringBuilder builder = new SpannableStringBuilder(from.toShortString());