set conversation actionbar statelessly

// FREEBIE
This commit is contained in:
Jake McGinty 2015-01-04 13:14:09 -08:00
parent 5e5531805b
commit e67dafe9c8

View File

@ -574,41 +574,44 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
///// Initializers ///// Initializers
private void initializeTitleBar() { private void initializeTitleBar() {
String title = null; final String title;
String subtitle = null; final String subtitle;
final Recipient recipient = getRecipients().getPrimaryRecipient();
if (isSingleConversation()) { if (isSingleConversation()) {
title = getRecipients().getPrimaryRecipient().getName(); if (TextUtils.isEmpty(recipient.getName())) {
title = recipient.getNumber();
if (title == null || title.trim().length() == 0) { subtitle = null;
title = getRecipients().getPrimaryRecipient().getNumber();
} else { } else {
subtitle = getRecipients().getPrimaryRecipient().getNumber(); title = recipient.getName();
subtitle = PhoneNumberUtils.formatNumber(recipient.getNumber());
} }
} else if (isGroupConversation()) { } else if (isGroupConversation()) {
if (isPushGroupConversation()) { if (isPushGroupConversation()) {
final String groupName = getRecipients().getPrimaryRecipient().getName(); final String groupName = recipient.getName();
title = (!TextUtils.isEmpty(groupName)) ? groupName : getString(R.string.ConversationActivity_unnamed_group); final Bitmap avatar = recipient.getContactPhoto();
final Bitmap avatar = getRecipients().getPrimaryRecipient().getContactPhoto();
if (avatar != null) { if (avatar != null) {
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), BitmapUtil.getCircleCroppedBitmap(avatar))); getSupportActionBar().setIcon(new BitmapDrawable(getResources(), BitmapUtil.getCircleCroppedBitmap(avatar)));
} }
title = (!TextUtils.isEmpty(groupName)) ? groupName : getString(R.string.ConversationActivity_unnamed_group);
subtitle = null;
} else { } else {
title = getString(R.string.ConversationActivity_group_conversation); final int size = getRecipients().getRecipientsList().size();
int size = getRecipients().getRecipientsList().size();
title = getString(R.string.ConversationActivity_group_conversation);
subtitle = (size == 1) ? getString(R.string.ConversationActivity_d_recipients_in_group_singular) subtitle = (size == 1) ? getString(R.string.ConversationActivity_d_recipients_in_group_singular)
: String.format(getString(R.string.ConversationActivity_d_recipients_in_group), size); : String.format(getString(R.string.ConversationActivity_d_recipients_in_group), size);
} }
} else { } else {
title = getString(R.string.ConversationActivity_compose_message); title = getString(R.string.ConversationActivity_compose_message);
subtitle = ""; subtitle = null;
} }
this.getSupportActionBar().setTitle(title); getSupportActionBar().setTitle(title);
getWindow().getDecorView().setContentDescription(getString(R.string.conversation_activity__window_description, title)); getSupportActionBar().setSubtitle(subtitle);
if (subtitle != null && !TextUtils.isEmpty(subtitle)) getWindow().getDecorView().setContentDescription(getString(R.string.conversation_activity__window_description, title));
this.getSupportActionBar().setSubtitle(PhoneNumberUtils.formatNumber(subtitle));
this.supportInvalidateOptionsMenu(); this.supportInvalidateOptionsMenu();
} }