mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Merge pull request #1112 from mpretty-cyro/fix/link-preview-layout-issues
Fixed a few layout issues with the LinkPreviewView
This commit is contained in:
commit
5bd188387b
@ -4,30 +4,48 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import com.bumptech.glide.request.target.BitmapImageViewTarget;
|
import com.bumptech.glide.request.target.BitmapImageViewTarget;
|
||||||
|
|
||||||
import org.session.libsignal.utilities.SettableFuture;
|
import org.session.libsignal.utilities.SettableFuture;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public class GlideBitmapListeningTarget extends BitmapImageViewTarget {
|
public class GlideBitmapListeningTarget extends BitmapImageViewTarget {
|
||||||
|
|
||||||
private final SettableFuture<Boolean> loaded;
|
private final SettableFuture<Boolean> loaded;
|
||||||
|
private final WeakReference<View> loadingView;
|
||||||
|
|
||||||
public GlideBitmapListeningTarget(@NonNull ImageView view, @NonNull SettableFuture<Boolean> loaded) {
|
public GlideBitmapListeningTarget(@NonNull ImageView view, @Nullable View loadingView, @NonNull SettableFuture<Boolean> loaded) {
|
||||||
super(view);
|
super(view);
|
||||||
this.loaded = loaded;
|
this.loaded = loaded;
|
||||||
|
this.loadingView = new WeakReference<View>(loadingView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setResource(@Nullable Bitmap resource) {
|
protected void setResource(@Nullable Bitmap resource) {
|
||||||
super.setResource(resource);
|
super.setResource(resource);
|
||||||
loaded.set(true);
|
loaded.set(true);
|
||||||
|
|
||||||
|
View loadingViewInstance = loadingView.get();
|
||||||
|
|
||||||
|
if (loadingViewInstance != null) {
|
||||||
|
loadingViewInstance.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||||
super.onLoadFailed(errorDrawable);
|
super.onLoadFailed(errorDrawable);
|
||||||
loaded.set(true);
|
loaded.set(true);
|
||||||
|
|
||||||
|
View loadingViewInstance = loadingView.get();
|
||||||
|
|
||||||
|
if (loadingViewInstance != null) {
|
||||||
|
loadingViewInstance.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,48 @@ package org.thoughtcrime.securesms.components;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import com.bumptech.glide.request.target.DrawableImageViewTarget;
|
import com.bumptech.glide.request.target.DrawableImageViewTarget;
|
||||||
|
|
||||||
import org.session.libsignal.utilities.SettableFuture;
|
import org.session.libsignal.utilities.SettableFuture;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public class GlideDrawableListeningTarget extends DrawableImageViewTarget {
|
public class GlideDrawableListeningTarget extends DrawableImageViewTarget {
|
||||||
|
|
||||||
private final SettableFuture<Boolean> loaded;
|
private final SettableFuture<Boolean> loaded;
|
||||||
|
private final WeakReference<View> loadingView;
|
||||||
|
|
||||||
public GlideDrawableListeningTarget(@NonNull ImageView view, @NonNull SettableFuture<Boolean> loaded) {
|
public GlideDrawableListeningTarget(@NonNull ImageView view, @Nullable View loadingView, @NonNull SettableFuture<Boolean> loaded) {
|
||||||
super(view);
|
super(view);
|
||||||
this.loaded = loaded;
|
this.loaded = loaded;
|
||||||
|
this.loadingView = new WeakReference<View>(loadingView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setResource(@Nullable Drawable resource) {
|
protected void setResource(@Nullable Drawable resource) {
|
||||||
super.setResource(resource);
|
super.setResource(resource);
|
||||||
loaded.set(true);
|
loaded.set(true);
|
||||||
|
|
||||||
|
View loadingViewInstance = loadingView.get();
|
||||||
|
|
||||||
|
if (loadingViewInstance != null) {
|
||||||
|
loadingViewInstance.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||||
super.onLoadFailed(errorDrawable);
|
super.onLoadFailed(errorDrawable);
|
||||||
loaded.set(true);
|
loaded.set(true);
|
||||||
|
|
||||||
|
View loadingViewInstance = loadingView.get();
|
||||||
|
|
||||||
|
if (loadingViewInstance != null) {
|
||||||
|
loadingViewInstance.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,12 @@ class LinkPreviewView : LinearLayout {
|
|||||||
val cornerRadii = MessageBubbleUtilities.calculateRadii(context, isStartOfMessageCluster, isEndOfMessageCluster, message.isOutgoing)
|
val cornerRadii = MessageBubbleUtilities.calculateRadii(context, isStartOfMessageCluster, isEndOfMessageCluster, message.isOutgoing)
|
||||||
cornerMask.setTopLeftRadius(cornerRadii[0])
|
cornerMask.setTopLeftRadius(cornerRadii[0])
|
||||||
cornerMask.setTopRightRadius(cornerRadii[1])
|
cornerMask.setTopRightRadius(cornerRadii[1])
|
||||||
cornerMask.setBottomRightRadius(cornerRadii[2])
|
|
||||||
cornerMask.setBottomLeftRadius(cornerRadii[3])
|
// Only round the bottom corners if there is no body text
|
||||||
|
if (message.body.isEmpty()) {
|
||||||
|
cornerMask.setBottomRightRadius(cornerRadii[2])
|
||||||
|
cornerMask.setBottomLeftRadius(cornerRadii[3])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispatchDraw(canvas: Canvas) {
|
override fun dispatchDraw(canvas: Canvas) {
|
||||||
|
@ -158,7 +158,9 @@ class VisibleMessageContentView : ConstraintLayout {
|
|||||||
message is MmsMessageRecord && message.linkPreviews.isNotEmpty() -> {
|
message is MmsMessageRecord && message.linkPreviews.isNotEmpty() -> {
|
||||||
binding.linkPreviewView.root.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster)
|
binding.linkPreviewView.root.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||||
onContentClick.add { event -> binding.linkPreviewView.root.calculateHit(event) }
|
onContentClick.add { event -> binding.linkPreviewView.root.calculateHit(event) }
|
||||||
// Body text view is inside the link preview for layout convenience
|
|
||||||
|
// When in a link preview ensure the bodyTextView can expand to the full width
|
||||||
|
binding.bodyTextView.maxWidth = binding.linkPreviewView.root.layoutParams.width
|
||||||
}
|
}
|
||||||
message is MmsMessageRecord && message.slideDeck.audioSlide != null -> {
|
message is MmsMessageRecord && message.slideDeck.audioSlide != null -> {
|
||||||
hideBody = true
|
hideBody = true
|
||||||
|
@ -123,12 +123,13 @@ open class ThumbnailView: FrameLayout {
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
slide.thumbnailUri != null -> {
|
slide.thumbnailUri != null -> {
|
||||||
buildThumbnailGlideRequest(glide, slide).into(GlideDrawableListeningTarget(binding.thumbnailImage, result))
|
buildThumbnailGlideRequest(glide, slide).into(GlideDrawableListeningTarget(binding.thumbnailImage, binding.thumbnailLoadIndicator, result))
|
||||||
}
|
}
|
||||||
slide.hasPlaceholder() -> {
|
slide.hasPlaceholder() -> {
|
||||||
buildPlaceholderGlideRequest(glide, slide).into(GlideBitmapListeningTarget(binding.thumbnailImage, result))
|
buildPlaceholderGlideRequest(glide, slide).into(GlideBitmapListeningTarget(binding.thumbnailImage, binding.thumbnailLoadIndicator, result))
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
binding.thumbnailLoadIndicator.isVisible = false
|
||||||
glide.clear(binding.thumbnailImage)
|
glide.clear(binding.thumbnailImage)
|
||||||
result.set(false)
|
result.set(false)
|
||||||
}
|
}
|
||||||
@ -190,7 +191,7 @@ open class ThumbnailView: FrameLayout {
|
|||||||
request.transforms(CenterCrop())
|
request.transforms(CenterCrop())
|
||||||
}
|
}
|
||||||
|
|
||||||
request.into(GlideDrawableListeningTarget(binding.thumbnailImage, future))
|
request.into(GlideDrawableListeningTarget(binding.thumbnailImage, binding.thumbnailLoadIndicator, future))
|
||||||
|
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:id="@+id/linkPreviewView"
|
android:id="@+id/linkPreviewView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="300dp"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Barrier
|
<androidx.constraintlayout.widget.Barrier
|
||||||
|
Loading…
Reference in New Issue
Block a user