ViewStub for ReminderView, lazy create AttachmentTypeSelector

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-01-18 18:46:40 -08:00
parent 3d6cbdd775
commit 508a666e76
5 changed files with 32 additions and 12 deletions

View File

@ -23,8 +23,10 @@
android:clipToPadding="false" android:clipToPadding="false"
android:clipChildren="false"> android:clipChildren="false">
<org.thoughtcrime.securesms.components.reminder.ReminderView <ViewStub
android:id="@+id/reminder" android:id="@+id/reminder_stub"
android:layout="@layout/conversation_activity_reminderview_stub"
android:inflatedId="@+id/reminder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.components.reminder.ReminderView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/reminder"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@ -55,6 +55,7 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener; import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener; import android.view.View.OnKeyListener;
import android.view.ViewStub;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; 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.AssertedSuccessListener;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.concurrent.SettableFuture; import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
import org.thoughtcrime.securesms.util.views.Stub;
import org.whispersystems.libsignal.InvalidMessageException; import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
@ -205,7 +207,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private Button makeDefaultSmsButton; private Button makeDefaultSmsButton;
private InputAwareLayout container; private InputAwareLayout container;
private View composePanel; private View composePanel;
protected ReminderView reminderView; protected Stub<ReminderView> reminderView;
private AttachmentTypeSelector attachmentTypeSelector; private AttachmentTypeSelector attachmentTypeSelector;
private AttachmentManager attachmentManager; private AttachmentManager attachmentManager;
@ -782,6 +784,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private void handleAddAttachment() { private void handleAddAttachment() {
if (this.isMmsEnabled || isSecureText) { if (this.isMmsEnabled || isSecureText) {
if (attachmentTypeSelector == null) {
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener());
}
attachmentTypeSelector.show(this, attachButton); attachmentTypeSelector.show(this, attachButton);
} else { } else {
handleManualMmsRequired(); handleManualMmsRequired();
@ -947,12 +952,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override @Override
public void onClick(View v) { public void onClick(View v) {
handleInviteLink(); handleInviteLink();
reminderView.requestDismiss(); reminderView.get().requestDismiss();
} }
}); });
reminderView.showReminder(reminder); reminderView.get().showReminder(reminder);
} else { } else if (reminderView.resolved()) {
reminderView.hide(); reminderView.get().hide();
} }
} }
@ -987,7 +992,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button); makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button);
composePanel = ViewUtil.findById(this, R.id.bottom_panel); composePanel = ViewUtil.findById(this, R.id.bottom_panel);
container = ViewUtil.findById(this, R.id.layout_container); 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); quickAttachmentDrawer = ViewUtil.findById(this, R.id.quick_attachment_drawer);
quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle); quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle);
inputPanel = ViewUtil.findById(this, R.id.bottom_panel); inputPanel = ViewUtil.findById(this, R.id.bottom_panel);
@ -1005,7 +1010,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
composeBubble.getBackground().setColorFilter(defaultColor, PorterDuff.Mode.MULTIPLY); composeBubble.getBackground().setColorFilter(defaultColor, PorterDuff.Mode.MULTIPLY);
colors.recycle(); colors.recycle();
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener()); attachmentTypeSelector = null;
attachmentManager = new AttachmentManager(this, this); attachmentManager = new AttachmentManager(this, this);
audioRecorder = new AudioRecorder(this, masterSecret); audioRecorder = new AudioRecorder(this, masterSecret);

View File

@ -122,6 +122,8 @@ public class ConversationPopupActivity extends ConversationActivity {
@Override @Override
protected void updateInviteReminder(boolean seenInvite) { protected void updateInviteReminder(boolean seenInvite) {
reminderView.setVisibility(View.GONE); if (reminderView.resolved()) {
reminderView.get().setVisibility(View.GONE);
}
} }
} }

View File

@ -42,6 +42,7 @@ import android.widget.TextView;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.concurrent.SettableFuture; import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
import org.thoughtcrime.securesms.util.views.Stub;
public class ViewUtil { public class ViewUtil {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -121,6 +122,10 @@ public class ViewUtil {
return (T) parent.findViewById(resId); return (T) parent.findViewById(resId);
} }
public static <T extends View> Stub<T> findStubById(@NonNull Activity parent, @IdRes int resId) {
return new Stub<T>((ViewStub)parent.findViewById(resId));
}
private static Animation getAlphaAnimation(float from, float to, int duration) { private static Animation getAlphaAnimation(float from, float to, int duration) {
final Animation anim = new AlphaAnimation(from, to); final Animation anim = new AlphaAnimation(from, to);
anim.setInterpolator(new FastOutSlowInInterpolator()); anim.setInterpolator(new FastOutSlowInInterpolator());