Wider messages for tall images

This commit is contained in:
Hocuri
2020-10-26 17:21:04 +01:00
parent 5990606148
commit df0196a7cf
8 changed files with 62 additions and 31 deletions
+1 -1
View File
@@ -114,7 +114,7 @@
<ViewStub
android:id="@+id/image_view_stub"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout="@layout/conversation_item_received_thumbnail" />
@@ -2,18 +2,12 @@
<org.thoughtcrime.securesms.components.ConversationItemThumbnail
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image_view"
android:layout_width="@dimen/media_bubble_default_dimens"
android:layout_width="match_parent"
android:layout_height="@dimen/media_bubble_default_dimens"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:contentDescription="@string/image"
android:visibility="gone"
android:elevation="8dp"
app:conversationThumbnail_minWidth="@dimen/media_bubble_min_width"
app:conversationThumbnail_maxWidth="@dimen/media_bubble_max_width"
app:conversationThumbnail_minHeight="@dimen/media_bubble_min_height"
app:conversationThumbnail_maxHeight="@dimen/media_bubble_max_height"
tools:src="@drawable/ic_video_light"
tools:visibility="gone" />
+1 -1
View File
@@ -92,7 +92,7 @@
<ViewStub
android:id="@+id/image_view_stub"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout="@layout/conversation_item_sent_thumbnail" />
@@ -2,20 +2,14 @@
<org.thoughtcrime.securesms.components.ConversationItemThumbnail
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image_view"
android:layout_width="@dimen/media_bubble_default_dimens"
android:layout_width="match_parent"
android:layout_height="@dimen/media_bubble_default_dimens"
android:layout_marginBottom="5dp"
android:layout_gravity="center"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:contentDescription="@string/chat_input_placeholder"
android:visibility="gone"
android:elevation="8dp"
app:conversationThumbnail_minWidth="@dimen/media_bubble_min_width"
app:conversationThumbnail_maxWidth="@dimen/media_bubble_max_width"
app:conversationThumbnail_minHeight="@dimen/media_bubble_min_height"
app:conversationThumbnail_maxHeight="@dimen/media_bubble_max_height"
tools:src="@drawable/ic_video_light"
tools:visibility="visible" />
+8 -8
View File
@@ -1,18 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<org.thoughtcrime.securesms.components.ThumbnailView
android:id="@+id/conversation_thumbnail_image"
android:layout_width="@dimen/media_bubble_default_dimens"
android:layout_height="@dimen/media_bubble_default_dimens"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:longClickable="false"
android:scaleType="fitCenter"
android:scaleType="centerCrop"
android:contentDescription="@string/image"
app:thumbnail_radius="1dp"/>
app:thumbnail_radius="1dp" />
<ImageView
android:id="@+id/conversation_thumbnail_shade"
@@ -20,6 +19,7 @@
android:layout_height="48dp"
android:layout_gravity="bottom"
android:visibility="gone"
tools:visibility="visible"
android:src="@drawable/image_shade" />
<org.thoughtcrime.securesms.components.ConversationItemFooter
+1 -2
View File
@@ -8,10 +8,9 @@
android:id="@+id/thumbnail_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:clickable="false"
android:longClickable="false"
android:scaleType="fitCenter"
android:scaleType="centerCrop"
android:contentDescription="@null" />
<FrameLayout
@@ -463,6 +463,7 @@ public class ConversationItem extends LinearLayout
setThumbnailOutlineCorners(messageRecord, isGroupThread);
bodyBubble.getLayoutParams().width = ViewUtil.dpToPx(readDimen(R.dimen.media_bubble_max_width));
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
footer.setVisibility(VISIBLE);
@@ -1,6 +1,8 @@
package org.thoughtcrime.securesms.components;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -8,10 +10,13 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.net.Uri;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -21,6 +26,8 @@ import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideClickListener;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
@@ -53,6 +60,10 @@ public class ConversationItemThumbnail extends FrameLayout {
private ConversationItemFooter footer;
private Paint outlinePaint;
private CornerMask cornerMask;
private int naturalWidth;
private int naturalHeight;
private int minHeight;
private int maxHeight;
public ConversationItemThumbnail(Context context) {
super(context);
@@ -82,14 +93,40 @@ public class ConversationItemThumbnail extends FrameLayout {
if (attrs != null) {
TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ConversationItemThumbnail, 0, 0);
thumbnail.setBounds(typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_minWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_maxWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_minHeight, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_maxHeight, 0));
minHeight = readDimen(R.dimen.media_bubble_min_height);
maxHeight = readDimen(R.dimen.media_bubble_max_height);
// At least allow the image to be as high as half the screen size
// Otherwise on tablets all images would be shown wide, but with a low height
DisplayMetrics dm = new DisplayMetrics();
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
// Screen could be rotated later so that width and height swap, but just take the lower value:
int screenHeight = Math.min(dm.heightPixels, dm.widthPixels);
maxHeight = Math.max(screenHeight / 2, maxHeight);
typedArray.recycle();
}
}
@Override
protected void onMeasure(int originalWidthMeasureSpec, int originalHeightMeasureSpec) {
int width = MeasureSpec.getSize(originalWidthMeasureSpec);
if (naturalWidth == 0 || naturalHeight == 0) {
super.onMeasure(originalWidthMeasureSpec, originalHeightMeasureSpec);
return;
}
// Compute height:
int best = width * naturalHeight / naturalWidth;
int min = ViewUtil.dpToPx(50);
int max = (int) (width * 0.8);
int height = Util.clamp(best, min, max);
int finalHeight = Util.clamp(height, this.minHeight, this.maxHeight);
super.onMeasure(originalWidthMeasureSpec,
MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY));
}
@SuppressWarnings("SuspiciousNameCombination")
@Override
protected void dispatchDraw(Canvas canvas) {
@@ -173,7 +210,9 @@ public class ConversationItemThumbnail extends FrameLayout {
public void setImageResource(@NonNull GlideRequests glideRequests, @NonNull Slide slide,
int naturalWidth, int naturalHeight)
{
refreshSlideAttachmentState(thumbnail.setImageResource(glideRequests, slide, naturalWidth, naturalHeight), slide);
this.naturalWidth = naturalWidth;
this.naturalHeight = naturalHeight;
refreshSlideAttachmentState(thumbnail.setImageResource(glideRequests, slide), slide);
}
@@ -188,4 +227,8 @@ public class ConversationItemThumbnail extends FrameLayout {
public void clear(GlideRequests glideRequests) {
thumbnail.clear(glideRequests);
}
private int readDimen(@DimenRes int dimenId) {
return getResources().getDimensionPixelOffset(dimenId);
}
}