1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-26 08:37:29 +00:00

Fix chat layouts

This commit is contained in:
Ammar Githam 2021-01-03 23:53:16 +09:00
parent 0ec3691cac
commit 788358eb35
8 changed files with 32 additions and 25 deletions

View File

@ -8,7 +8,6 @@ import androidx.annotation.NonNull;
import androidx.core.util.Pair; import androidx.core.util.Pair;
import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.generic.RoundingParams; import com.facebook.drawee.generic.RoundingParams;
@ -33,6 +32,8 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
private final LayoutDmMediaShareBinding binding; private final LayoutDmMediaShareBinding binding;
private final int maxWidth; private final int maxWidth;
private final RoundingParams incomingRoundingParams;
private final RoundingParams outgoingRoundingParams;
public DirectItemMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, public DirectItemMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmMediaShareBinding binding, @NonNull final LayoutDmMediaShareBinding binding,
@ -43,20 +44,18 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding; this.binding = binding;
maxWidth = windowWidth - margin - dmRadiusSmall; maxWidth = windowWidth - margin - dmRadiusSmall;
incomingRoundingParams = RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius);
outgoingRoundingParams = RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius);
setItemView(binding.getRoot()); setItemView(binding.getRoot());
} }
@Override @Override
public void bindItem(final DirectItem item, final MessageDirection messageDirection) { public void bindItem(final DirectItem item, final MessageDirection messageDirection) {
removeBg(); final RoundingParams roundingParams = messageDirection == MessageDirection.INCOMING ? incomingRoundingParams : outgoingRoundingParams;
final RoundingParams roundingParams = messageDirection == MessageDirection.INCOMING binding.mediaPreview.setHierarchy(new GenericDraweeHierarchyBuilder(itemView.getResources())
? RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius) .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
: RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius); .setRoundingParams(roundingParams)
final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(itemView.getResources()) .build());
.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
.setRoundingParams(roundingParams)
.build();
binding.mediaPreview.setHierarchy(hierarchy);
binding.topBg.setBackgroundResource(messageDirection == MessageDirection.INCOMING binding.topBg.setBackgroundResource(messageDirection == MessageDirection.INCOMING
? R.drawable.bg_media_share_top_incoming ? R.drawable.bg_media_share_top_incoming
: R.drawable.bg_media_share_top_outgoing); : R.drawable.bg_media_share_top_outgoing);
@ -107,7 +106,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
media.getOriginalHeight(), media.getOriginalHeight(),
media.getOriginalWidth(), media.getOriginalWidth(),
mediaImageMaxHeight, mediaImageMaxHeight,
maxWidth mediaImageMaxWidth
); );
final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams(); final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams();
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0; layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;

View File

@ -25,7 +25,6 @@ import awais.instagrabber.utils.ResponseBodyUtils;
public class DirectItemMediaViewHolder extends DirectItemViewHolder { public class DirectItemMediaViewHolder extends DirectItemViewHolder {
private final LayoutDmMediaBinding binding; private final LayoutDmMediaBinding binding;
private final int maxWidth;
private final RoundingParams incomingRoundingParams; private final RoundingParams incomingRoundingParams;
private final RoundingParams outgoingRoundingParams; private final RoundingParams outgoingRoundingParams;
@ -37,7 +36,6 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder {
final View.OnClickListener onClickListener) { final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding; this.binding = binding;
maxWidth = windowWidth - margin - dmRadiusSmall;
incomingRoundingParams = RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius); incomingRoundingParams = RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius);
outgoingRoundingParams = RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius); outgoingRoundingParams = RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius);
setItemView(binding.getRoot()); setItemView(binding.getRoot());
@ -59,7 +57,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder {
media.getOriginalHeight(), media.getOriginalHeight(),
media.getOriginalWidth(), media.getOriginalWidth(),
mediaImageMaxHeight, mediaImageMaxHeight,
maxWidth mediaImageMaxWidth
); );
final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams(); final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams();
final int width = widthHeight.first != null ? widthHeight.first : 0; final int width = widthHeight.first != null ? widthHeight.first : 0;

View File

@ -25,6 +25,7 @@ import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.DirectUser; import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.directmessages.ImageVersions2; import awais.instagrabber.repositories.responses.directmessages.ImageVersions2;
import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
public class DirectItemProfileViewHolder extends DirectItemViewHolder { public class DirectItemProfileViewHolder extends DirectItemViewHolder {
@ -60,7 +61,6 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
@Override @Override
public void bindItem(@NonNull final DirectItem item, public void bindItem(@NonNull final DirectItem item,
final MessageDirection messageDirection) { final MessageDirection messageDirection) {
removeBg();
binding.getRoot().setBackgroundResource(messageDirection == MessageDirection.INCOMING binding.getRoot().setBackgroundResource(messageDirection == MessageDirection.INCOMING
? R.drawable.bg_speech_bubble_incoming ? R.drawable.bg_speech_bubble_incoming
: R.drawable.bg_speech_bubble_outgoing); : R.drawable.bg_speech_bubble_outgoing);
@ -108,7 +108,13 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
if (location == null) return; if (location == null) return;
binding.profilePic.setVisibility(View.GONE); binding.profilePic.setVisibility(View.GONE);
binding.username.setText(location.getName()); binding.username.setText(location.getName());
binding.fullName.setText(location.getAddress()); final String address = location.getAddress();
if (!TextUtils.isEmpty(address)) {
binding.fullName.setText(address);
binding.fullName.setVisibility(View.VISIBLE);
} else {
binding.fullName.setVisibility(View.GONE);
}
binding.isVerified.setVisibility(View.GONE); binding.isVerified.setVisibility(View.GONE);
} }
} }

View File

@ -27,7 +27,7 @@ import awais.instagrabber.utils.TextUtils;
public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
private final LayoutDmStoryShareBinding binding; private final LayoutDmStoryShareBinding binding;
private final int maxWidth; // private final int maxWidth;
public DirectItemStoryShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, public DirectItemStoryShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmStoryShareBinding binding, @NonNull final LayoutDmStoryShareBinding binding,
@ -37,13 +37,12 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
final View.OnClickListener onClickListener) { final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding; this.binding = binding;
maxWidth = windowWidth - margin - dmRadiusSmall; // maxWidth = windowWidth - margin - dmRadiusSmall;
setItemView(binding.getRoot()); setItemView(binding.getRoot());
} }
@Override @Override
public void bindItem(final DirectItem item, final MessageDirection messageDirection) { public void bindItem(final DirectItem item, final MessageDirection messageDirection) {
removeBg();
String format = "@%s's story"; String format = "@%s's story";
final String reelType = item.getStoryShare().getReelType(); final String reelType = item.getStoryShare().getReelType();
if (reelType == null || item.getStoryShare().getMedia() == null) { if (reelType == null || item.getStoryShare().getMedia() == null) {
@ -79,7 +78,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
storyShareMedia.getOriginalHeight(), storyShareMedia.getOriginalHeight(),
storyShareMedia.getOriginalWidth(), storyShareMedia.getOriginalWidth(),
mediaImageMaxHeight, mediaImageMaxHeight,
maxWidth mediaImageMaxWidth
); );
final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams(); final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams();
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0; layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;

View File

@ -70,9 +70,10 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
messageInfoPaddingSmall = resources.getDimensionPixelSize(R.dimen.dm_message_info_padding_small); messageInfoPaddingSmall = resources.getDimensionPixelSize(R.dimen.dm_message_info_padding_small);
windowWidth = resources.getDisplayMetrics().widthPixels; windowWidth = resources.getDisplayMetrics().widthPixels;
mediaImageMaxHeight = resources.getDimensionPixelSize(R.dimen.dm_media_img_max_height); mediaImageMaxHeight = resources.getDimensionPixelSize(R.dimen.dm_media_img_max_height);
mediaImageMaxWidth = windowWidth - margin; final int groupWidthCorrection = avatarSize + messageInfoPaddingSmall * 3;
mediaImageMaxWidth = windowWidth - margin - (thread.isGroup() ? groupWidthCorrection : 0);
// messageInfoPaddingSmall is used cuz it's also 4dp, 1 avatar margin + 2 paddings = 3 // messageInfoPaddingSmall is used cuz it's also 4dp, 1 avatar margin + 2 paddings = 3
groupMessageWidth = windowWidth - margin - avatarSize - messageInfoPaddingSmall * 3; groupMessageWidth = windowWidth - margin - groupWidthCorrection;
} }
public void bind(final DirectItem item) { public void bind(final DirectItem item) {
@ -120,7 +121,8 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
messageInfoPaddingSmall, messageInfoPaddingSmall,
dmRadiusSmall); dmRadiusSmall);
} }
if (itemType == DirectItemType.MEDIA) { if (itemType == DirectItemType.MEDIA || itemType == DirectItemType.MEDIA_SHARE || itemType == DirectItemType.CLIP || itemType == DirectItemType.STORY_SHARE
|| itemType == DirectItemType.LOCATION || itemType == DirectItemType.FELIX_SHARE) {
// no background for media items // no background for media items
binding.background.setBackgroundResource(0); binding.background.setBackgroundResource(0);
} }

View File

@ -92,7 +92,7 @@ public class ChatMessageLayout extends FrameLayout {
if (firstChildId == R.id.media_container) { if (firstChildId == R.id.media_container) {
widthSize += viewPartMainWidth; widthSize += viewPartMainWidth;
heightSize += viewPartMainHeight; heightSize += viewPartMainHeight;
} else if (firstChildId == R.id.raven_media_container || firstChildId == R.id.profile_container || firstChildId == R.id.voice_media) { } else if (firstChildId == R.id.raven_media_container || firstChildId == R.id.profile_container || firstChildId == R.id.voice_media || firstChildId == R.id.story_container) {
widthSize += viewPartMainWidth; widthSize += viewPartMainWidth;
heightSize += viewPartMainHeight + viewPartInfoHeight; heightSize += viewPartMainHeight + viewPartInfoHeight;
} else { } else {

View File

@ -17,7 +17,7 @@
app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" /> tools:visibility="gone" />
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/username" android:id="@+id/username"
@ -35,6 +35,7 @@
app:layout_constraintEnd_toStartOf="@id/isVerified" app:layout_constraintEnd_toStartOf="@id/isVerified"
app:layout_constraintStart_toEndOf="@id/profile_pic" app:layout_constraintStart_toEndOf="@id/profile_pic"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginBottom="8dp"
app:layout_goneMarginEnd="8dp" app:layout_goneMarginEnd="8dp"
app:layout_goneMarginStart="8dp" app:layout_goneMarginStart="8dp"
tools:text="Long..long... Long..long... Long..long..." /> tools:text="Long..long... Long..long... Long..long..." />
@ -61,6 +62,7 @@
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/barrier" app:layout_constraintBottom_toTopOf="@id/barrier"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/username" app:layout_constraintStart_toStartOf="@id/username"

View File

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/story_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">