From 449a53ea328488c11f2135c2b3c29500c24a7c08 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Fri, 13 Mar 2020 10:56:25 +1100 Subject: [PATCH] Fix QR code handler not running on UI thread --- .../conversation/ConversationItem.java | 1 + .../activities/JoinPublicChatActivity.kt | 28 +++++++++---------- .../fragments/ScanQRCodeWrapperFragment.kt | 4 ++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index d63da04f01..235679f008 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -797,6 +797,7 @@ public class ConversationItem extends LinearLayout } private void setContactPhoto(@NonNull Recipient recipient) { + if (messageRecord == null) return; LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)bodyBubble.getLayoutParams(); int groupThreadMargin = (int)(getResources().getDimension(R.dimen.large_spacing) + getResources().getDimension(R.dimen.small_profile_picture_size)); int defaultMargin = 0; diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt index 38970a1f9c..b293977cd5 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt @@ -62,22 +62,20 @@ class JoinPublicChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCode } fun joinPublicChatIfPossible(url: String) { - runOnUiThread { - if (!Patterns.WEB_URL.matcher(url).matches() || !url.startsWith("https://")) { - Toast.makeText(this, "Invalid URL", Toast.LENGTH_SHORT).show() - return@runOnUiThread - } - showLoader() + if (!Patterns.WEB_URL.matcher(url).matches() || !url.startsWith("https://")) { + Toast.makeText(this, "Invalid URL", Toast.LENGTH_SHORT).show() + return + } + showLoader() - val channel: Long = 1 - OpenGroupUtilities.addGroup(this, url, channel).success { - MessageSender.syncAllOpenGroups(this) - }.successUi { - finish() - }.failUi { - hideLoader() - Toast.makeText(this, "Couldn't join channel", Toast.LENGTH_SHORT).show() - } + val channel: Long = 1 + OpenGroupUtilities.addGroup(this, url, channel).success { + MessageSender.syncAllOpenGroups(this) + }.successUi { + finish() + }.failUi { + hideLoader() + Toast.makeText(this, "Couldn't join channel", Toast.LENGTH_SHORT).show() } } // endregion diff --git a/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeWrapperFragment.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeWrapperFragment.kt index 1d546613b0..1895071f2f 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeWrapperFragment.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeWrapperFragment.kt @@ -52,7 +52,9 @@ class ScanQRCodeWrapperFragment : Fragment(), ScanQRCodePlaceholderFragmentDeleg } override fun onQrDataFound(string: String) { - delegate?.handleQRCodeScanned(string) + activity?.runOnUiThread { + delegate?.handleQRCodeScanned(string) + } } }