Refactor "unnamed" group logic

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-01-22 21:23:51 -08:00
parent 7e51d61c79
commit dadc8d0183
4 changed files with 20 additions and 29 deletions

View File

@ -117,7 +117,7 @@
<string name="ConversationActivity_message_is_empty_exclamation">Message is empty!</string> <string name="ConversationActivity_message_is_empty_exclamation">Message is empty!</string>
<string name="ConversationActivity_group_members">Group members</string> <string name="ConversationActivity_group_members">Group members</string>
<string name="ConversationActivity_group_conversation">Group conversation</string> <string name="ConversationActivity_group_conversation">Group conversation</string>
<string name="ConversationActivity_unnamed_group">Unnamed group</string>
<plurals name="ConversationActivity_d_recipients_in_group"> <plurals name="ConversationActivity_d_recipients_in_group">
<item quantity="one">1 member</item> <item quantity="one">1 member</item>
<item quantity="other">%d members</item> <item quantity="other">%d members</item>
@ -455,6 +455,9 @@
<string name="RecipientPreferenceActivity_disabled">Disabled</string> <string name="RecipientPreferenceActivity_disabled">Disabled</string>
<string name="RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received">Available once a message has been sent or received.</string> <string name="RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received">Available once a message has been sent or received.</string>
<!-- RecipientProvider -->
<string name="RecipientProvider_unnamed_group">Unnamed group</string>
<!-- RedPhone --> <!-- RedPhone -->
<string name="RedPhone_answering">Answering</string> <string name="RedPhone_answering">Answering</string>
<string name="RedPhone_ending_call">Ending call</string> <string name="RedPhone_ending_call">Ending call</string>

View File

@ -71,11 +71,7 @@ public class ConversationTitleView extends LinearLayout {
this.subtitle.setVisibility(View.VISIBLE); this.subtitle.setVisibility(View.VISIBLE);
} }
} else { } else {
String groupName = (!TextUtils.isEmpty(recipient.getName())) ? this.title.setText(recipient.getName());
recipient.getName() :
getContext().getString(R.string.ConversationActivity_unnamed_group);
this.title.setText(groupName);
this.subtitle.setText(null); this.subtitle.setText(null);
this.subtitle.setVisibility(View.GONE); this.subtitle.setVisibility(View.GONE);
} }

View File

@ -3,13 +3,10 @@ package org.thoughtcrime.securesms.components;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.emoji.EmojiTextView; import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
@ -40,22 +37,11 @@ public class FromTextView extends EmojiTextView {
public void setText(Recipients recipients, boolean read) { public void setText(Recipients recipients, boolean read) {
int attributes[] = new int[]{R.attr.conversation_list_item_count_color}; int attributes[] = new int[]{R.attr.conversation_list_item_count_color};
TypedArray colors = getContext().obtainStyledAttributes(attributes); TypedArray colors = getContext().obtainStyledAttributes(attributes);
boolean isUnnamedGroup = recipients.isGroupRecipient() && TextUtils.isEmpty(recipients.getPrimaryRecipient().getName()); String fromString = recipients.toShortString();
String fromString;
if (isUnnamedGroup) {
fromString = getContext().getString(R.string.ConversationActivity_unnamed_group);
} else {
fromString = recipients.toShortString();
}
int typeface; int typeface;
if (isUnnamedGroup) { if (!read) {
if (!read) typeface = Typeface.BOLD_ITALIC;
else typeface = Typeface.ITALIC;
} else if (!read) {
typeface = Typeface.BOLD; typeface = Typeface.BOLD;
} else { } else {
typeface = Typeface.NORMAL; typeface = Typeface.NORMAL;

View File

@ -167,13 +167,19 @@ public class RecipientProvider {
if (record != null) { if (record != null) {
ContactPhoto contactPhoto = ContactPhotoFactory.getGroupContactPhoto(record.getAvatar()); ContactPhoto contactPhoto = ContactPhotoFactory.getGroupContactPhoto(record.getAvatar());
return new RecipientDetails(record.getTitle(), groupId, null, contactPhoto, null); String title = record.getTitle();
if (title == null) {
title = context.getString(R.string.RecipientProvider_unnamed_group);;
} }
return new RecipientDetails(null, groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null); return new RecipientDetails(title, groupId, null, contactPhoto, null);
}
return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null);
} catch (IOException e) { } catch (IOException e) {
Log.w("RecipientProvider", e); Log.w("RecipientProvider", e);
return new RecipientDetails(null, groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null); return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null);
} }
} }