Fix attachment type selector

This commit is contained in:
Niels Andriesse 2020-01-13 10:11:20 +11:00
parent c05c1eecd8
commit b75a15a063
4 changed files with 30 additions and 17 deletions

View file

@ -12,9 +12,11 @@
android:background="@drawable/attachment_selector_shadow"/>
<LinearLayout
android:id="@+id/contentView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="?attachment_type_selector_background">
<org.thoughtcrime.securesms.components.RecentPhotoViewRail

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/default_session_background">

View file

@ -26,10 +26,11 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import network.loki.messenger.R;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.util.ViewUtil;
import network.loki.messenger.R;
public class AttachmentTypeSelector extends PopupWindow {
public static final int ADD_GALLERY = 1;
@ -59,7 +60,7 @@ public class AttachmentTypeSelector extends PopupWindow {
private @Nullable View currentAnchor;
private @Nullable AttachmentClickedListener listener;
public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener) {
public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener, int keyboardHeight) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@ -96,6 +97,14 @@ public class AttachmentTypeSelector extends PopupWindow {
setFocusable(true);
setTouchable(true);
int thresholdInDP = 200;
float scale = context.getResources().getDisplayMetrics().density;
int thresholdInPX = (int)(thresholdInDP * scale);
View contentView = ViewUtil.findById(layout, R.id.contentView);
LinearLayout.LayoutParams contentViewLayoutParams = (LinearLayout.LayoutParams)contentView.getLayoutParams();
contentViewLayoutParams.height = keyboardHeight > thresholdInPX ? keyboardHeight : LinearLayout.LayoutParams.WRAP_CONTENT;
contentView.setLayoutParams(contentViewLayoutParams);
loaderManager.initLoader(1, null, recentRail);
}

View file

@ -223,7 +223,6 @@ import org.whispersystems.signalservice.loki.api.LokiStorageAPI;
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus;
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
import org.whispersystems.signalservice.loki.messaging.Mention;
import org.whispersystems.signalservice.loki.utilities.Analytics;
import java.io.IOException;
import java.text.SimpleDateFormat;
@ -330,9 +329,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private int distributionType;
private boolean archived;
private boolean isSecureText;
private boolean isDefaultSms = true;
private boolean isMmsEnabled = true;
private boolean isSecurityInitialized = false;
private boolean isDefaultSms = true;
private boolean isMmsEnabled = true;
private boolean isSecurityInitialized = false;
private int expandedKeyboardHeight = 0;
private int collapsedKeyboardHeight = Integer.MAX_VALUE;
private int keyboardHeight = 0;
private final IdentityRecordList identityRecords = new IdentityRecordList();
private final DynamicNoActionBarTheme dynamicTheme = new DynamicNoActionBarTheme();
@ -416,15 +418,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
LokiAPIUtilities.INSTANCE.populateUserHexEncodedPublicKeyCacheIfNeeded(threadId, this);
if (this.recipient.isGroupRecipient()) {
if (this.recipient.getName().equals("Loki Public Chat")) {
Analytics.Companion.getShared().track("Loki Public Chat Opened");
} else {
Analytics.Companion.getShared().track("RSS Feed Opened");
}
} else {
Analytics.Companion.getShared().track("Conversation Opened");
}
View rootView = findViewById(R.id.rootView);
rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
int height = rootView.getRootView().getHeight() - rootView.getHeight();
expandedKeyboardHeight = Math.max(expandedKeyboardHeight, height);
collapsedKeyboardHeight = Math.min(collapsedKeyboardHeight, height);
keyboardHeight = Math.max(expandedKeyboardHeight - collapsedKeyboardHeight, keyboardHeight);
});
}
@Override
@ -1173,7 +1173,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private void handleAddAttachment() {
if (this.isMmsEnabled || isSecureText) {
if (attachmentTypeSelector == null) {
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener());
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener(), keyboardHeight);
}
attachmentTypeSelector.show(this, attachButton);
} else {