Show something for unnamed groups, allow us to have different default photos for groups vs. individuals

This commit is contained in:
Jake McGinty 2014-02-17 21:42:30 -08:00
parent 877ed8f59c
commit 25324a45b3
5 changed files with 57 additions and 15 deletions

View file

@ -67,6 +67,7 @@
<string name="ConversationActivity_forward_message_prefix">FWD</string>
<string name="ConversationActivity_group_conversation_recipients">Group Conversation Recipients</string>
<string name="ConversationActivity_group_conversation">Group Conversation</string>
<string name="ConversationActivity_unnamed_group">Unnamed Group</string>
<string name="ConversationActivity_d_recipients_in_group">%d members</string>
<string name="ConversationActivity_d_recipients_in_group_singular">1 member</string>
<string name="ConversationActivity_saving_draft">Saving draft...</string>

View file

@ -24,6 +24,9 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
@ -32,6 +35,7 @@ import android.provider.ContactsContract;
import android.telephony.PhoneNumberUtils;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.ContextMenu;
@ -57,6 +61,7 @@ import org.thoughtcrime.securesms.components.EmojiToggle;
import org.thoughtcrime.securesms.components.RecipientsPanel;
import org.thoughtcrime.securesms.contacts.ContactAccessor;
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
import org.thoughtcrime.securesms.crypto.KeyExchangeInitiator;
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor;
import org.thoughtcrime.securesms.database.DatabaseFactory;
@ -80,6 +85,7 @@ import org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.util.ActionBarUtil;
import org.thoughtcrime.securesms.util.BitmapDecodingException;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.CharacterCalculator;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
@ -486,8 +492,12 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
}
} else if (isGroupConversation()) {
if (isPushGroupConversation()) {
Log.i(TAG, "name: " + getRecipients().getPrimaryRecipient().getName() + ", number: " + getRecipients().getPrimaryRecipient().getNumber() + ", avatar?: " + (getRecipients().getPrimaryRecipient().getContactPhoto() != null));
title = getRecipients().getPrimaryRecipient().getName();
final String groupName = getRecipients().getPrimaryRecipient().getName();
title = (!TextUtils.isEmpty(groupName)) ? groupName : getString(R.string.ConversationActivity_unnamed_group);
final Bitmap avatar = getRecipients().getPrimaryRecipient().getContactPhoto();
if (avatar != null) {
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), BitmapUtil.getCroppedBitmap(avatar)));
}
}
else {
title = getString(R.string.ConversationActivity_group_conversation);

View file

@ -27,6 +27,7 @@ import android.provider.Contacts.Intents;
import android.provider.ContactsContract.QuickContact;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.view.View;
@ -66,7 +67,6 @@ public class ConversationListItem extends RelativeLayout
private boolean read;
private ImageView contactPhotoImage;
private QuickContactBadge contactPhotoBadge;
private final Handler handler = new Handler();
private int distributionType;
@ -87,7 +87,6 @@ public class ConversationListItem extends RelativeLayout
this.fromView = (TextView) findViewById(R.id.from);
this.dateView = (TextView) findViewById(R.id.date);
this.contactPhotoBadge = (QuickContactBadge) findViewById(R.id.contact_photo_badge);
this.contactPhotoImage = (ImageView) findViewById(R.id.contact_photo_image);
initializeContactWidgetVisibility();
@ -167,14 +166,30 @@ public class ConversationListItem extends RelativeLayout
int attributes[] = new int[] {R.attr.conversation_list_item_count_color};
TypedArray colors = context.obtainStyledAttributes(attributes);
String fromString = from.toShortString();
final String fromString;
final boolean isUnnamedGroup = from.isGroupRecipient() && TextUtils.isEmpty(from.getPrimaryRecipient().getName());
if (isUnnamedGroup) {
fromString = context.getString(R.string.ConversationActivity_unnamed_group);
} else {
fromString = from.toShortString();
}
SpannableStringBuilder builder = new SpannableStringBuilder(fromString);
if (!read) {
builder.setSpan(new StyleSpan(Typeface.BOLD), 0, builder.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
final int typeface;
if (isUnnamedGroup) {
if (!read) typeface = Typeface.BOLD_ITALIC;
else typeface = Typeface.ITALIC;
} else if (!read) {
typeface = Typeface.BOLD;
} else {
typeface = Typeface.NORMAL;
}
builder.setSpan(new StyleSpan(typeface), 0, builder.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
colors.recycle();
return builder;
}

View file

@ -38,6 +38,15 @@ public class ContactPhotoFactory {
}
}
public static Bitmap getDefaultGroupPhoto(Context context) {
synchronized (defaultPhotoLock) {
if (defaultContactPhoto == null)
defaultContactPhoto = BitmapFactory.decodeResource(context.getResources(),
R.drawable.ic_contact_picture);
return defaultContactPhoto;
}
}
public static Bitmap getLocalUserContactPhoto(Context context, Uri uri) {
if (uri == null) return getDefaultContactPhoto(context);

View file

@ -66,16 +66,19 @@ public class RecipientProvider {
Recipient recipient;
RecipientDetails details;
String number = CanonicalAddressDatabase.getInstance(context).getAddressFromId(String.valueOf(recipientId));
final boolean isGroupRecipient = GroupUtil.isEncodedGroup(number);
if (GroupUtil.isEncodedGroup(number)) details = getGroupRecipientDetails(context, number);
else details = getRecipientDetails(context, number);
if (isGroupRecipient) details = getGroupRecipientDetails(context, number);
else details = getRecipientDetails(context, number);
if (details != null) {
recipient = new Recipient(details.name, number, recipientId, details.contactUri, details.avatar);
} else {
recipient = new Recipient(null, number, recipientId, null, ContactPhotoFactory.getDefaultContactPhoto(context));
final Bitmap defaultPhoto = isGroupRecipient
? ContactPhotoFactory.getDefaultGroupPhoto(context)
: ContactPhotoFactory.getDefaultContactPhoto(context);
recipient = new Recipient(null, number, recipientId, null, defaultPhoto);
}
recipientCache.put(recipientId, recipient);
@ -86,12 +89,13 @@ public class RecipientProvider {
Log.w("RecipientProvider", "Cache miss [ASYNC]!");
final String number = CanonicalAddressDatabase.getInstance(context).getAddressFromId(String.valueOf(recipientId));
final boolean isGroupRecipient = GroupUtil.isEncodedGroup(number);
Callable<RecipientDetails> task = new Callable<RecipientDetails>() {
@Override
public RecipientDetails call() throws Exception {
if (GroupUtil.isEncodedGroup(number)) return getGroupRecipientDetails(context, number);
else return getRecipientDetails(context, number);
if (isGroupRecipient) return getGroupRecipientDetails(context, number);
else return getRecipientDetails(context, number);
}
};
@ -99,7 +103,10 @@ public class RecipientProvider {
asyncRecipientResolver.submit(future);
Recipient recipient = new Recipient(number, ContactPhotoFactory.getDefaultContactPhoto(context), recipientId, future);
final Bitmap defaultPhoto = isGroupRecipient
? ContactPhotoFactory.getDefaultGroupPhoto(context)
: ContactPhotoFactory.getDefaultContactPhoto(context);
Recipient recipient = new Recipient(number, defaultPhoto, recipientId, future);
recipientCache.put(recipientId, recipient);
return recipient;