From 788358eb35edd7977e204cdd6fed5918a64838e6 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 3 Jan 2021 23:53:16 +0900 Subject: [PATCH] Fix chat layouts --- .../DirectItemMediaShareViewHolder.java | 21 +++++++++---------- .../DirectItemMediaViewHolder.java | 4 +--- .../DirectItemProfileViewHolder.java | 10 +++++++-- .../DirectItemStoryShareViewHolder.java | 7 +++---- .../directmessages/DirectItemViewHolder.java | 8 ++++--- .../customviews/ChatMessageLayout.java | 2 +- app/src/main/res/layout/layout_dm_profile.xml | 4 +++- .../main/res/layout/layout_dm_story_share.xml | 1 + 8 files changed, 32 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java index dc770618..5c5ab369 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java @@ -8,7 +8,6 @@ import androidx.annotation.NonNull; import androidx.core.util.Pair; import com.facebook.drawee.drawable.ScalingUtils; -import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; @@ -33,6 +32,8 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { private final LayoutDmMediaShareBinding binding; private final int maxWidth; + private final RoundingParams incomingRoundingParams; + private final RoundingParams outgoingRoundingParams; public DirectItemMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmMediaShareBinding binding, @@ -43,20 +44,18 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; maxWidth = windowWidth - margin - dmRadiusSmall; + incomingRoundingParams = RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius); + outgoingRoundingParams = RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius); setItemView(binding.getRoot()); } @Override public void bindItem(final DirectItem item, final MessageDirection messageDirection) { - removeBg(); - final RoundingParams roundingParams = messageDirection == MessageDirection.INCOMING - ? RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius) - : RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius); - final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(itemView.getResources()) - .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) - .setRoundingParams(roundingParams) - .build(); - binding.mediaPreview.setHierarchy(hierarchy); + final RoundingParams roundingParams = messageDirection == MessageDirection.INCOMING ? incomingRoundingParams : outgoingRoundingParams; + binding.mediaPreview.setHierarchy(new GenericDraweeHierarchyBuilder(itemView.getResources()) + .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) + .setRoundingParams(roundingParams) + .build()); binding.topBg.setBackgroundResource(messageDirection == MessageDirection.INCOMING ? R.drawable.bg_media_share_top_incoming : R.drawable.bg_media_share_top_outgoing); @@ -107,7 +106,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { media.getOriginalHeight(), media.getOriginalWidth(), mediaImageMaxHeight, - maxWidth + mediaImageMaxWidth ); final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams(); layoutParams.width = widthHeight.first != null ? widthHeight.first : 0; diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaViewHolder.java index 6d8ea536..b8de49b1 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaViewHolder.java @@ -25,7 +25,6 @@ import awais.instagrabber.utils.ResponseBodyUtils; public class DirectItemMediaViewHolder extends DirectItemViewHolder { private final LayoutDmMediaBinding binding; - private final int maxWidth; private final RoundingParams incomingRoundingParams; private final RoundingParams outgoingRoundingParams; @@ -37,7 +36,6 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - maxWidth = windowWidth - margin - dmRadiusSmall; incomingRoundingParams = RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius); outgoingRoundingParams = RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius); setItemView(binding.getRoot()); @@ -59,7 +57,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder { media.getOriginalHeight(), media.getOriginalWidth(), mediaImageMaxHeight, - maxWidth + mediaImageMaxWidth ); final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams(); final int width = widthHeight.first != null ? widthHeight.first : 0; diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemProfileViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemProfileViewHolder.java index abe9182f..5997a982 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemProfileViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemProfileViewHolder.java @@ -25,6 +25,7 @@ import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectUser; import awais.instagrabber.repositories.responses.directmessages.ImageVersions2; import awais.instagrabber.utils.ResponseBodyUtils; +import awais.instagrabber.utils.TextUtils; public class DirectItemProfileViewHolder extends DirectItemViewHolder { @@ -60,7 +61,6 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder { @Override public void bindItem(@NonNull final DirectItem item, final MessageDirection messageDirection) { - removeBg(); binding.getRoot().setBackgroundResource(messageDirection == MessageDirection.INCOMING ? R.drawable.bg_speech_bubble_incoming : R.drawable.bg_speech_bubble_outgoing); @@ -108,7 +108,13 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder { if (location == null) return; binding.profilePic.setVisibility(View.GONE); 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); } } diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java index 89f63239..d7931c80 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java @@ -27,7 +27,7 @@ import awais.instagrabber.utils.TextUtils; public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { private final LayoutDmStoryShareBinding binding; - private final int maxWidth; + // private final int maxWidth; public DirectItemStoryShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmStoryShareBinding binding, @@ -37,13 +37,12 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - maxWidth = windowWidth - margin - dmRadiusSmall; + // maxWidth = windowWidth - margin - dmRadiusSmall; setItemView(binding.getRoot()); } @Override public void bindItem(final DirectItem item, final MessageDirection messageDirection) { - removeBg(); String format = "@%s's story"; final String reelType = item.getStoryShare().getReelType(); if (reelType == null || item.getStoryShare().getMedia() == null) { @@ -79,7 +78,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { storyShareMedia.getOriginalHeight(), storyShareMedia.getOriginalWidth(), mediaImageMaxHeight, - maxWidth + mediaImageMaxWidth ); final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams(); layoutParams.width = widthHeight.first != null ? widthHeight.first : 0; 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 de80a758..24209134 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 @@ -70,9 +70,10 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { messageInfoPaddingSmall = resources.getDimensionPixelSize(R.dimen.dm_message_info_padding_small); windowWidth = resources.getDisplayMetrics().widthPixels; 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 - groupMessageWidth = windowWidth - margin - avatarSize - messageInfoPaddingSmall * 3; + groupMessageWidth = windowWidth - margin - groupWidthCorrection; } public void bind(final DirectItem item) { @@ -120,7 +121,8 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { messageInfoPaddingSmall, 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 binding.background.setBackgroundResource(0); } diff --git a/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java b/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java index 6e92be08..f18633ab 100644 --- a/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java +++ b/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java @@ -92,7 +92,7 @@ public class ChatMessageLayout extends FrameLayout { if (firstChildId == R.id.media_container) { widthSize += viewPartMainWidth; 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; heightSize += viewPartMainHeight + viewPartInfoHeight; } else { diff --git a/app/src/main/res/layout/layout_dm_profile.xml b/app/src/main/res/layout/layout_dm_profile.xml index b9f17fff..a8e179b5 100644 --- a/app/src/main/res/layout/layout_dm_profile.xml +++ b/app/src/main/res/layout/layout_dm_profile.xml @@ -17,7 +17,7 @@ app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - tools:visibility="visible" /> + tools:visibility="gone" /> @@ -61,6 +62,7 @@ android:ellipsize="end" android:singleLine="true" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" + android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/barrier" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="@id/username" diff --git a/app/src/main/res/layout/layout_dm_story_share.xml b/app/src/main/res/layout/layout_dm_story_share.xml index 04052d78..d71ebcce 100644 --- a/app/src/main/res/layout/layout_dm_story_share.xml +++ b/app/src/main/res/layout/layout_dm_story_share.xml @@ -2,6 +2,7 @@