diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.java index 82eceffa61..20462bef34 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.java @@ -81,6 +81,8 @@ public final class ConversationReactionOverlay extends FrameLayout { private View dropdownAnchor; private LinearLayout conversationItem; + private View conversationBubble; + private TextView conversationTimestamp; private View backgroundView; private ConstraintLayout foregroundView; private EmojiImageView[] emojiViews; @@ -116,6 +118,8 @@ public final class ConversationReactionOverlay extends FrameLayout { dropdownAnchor = findViewById(R.id.dropdown_anchor); conversationItem = findViewById(R.id.conversation_item); + conversationBubble = conversationItem.findViewById(R.id.conversation_item_bubble); + conversationTimestamp = conversationItem.findViewById(R.id.conversation_item_timestamp); backgroundView = findViewById(R.id.conversation_reaction_scrubber_background); foregroundView = findViewById(R.id.conversation_reaction_scrubber_foreground); @@ -165,10 +169,8 @@ public final class ConversationReactionOverlay extends FrameLayout { Bitmap conversationItemSnapshot = selectedConversationModel.getBitmap(); - View conversationBubble = conversationItem.findViewById(R.id.conversation_item_bubble); conversationBubble.setLayoutParams(new LinearLayout.LayoutParams(conversationItemSnapshot.getWidth(), conversationItemSnapshot.getHeight())); conversationBubble.setBackground(new BitmapDrawable(getResources(), conversationItemSnapshot)); - TextView conversationTimestamp = conversationItem.findViewById(R.id.conversation_item_timestamp); conversationTimestamp.setText(DateUtils.getDisplayFormattedTimeSpanString(getContext(), Locale.getDefault(), messageRecord.getTimestamp())); updateConversationTimestamp(messageRecord); @@ -190,12 +192,8 @@ public final class ConversationReactionOverlay extends FrameLayout { } private void updateConversationTimestamp(MessageRecord message) { - View bubble = conversationItem.findViewById(R.id.conversation_item_bubble); - View timestamp = conversationItem.findViewById(R.id.conversation_item_timestamp); - conversationItem.removeAllViewsInLayout(); - conversationItem.addView(message.isOutgoing() ? timestamp : bubble); - conversationItem.addView(message.isOutgoing() ? bubble : timestamp); - conversationItem.requestLayout(); + if (message.isOutgoing()) conversationBubble.bringToFront(); + else conversationTimestamp.bringToFront(); } private void showAfterLayout(@NonNull MessageRecord messageRecord, @@ -351,11 +349,14 @@ public final class ConversationReactionOverlay extends FrameLayout { int revealDuration = getContext().getResources().getInteger(R.integer.reaction_scrubber_reveal_duration); + conversationBubble.animate() + .scaleX(endScale) + .scaleY(endScale) + .setDuration(revealDuration); + conversationItem.animate() .x(endX) .y(endY) - .scaleX(endScale) - .scaleY(endScale) .setDuration(revealDuration); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtilities.kt index ffe5e9094f..8345473490 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtilities.kt @@ -8,6 +8,7 @@ import android.content.Context import android.graphics.Bitmap import android.graphics.PointF import android.graphics.Rect +import android.util.Size import android.view.View import androidx.annotation.ColorInt import androidx.annotation.DimenRes @@ -15,6 +16,7 @@ import network.loki.messenger.R import org.session.libsession.utilities.getColorFromAttr import android.view.inputmethod.InputMethodManager import androidx.core.graphics.applyCanvas +import kotlin.math.roundToInt fun View.contains(point: PointF): Boolean { return hitRect.contains(point.x.toInt(), point.y.toInt()) @@ -68,8 +70,23 @@ fun View.hideKeyboard() { imm.hideSoftInputFromWindow(this.windowToken, 0) } -fun View.drawToBitmap(config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap = - Bitmap.createBitmap(width, height, config).applyCanvas { + +fun View.drawToBitmap(config: Bitmap.Config = Bitmap.Config.ARGB_8888, longestWidth: Int = 2000): Bitmap { + val size = Size(measuredWidth, measuredHeight).coerceAtMost(longestWidth) + val scale = size.width / measuredWidth.toFloat() + + return Bitmap.createBitmap(size.width, size.height, config).applyCanvas { + scale(scale, scale) translate(-scrollX.toFloat(), -scrollY.toFloat()) draw(this) } +} + +fun Size.coerceAtMost(longestWidth: Int): Size = + (width.toFloat() / height).let { aspect -> + if (aspect > 1) { + width.coerceAtMost(longestWidth).let { Size(it, (it / aspect).roundToInt()) } + } else { + height.coerceAtMost(longestWidth).let { Size((it * aspect).roundToInt(), it) } + } + }