From 41c9bed155e978f970f8d1d117787783300bcb6e Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Thu, 19 Jan 2017 11:31:41 -0800 Subject: [PATCH] ViewStub for EmojiDrawer // FREEBIE --- res/layout/conversation_activity.xml | 9 +++---- ...conversation_activity_emojidrawer_stub.xml | 7 ++++++ .../securesms/ConversationActivity.java | 24 +++++++++++++------ .../securesms/components/InputPanel.java | 8 +++++-- 4 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 res/layout/conversation_activity_emojidrawer_stub.xml diff --git a/res/layout/conversation_activity.xml b/res/layout/conversation_activity.xml index 0faa9da03c..26492329c5 100644 --- a/res/layout/conversation_activity.xml +++ b/res/layout/conversation_activity.xml @@ -67,11 +67,12 @@ android:text="160/160 (1)" /> - + android:layout_height="wrap_content"/> diff --git a/res/layout/conversation_activity_emojidrawer_stub.xml b/res/layout/conversation_activity_emojidrawer_stub.xml new file mode 100644 index 0000000000..d29a342eaa --- /dev/null +++ b/res/layout/conversation_activity_emojidrawer_stub.xml @@ -0,0 +1,7 @@ + + diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 89b03b222f..93a54e1b09 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -214,7 +214,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private AudioRecorder audioRecorder; private BroadcastReceiver securityUpdateReceiver; private BroadcastReceiver recipientsStaleReceiver; - private EmojiDrawer emojiDrawer; + private Stub emojiDrawerStub; protected HidingLinearLayout quickAttachmentToggle; private QuickAttachmentDrawer quickAttachmentDrawer; private InputPanel inputPanel; @@ -326,7 +326,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity super.onConfigurationChanged(newConfig); composeText.setTransport(sendButton.getSelectedTransport()); quickAttachmentDrawer.onConfigurationChanged(); - if (container.getCurrentInput() == emojiDrawer) container.hideAttachedInput(true); + + if (emojiDrawerStub.resolved() && container.getCurrentInput() == emojiDrawerStub.get()) { + container.hideAttachedInput(true); + } } @Override @@ -987,7 +990,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity attachButton = ViewUtil.findById(this, R.id.attach_button); composeText = ViewUtil.findById(this, R.id.embedded_text_editor); charactersLeft = ViewUtil.findById(this, R.id.space_left); - emojiDrawer = ViewUtil.findById(this, R.id.emoji_drawer); + emojiDrawerStub = ViewUtil.findStubById(this, R.id.emoji_drawer_stub); unblockButton = ViewUtil.findById(this, R.id.unblock_button); makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button); composePanel = ViewUtil.findById(this, R.id.bottom_panel); @@ -1001,7 +1004,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity View composeBubble = ViewUtil.findById(this, R.id.compose_bubble); container.addOnKeyboardShownListener(this); - inputPanel.setListener(this, emojiDrawer); + inputPanel.setListener(this); inputPanel.setMediaListener(this); int[] attributes = new int[]{R.attr.conversation_item_bubble_background}; @@ -1017,7 +1020,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity SendButtonListener sendButtonListener = new SendButtonListener(); ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener(); - emojiDrawer.setEmojiEventListener(inputPanel); composeText.setOnEditorActionListener(sendButtonListener); attachButton.setOnClickListener(new AttachButtonListener()); attachButton.setOnLongClickListener(new AttachButtonLongClickListener()); @@ -1624,8 +1626,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void onEmojiToggle() { - if (container.getCurrentInput() == emojiDrawer) container.showSoftkey(composeText); - else container.show(composeText, emojiDrawer); + if (!emojiDrawerStub.resolved()) { + inputPanel.setEmojiDrawer(emojiDrawerStub.get()); + emojiDrawerStub.get().setEmojiEventListener(inputPanel); + } + + if (container.getCurrentInput() == emojiDrawerStub.get()) { + container.showSoftkey(composeText); + } else { + container.show(composeText, emojiDrawerStub.get()); + } } @Override diff --git a/src/org/thoughtcrime/securesms/components/InputPanel.java b/src/org/thoughtcrime/securesms/components/InputPanel.java index 90d2c3e048..6ea8f5b441 100644 --- a/src/org/thoughtcrime/securesms/components/InputPanel.java +++ b/src/org/thoughtcrime/securesms/components/InputPanel.java @@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.thoughtcrime.securesms.util.concurrent.SettableFuture; +import org.thoughtcrime.securesms.util.views.Stub; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -99,10 +100,9 @@ public class InputPanel extends LinearLayout } } - public void setListener(final @NonNull Listener listener, @NonNull EmojiDrawer emojiDrawer) { + public void setListener(final @NonNull Listener listener) { this.listener = listener; - emojiToggle.attach(emojiDrawer); emojiToggle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -115,6 +115,10 @@ public class InputPanel extends LinearLayout composeText.setMediaListener(listener); } + public void setEmojiDrawer(@NonNull EmojiDrawer emojiDrawer) { + emojiToggle.attach(emojiDrawer); + } + @Override public void onRecordPressed(float startPositionX) { if (listener != null) listener.onRecorderStarted();