From 8933e03c025d3c8b9e143eae9c8133500ee1a427 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Wed, 9 Sep 2015 15:08:31 -1000 Subject: [PATCH] prevent blocking recipient resolution on UI thread fixes #4058 Closes #4059 // FREEBIE --- src/org/thoughtcrime/securesms/SmsSendtoActivity.java | 2 +- .../securesms/components/PushRecipientsPanel.java | 10 ++++++++-- .../securesms/components/SingleRecipientPanel.java | 11 ++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/SmsSendtoActivity.java b/src/org/thoughtcrime/securesms/SmsSendtoActivity.java index 5b63b2def8..e36f161560 100644 --- a/src/org/thoughtcrime/securesms/SmsSendtoActivity.java +++ b/src/org/thoughtcrime/securesms/SmsSendtoActivity.java @@ -38,7 +38,7 @@ public class SmsSendtoActivity extends Activity { destination = getDestinationForView(original); } - Recipients recipients = RecipientFactory.getRecipientsFromString(this, destination.getDestination(), false); + Recipients recipients = RecipientFactory.getRecipientsFromString(this, destination.getDestination(), true); long threadId = DatabaseFactory.getThreadDatabase(this).getThreadIdIfExistsFor(recipients); final Intent nextIntent; diff --git a/src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java b/src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java index 3efd39b226..30ff3dbd9e 100644 --- a/src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java +++ b/src/org/thoughtcrime/securesms/components/PushRecipientsPanel.java @@ -36,6 +36,7 @@ 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.recipients.Recipients.RecipientsModifiedListener; import java.util.HashSet; import java.util.Iterator; @@ -49,7 +50,7 @@ import java.util.Set; * * @author Moxie Marlinspike */ -public class PushRecipientsPanel extends RelativeLayout { +public class PushRecipientsPanel extends RelativeLayout implements RecipientsModifiedListener { private final String TAG = PushRecipientsPanel.class.getSimpleName(); private RecipientsPanelChangedListener panelChangeListener; @@ -90,7 +91,7 @@ public class PushRecipientsPanel extends RelativeLayout { public Recipients getRecipients() throws RecipientFormattingException { String rawText = recipientsText.getText().toString(); - Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText, false); + Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText, true); if (recipients.isEmpty()) throw new RecipientFormattingException("Recipient List Is Empty!"); @@ -129,6 +130,7 @@ public class PushRecipientsPanel extends RelativeLayout { } catch (RecipientFormattingException e) { recipients = RecipientFactory.getRecipientsFor(getContext(), new LinkedList(), true); } + recipients.addListener(this); recipientsText.setAdapter(new RecipientsAdapter(this.getContext())); recipientsText.populate(recipients); @@ -149,6 +151,10 @@ public class PushRecipientsPanel extends RelativeLayout { }); } + @Override public void onModified(Recipients recipients) { + recipientsText.populate(recipients); + } + private class FocusChangedListener implements View.OnFocusChangeListener { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus && (panelChangeListener != null)) { diff --git a/src/org/thoughtcrime/securesms/components/SingleRecipientPanel.java b/src/org/thoughtcrime/securesms/components/SingleRecipientPanel.java index 9d9662c00b..1685ad75c3 100644 --- a/src/org/thoughtcrime/securesms/components/SingleRecipientPanel.java +++ b/src/org/thoughtcrime/securesms/components/SingleRecipientPanel.java @@ -17,7 +17,6 @@ package org.thoughtcrime.securesms.components; import android.content.Context; -import android.os.Build; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -33,6 +32,7 @@ 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.recipients.Recipients.RecipientsModifiedListener; import java.util.Iterator; import java.util.LinkedList; @@ -44,7 +44,7 @@ import java.util.List; * * @author Moxie Marlinspike */ -public class SingleRecipientPanel extends RelativeLayout { +public class SingleRecipientPanel extends RelativeLayout implements RecipientsModifiedListener { private final String TAG = SingleRecipientPanel.class.getSimpleName(); private RecipientsPanelChangedListener panelChangeListener; @@ -94,7 +94,7 @@ public class SingleRecipientPanel extends RelativeLayout { public Recipients getRecipients() throws RecipientFormattingException { String rawText = recipientsText.getText().toString(); - Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText, false); + Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText, true); if (recipients.isEmpty()) throw new RecipientFormattingException("Recipient List Is Empty!"); @@ -132,6 +132,7 @@ public class SingleRecipientPanel extends RelativeLayout { } catch (RecipientFormattingException e) { recipients = RecipientFactory.getRecipientsFor(getContext(), new LinkedList(), true); } + recipients.addListener(this); recipientsText.setAdapter(new RecipientsAdapter(this.getContext())); recipientsText.populate(recipients); @@ -152,6 +153,10 @@ public class SingleRecipientPanel extends RelativeLayout { }); } + @Override public void onModified(Recipients recipients) { + recipientsText.populate(recipients); + } + private class FocusChangedListener implements OnFocusChangeListener { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus && (panelChangeListener != null)) {