1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

group message width layout fix (dynamic)

This commit is contained in:
Austin Huang 2021-01-02 22:35:33 -05:00
parent 47e8645dea
commit 8de3021c7f
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with 9 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -42,6 +43,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
private final int dmRadius; private final int dmRadius;
private final int messageInfoPaddingSmall; private final int messageInfoPaddingSmall;
private final int dmRadiusSmall; private final int dmRadiusSmall;
private final int groupMessageWidth;
private final List<Long> userIds; private final List<Long> userIds;
public DirectItemViewHolder(@NonNull final LayoutDmBaseBinding binding, 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.ivProfilePic.setOnClickListener(thread.isGroup() ? onClickListener : null);
// binding.messageCard.setOnClickListener(onClickListener); // binding.messageCard.setOnClickListener(onClickListener);
margin = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_item_margin); margin = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_item_margin);
final int avatarSize = Utils.convertDpToPx(48);
final Resources resources = itemView.getResources(); final Resources resources = itemView.getResources();
dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius); dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius);
dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small); dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small);
messageInfoPaddingSmall = Utils.convertDpToPx(4); 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) { public void bind(final DirectItem item) {
@ -86,6 +92,9 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
binding.tvUsername.setText(user.getUsername()); binding.tvUsername.setText(user.getUsername());
binding.ivProfilePic.setImageURI(user.getProfilePicUrl()); binding.ivProfilePic.setImageURI(user.getProfilePicUrl());
} }
ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) binding.chatMessageLayout.getLayoutParams();
layoutParams.matchConstraintMaxWidth = groupMessageWidth;
binding.chatMessageLayout.setLayoutParams(layoutParams);
} }
} else { } else {
binding.ivProfilePic.setVisibility(View.GONE); binding.ivProfilePic.setVisibility(View.GONE);

View File

@ -123,7 +123,6 @@
app:layout_constraintStart_toEndOf="@id/ivProfilePic" app:layout_constraintStart_toEndOf="@id/ivProfilePic"
app:layout_constraintTop_toBottomOf="@id/tvUsername" app:layout_constraintTop_toBottomOf="@id/tvUsername"
app:layout_constraintWidth_min="wrap" app:layout_constraintWidth_min="wrap"
app:layout_constraintWidth_max="230dp"
app:viewPartInfo="@id/message_info" app:viewPartInfo="@id/message_info"
app:viewPartMain="@id/message"> app:viewPartMain="@id/message">