diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java index a0e606c8..e977622c 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java @@ -4,6 +4,7 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.text.format.DateFormat; +import android.util.DisplayMetrics; import android.view.Gravity; import android.view.View; import android.widget.FrameLayout; @@ -42,6 +43,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { private final int dmRadius; private final int messageInfoPaddingSmall; private final int dmRadiusSmall; + private final int groupMessageWidth; private final List userIds; public DirectItemViewHolder(@NonNull final LayoutDmBaseBinding binding, @@ -60,10 +62,14 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { binding.ivProfilePic.setOnClickListener(thread.isGroup() ? onClickListener : null); // binding.messageCard.setOnClickListener(onClickListener); margin = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_item_margin); + final int avatarSize = Utils.convertDpToPx(48); final Resources resources = itemView.getResources(); dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius); dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small); messageInfoPaddingSmall = Utils.convertDpToPx(4); + DisplayMetrics displayMetrics = itemView.getResources().getDisplayMetrics(); + // messageInfoPaddingSmall is used cuz it's also 4dp, 1 avatar margin + 2 paddings = 3 + groupMessageWidth = displayMetrics.widthPixels - margin - avatarSize - messageInfoPaddingSmall * 3; } public void bind(final DirectItem item) { @@ -86,6 +92,9 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { binding.tvUsername.setText(user.getUsername()); binding.ivProfilePic.setImageURI(user.getProfilePicUrl()); } + ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) binding.chatMessageLayout.getLayoutParams(); + layoutParams.matchConstraintMaxWidth = groupMessageWidth; + binding.chatMessageLayout.setLayoutParams(layoutParams); } } else { binding.ivProfilePic.setVisibility(View.GONE); diff --git a/app/src/main/res/layout/layout_dm_base.xml b/app/src/main/res/layout/layout_dm_base.xml index 2716809f..f6ff6c7d 100644 --- a/app/src/main/res/layout/layout_dm_base.xml +++ b/app/src/main/res/layout/layout_dm_base.xml @@ -123,7 +123,6 @@ app:layout_constraintStart_toEndOf="@id/ivProfilePic" app:layout_constraintTop_toBottomOf="@id/tvUsername" app:layout_constraintWidth_min="wrap" - app:layout_constraintWidth_max="230dp" app:viewPartInfo="@id/message_info" app:viewPartMain="@id/message">