mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
less hacky way of converting ContactData to Recipients
This commit is contained in:
parent
04327e9ed7
commit
c19ac8ec1e
@ -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);
|
||||
|
@ -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<ContactData> contactList = new ArrayList<ContactData>();
|
||||
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<Recipient> recipients = new ArrayList<Recipient>();
|
||||
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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user