diff --git a/res/values/strings.xml b/res/values/strings.xml
index a16aa2aa3..2f053ba43 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -67,6 +67,7 @@
FWD
Group Conversation Recipients
Group Conversation
+ Unnamed Group
%d members
1 member
Saving draft...
diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java
index b59b48435..af1125bab 100644
--- a/src/org/thoughtcrime/securesms/ConversationActivity.java
+++ b/src/org/thoughtcrime/securesms/ConversationActivity.java
@@ -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);
diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java
index 916fcedd3..c8eb1e086 100644
--- a/src/org/thoughtcrime/securesms/ConversationListItem.java
+++ b/src/org/thoughtcrime/securesms/ConversationListItem.java
@@ -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;
}
diff --git a/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java b/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java
index 4120944ca..036cb0789 100644
--- a/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java
+++ b/src/org/thoughtcrime/securesms/contacts/ContactPhotoFactory.java
@@ -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);
diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java
index ab2c78e68..0ddb9f935 100644
--- a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java
+++ b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java
@@ -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 task = new Callable() {
@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;