From 508a666e7645622c6683033f14762bb89f09fd2a Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 18 Jan 2017 18:46:40 -0800 Subject: [PATCH] ViewStub for ReminderView, lazy create AttachmentTypeSelector // FREEBIE --- res/layout/conversation_activity.xml | 10 ++++++---- ...onversation_activity_reminderview_stub.xml | 6 ++++++ .../securesms/ConversationActivity.java | 19 ++++++++++++------- .../securesms/ConversationPopupActivity.java | 4 +++- .../thoughtcrime/securesms/util/ViewUtil.java | 5 +++++ 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 res/layout/conversation_activity_reminderview_stub.xml diff --git a/res/layout/conversation_activity.xml b/res/layout/conversation_activity.xml index 52d33534b..0faa9da03 100644 --- a/res/layout/conversation_activity.xml +++ b/res/layout/conversation_activity.xml @@ -23,10 +23,12 @@ android:clipToPadding="false" android:clipChildren="false"> - + + diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 68ea8ba8b..89b03b222 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -55,6 +55,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.view.View.OnKeyListener; +import android.view.ViewStub; import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.ImageButton; @@ -143,6 +144,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 org.whispersystems.libsignal.InvalidMessageException; import org.whispersystems.libsignal.util.guava.Optional; @@ -205,7 +207,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private Button makeDefaultSmsButton; private InputAwareLayout container; private View composePanel; - protected ReminderView reminderView; + protected Stub reminderView; private AttachmentTypeSelector attachmentTypeSelector; private AttachmentManager attachmentManager; @@ -782,6 +784,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private void handleAddAttachment() { if (this.isMmsEnabled || isSecureText) { + if (attachmentTypeSelector == null) { + attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener()); + } attachmentTypeSelector.show(this, attachButton); } else { handleManualMmsRequired(); @@ -947,12 +952,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void onClick(View v) { handleInviteLink(); - reminderView.requestDismiss(); + reminderView.get().requestDismiss(); } }); - reminderView.showReminder(reminder); - } else { - reminderView.hide(); + reminderView.get().showReminder(reminder); + } else if (reminderView.resolved()) { + reminderView.get().hide(); } } @@ -987,7 +992,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button); composePanel = ViewUtil.findById(this, R.id.bottom_panel); container = ViewUtil.findById(this, R.id.layout_container); - reminderView = ViewUtil.findById(this, R.id.reminder); + reminderView = ViewUtil.findStubById(this, R.id.reminder_stub); quickAttachmentDrawer = ViewUtil.findById(this, R.id.quick_attachment_drawer); quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle); inputPanel = ViewUtil.findById(this, R.id.bottom_panel); @@ -1005,7 +1010,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity composeBubble.getBackground().setColorFilter(defaultColor, PorterDuff.Mode.MULTIPLY); colors.recycle(); - attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener()); + attachmentTypeSelector = null; attachmentManager = new AttachmentManager(this, this); audioRecorder = new AudioRecorder(this, masterSecret); diff --git a/src/org/thoughtcrime/securesms/ConversationPopupActivity.java b/src/org/thoughtcrime/securesms/ConversationPopupActivity.java index e0ba797db..94eaf6e22 100644 --- a/src/org/thoughtcrime/securesms/ConversationPopupActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationPopupActivity.java @@ -122,6 +122,8 @@ public class ConversationPopupActivity extends ConversationActivity { @Override protected void updateInviteReminder(boolean seenInvite) { - reminderView.setVisibility(View.GONE); + if (reminderView.resolved()) { + reminderView.get().setVisibility(View.GONE); + } } } diff --git a/src/org/thoughtcrime/securesms/util/ViewUtil.java b/src/org/thoughtcrime/securesms/util/ViewUtil.java index bc919b26a..947a90266 100644 --- a/src/org/thoughtcrime/securesms/util/ViewUtil.java +++ b/src/org/thoughtcrime/securesms/util/ViewUtil.java @@ -42,6 +42,7 @@ import android.widget.TextView; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.thoughtcrime.securesms.util.concurrent.SettableFuture; +import org.thoughtcrime.securesms.util.views.Stub; public class ViewUtil { @SuppressWarnings("deprecation") @@ -121,6 +122,10 @@ public class ViewUtil { return (T) parent.findViewById(resId); } + public static Stub findStubById(@NonNull Activity parent, @IdRes int resId) { + return new Stub((ViewStub)parent.findViewById(resId)); + } + private static Animation getAlphaAnimation(float from, float to, int duration) { final Animation anim = new AlphaAnimation(from, to); anim.setInterpolator(new FastOutSlowInInterpolator());