From 42f613e72232991b36eb3c90eb40504ab6f026fc Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 4 Oct 2017 14:56:31 -0700 Subject: [PATCH] Be more explicit with running on main thread // FREEBIE --- .../securesms/ConversationActivity.java | 23 ++++++++----------- .../securesms/ConversationFragment.java | 8 ++----- .../securesms/MessageDetailsActivity.java | 4 ++-- .../securesms/scribbles/ScribbleActivity.java | 12 ++++------ 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 69a2cbebae..c9b5ddfa5d 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -1262,19 +1262,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void onModified(final Recipient recipient) { - titleView.post(new Runnable() { - @Override - public void run() { - titleView.setTitle(recipient); - titleView.setVerified(identityRecords.isVerified()); - setBlockedUserState(recipient, isSecureText, isDefaultSms); - setActionBarColor(recipient.getColor()); - setGroupShareProfileReminder(recipient); - updateInviteReminder(recipient.hasSeenInviteReminder()); - updateDefaultSubscriptionId(recipient.getDefaultSubscriptionId()); - initializeSecurity(isSecureText, isDefaultSms); - invalidateOptionsMenu(); - } + Util.runOnMain(() -> { + titleView.setTitle(recipient); + titleView.setVerified(identityRecords.isVerified()); + setBlockedUserState(recipient, isSecureText, isDefaultSms); + setActionBarColor(recipient.getColor()); + setGroupShareProfileReminder(recipient); + updateInviteReminder(recipient.hasSeenInviteReminder()); + updateDefaultSubscriptionId(recipient.getDefaultSubscriptionId()); + initializeSecurity(isSecureText, isDefaultSms); + invalidateOptionsMenu(); }); } diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index 1b8aa791ec..a1f9b3400b 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -69,6 +69,7 @@ import org.thoughtcrime.securesms.sms.OutgoingTextMessage; import org.thoughtcrime.securesms.util.SaveAttachmentTask; import org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment; import org.thoughtcrime.securesms.util.StickyHeaderDecoration; +import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask; @@ -491,12 +492,7 @@ public class ConversationFragment extends Fragment private void scrollToLastSeenPosition(final int lastSeenPosition) { if (lastSeenPosition > 0) { - list.post(new Runnable() { - @Override - public void run() { - ((LinearLayoutManager)list.getLayoutManager()).scrollToPositionWithOffset(lastSeenPosition, list.getHeight()); - } - }); + Util.runOnMain(() -> ((LinearLayoutManager)list.getLayoutManager()).scrollToPositionWithOffset(lastSeenPosition, list.getHeight())); } } diff --git a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java index b8acbb3693..80c5d84291 100644 --- a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java +++ b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java @@ -223,7 +223,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity } expiresContainer.setVisibility(View.VISIBLE); - expiresInText.post(new Runnable() { + Util.runOnMain(new Runnable() { @Override public void run() { long elapsed = System.currentTimeMillis() - messageRecord.getExpireStarted(); @@ -233,7 +233,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity expiresInText.setText(duration); if (running) { - expiresInText.postDelayed(this, 500); + Util.runOnMainDelayed(this, 500); } } }); diff --git a/src/org/thoughtcrime/securesms/scribbles/ScribbleActivity.java b/src/org/thoughtcrime/securesms/scribbles/ScribbleActivity.java index bb06fda0c1..dc481f0900 100644 --- a/src/org/thoughtcrime/securesms/scribbles/ScribbleActivity.java +++ b/src/org/thoughtcrime/securesms/scribbles/ScribbleActivity.java @@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.scribbles.widget.entity.ImageEntity; import org.thoughtcrime.securesms.scribbles.widget.entity.MotionEntity; import org.thoughtcrime.securesms.scribbles.widget.entity.TextEntity; import org.thoughtcrime.securesms.util.MediaUtil; +import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import java.io.ByteArrayOutputStream; @@ -74,14 +75,11 @@ public class ScribbleActivity extends PassphraseRequiredActionBarActivity implem } private void addSticker(final Bitmap pica) { - scribbleView.post(new Runnable() { - @Override - public void run() { - Layer layer = new Layer(); - ImageEntity entity = new ImageEntity(layer, pica, scribbleView.getWidth(), scribbleView.getHeight()); + Util.runOnMain(() -> { + Layer layer = new Layer(); + ImageEntity entity = new ImageEntity(layer, pica, scribbleView.getWidth(), scribbleView.getHeight()); - scribbleView.addEntityAndPosition(entity); - } + scribbleView.addEntityAndPosition(entity); }); }