diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 7be956abb5..b102f522f5 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -631,9 +631,9 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi } private void initializeRecipientsInput() { - if (recipients == null || recipients.isEmpty()) + if (recipients == null || recipients.isEmpty()) { recipientsPanel.setVisibility(View.VISIBLE); - else if (recipients != null) { + } else if (recipients != null) { recipientsPanel.addRecipients(this.recipients); } else { InputMethodManager input = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); diff --git a/src/org/thoughtcrime/securesms/SingleContactSelectionActivity.java b/src/org/thoughtcrime/securesms/SingleContactSelectionActivity.java index d4e0be67a7..339334098c 100644 --- a/src/org/thoughtcrime/securesms/SingleContactSelectionActivity.java +++ b/src/org/thoughtcrime/securesms/SingleContactSelectionActivity.java @@ -25,15 +25,20 @@ import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.view.MenuItem; import org.thoughtcrime.securesms.components.SingleRecipientPanel; +import org.thoughtcrime.securesms.contacts.ContactAccessor; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.ThreadDatabase; +import org.thoughtcrime.securesms.recipients.Recipient; +import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.recipients.RecipientFormattingException; import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.util.ActionBarUtil; import org.thoughtcrime.securesms.util.DynamicTheme; +import org.thoughtcrime.securesms.util.NumberUtil; import org.whispersystems.textsecure.crypto.MasterSecret; import java.util.ArrayList; +import java.util.List; import static org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData; @@ -72,29 +77,35 @@ public class SingleContactSelectionActivity extends PassphraseRequiredSherlockFr listFragment.setOnContactSelectedListener(new SingleContactSelectionListFragment.OnContactSelectedListener() { @Override public void onContactSelected(ContactData contactData) { - ArrayList contactList = new ArrayList(); - contactList.add(contactData); - - recipientsPanel.setVisibility(View.INVISIBLE); - recipientsPanel.addContacts(contactList); - try { - openNewConversation(recipientsPanel.getRecipients()); - } catch (RecipientFormattingException rfe) { - recipientsPanel.clear(); - recipientsPanel.setVisibility(View.VISIBLE); - } + Log.i(TAG, "Choosing contact from list."); + Recipients recipients = contactDataToRecipients(contactData); + openNewConversation(recipients); } }); recipientsPanel.setPanelChangeListener(new SingleRecipientPanel.RecipientsPanelChangedListener() { @Override public void onRecipientsPanelUpdate(Recipients recipients) { - Log.i(TAG, "onRecipientsPanelUpdate received."); + Log.i(TAG, "Choosing contact from autocompletion."); openNewConversation(recipients); } }); } + private Recipients contactDataToRecipients(ContactData contactData) { + if (contactData == null || contactData.numbers == null) return null; + List recipients = new ArrayList(); + for (ContactAccessor.NumberData numberData : contactData.numbers) { + if (NumberUtil.isValidSmsOrEmailOrGroup(numberData.number)) { + Recipient recipient = RecipientFactory.getRecipientForNumber(SingleContactSelectionActivity.this, + numberData.number, + false); + recipients.add(recipient); + } + } + return new Recipients(recipients); + } + private void openNewConversation(Recipients recipients) { if (recipients != null) { Intent intent = new Intent(SingleContactSelectionActivity.this, ConversationActivity.class); diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java b/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java index aac8f8a172..c591efb360 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java @@ -51,7 +51,7 @@ public class RecipientFactory { return new Recipients(results); } - private static Recipient getRecipientForNumber(Context context, String number, boolean asynchronous) { + public static Recipient getRecipientForNumber(Context context, String number, boolean asynchronous) { long recipientId = CanonicalAddressDatabase.getInstance(context).getCanonicalAddress(number); return provider.getRecipient(context, recipientId, asynchronous); }