From 33ec122a94ad08e35da5dc5741e1adc15f491800 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 3 Jan 2021 20:29:13 +0900 Subject: [PATCH] Move almost all dimens to parent class --- .../DirectItemAnimatedMediaViewHolder.java | 11 ++------ .../DirectItemLinkViewHolder.java | 5 +--- .../DirectItemMediaShareViewHolder.java | 15 ++--------- .../DirectItemMediaViewHolder.java | 13 ++-------- .../DirectItemProfileViewHolder.java | 1 - .../DirectItemRavenMediaViewHolder.java | 13 ++-------- .../DirectItemReelShareViewHolder.java | 12 ++------- .../DirectItemStoryShareViewHolder.java | 15 ++--------- .../DirectItemTextViewHolder.java | 9 ------- .../directmessages/DirectItemViewHolder.java | 25 +++++++++++-------- .../DirectItemVoiceMediaViewHolder.java | 4 +-- app/src/main/res/values/dimens.xml | 4 ++- 12 files changed, 31 insertions(+), 96 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemAnimatedMediaViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemAnimatedMediaViewHolder.java index 201d2a98..c4744ce6 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemAnimatedMediaViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemAnimatedMediaViewHolder.java @@ -8,7 +8,6 @@ import androidx.core.util.Pair; import com.facebook.drawee.backends.pipeline.Fresco; -import awais.instagrabber.R; import awais.instagrabber.databinding.LayoutDmAnimatedMediaBinding; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.interfaces.MentionClickListener; @@ -19,13 +18,10 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItemAnimatedMedia; import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.NumberUtils; -import awais.instagrabber.utils.Utils; public class DirectItemAnimatedMediaViewHolder extends DirectItemViewHolder { private final LayoutDmAnimatedMediaBinding binding; - private final int maxHeight; - private final int maxWidth; public DirectItemAnimatedMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmAnimatedMediaBinding binding, @@ -35,9 +31,6 @@ public class DirectItemAnimatedMediaViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height); - final int margin = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_item_margin); - maxWidth = Utils.displayMetrics.widthPixels - margin; setItemView(binding.getRoot()); } @@ -53,8 +46,8 @@ public class DirectItemAnimatedMediaViewHolder extends DirectItemViewHolder { final Pair widthHeight = NumberUtils.calculateWidthHeight( fixedHeight.getHeight(), fixedHeight.getWidth(), - maxHeight, - maxWidth + mediaImageMaxHeight, + mediaImageMaxWidth ); binding.ivAnimatedMessage.setVisibility(View.VISIBLE); final ViewGroup.LayoutParams layoutParams = binding.ivAnimatedMessage.getLayoutParams(); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java index 8018dc12..b2f1df0f 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java @@ -5,7 +5,6 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; -import awais.instagrabber.R; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmLinkBinding; import awais.instagrabber.interfaces.MentionClickListener; @@ -15,7 +14,6 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItemLink; import awais.instagrabber.repositories.responses.directmessages.DirectItemLinkContext; import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.TextUtils; -import awais.instagrabber.utils.Utils; public class DirectItemLinkViewHolder extends DirectItemViewHolder { @@ -29,8 +27,7 @@ public class DirectItemLinkViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - final int margin = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_item_margin); - final int width = Utils.displayMetrics.widthPixels - margin - Utils.convertDpToPx(8); + final int width = windowWidth - margin - dmRadiusSmall; final ViewGroup.LayoutParams layoutParams = binding.preview.getLayoutParams(); layoutParams.width = width; binding.preview.requestLayout(); 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 9f34f9d5..dc770618 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 @@ -1,6 +1,5 @@ package awais.instagrabber.adapters.viewholder.directmessages; -import android.content.res.Resources; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; @@ -29,16 +28,11 @@ import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectUser; import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.ResponseBodyUtils; -import awais.instagrabber.utils.Utils; public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { private final LayoutDmMediaShareBinding binding; - private final int maxHeight; private final int maxWidth; - private final int dmRadius; - private final int dmRadiusSmall; - // private final RoundingParams roundingParams; public DirectItemMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmMediaShareBinding binding, @@ -48,12 +42,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - final Resources resources = itemView.getResources(); - maxHeight = resources.getDimensionPixelSize(R.dimen.dm_media_img_max_height); - final int margin = resources.getDimensionPixelSize(R.dimen.dm_message_item_margin); - maxWidth = Utils.displayMetrics.widthPixels - margin - Utils.convertDpToPx(8); - dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius); - dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small); + maxWidth = windowWidth - margin - dmRadiusSmall; setItemView(binding.getRoot()); } @@ -117,7 +106,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder { final Pair widthHeight = NumberUtils.calculateWidthHeight( media.getOriginalHeight(), media.getOriginalWidth(), - maxHeight, + mediaImageMaxHeight, maxWidth ); final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams(); 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 c3dfa666..6d8ea536 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 @@ -1,6 +1,5 @@ package awais.instagrabber.adapters.viewholder.directmessages; -import android.content.res.Resources; import android.view.View; import android.view.ViewGroup; @@ -11,7 +10,6 @@ import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; -import awais.instagrabber.R; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmMediaBinding; import awais.instagrabber.interfaces.MentionClickListener; @@ -23,12 +21,10 @@ import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.ImageVersions2; import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.ResponseBodyUtils; -import awais.instagrabber.utils.Utils; public class DirectItemMediaViewHolder extends DirectItemViewHolder { private final LayoutDmMediaBinding binding; - private final int maxHeight; private final int maxWidth; private final RoundingParams incomingRoundingParams; private final RoundingParams outgoingRoundingParams; @@ -41,12 +37,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - final Resources resources = itemView.getResources(); - maxHeight = resources.getDimensionPixelSize(R.dimen.dm_media_img_max_height); - final int margin = resources.getDimensionPixelSize(R.dimen.dm_message_item_margin); - maxWidth = Utils.displayMetrics.widthPixels - margin - Utils.convertDpToPx(8); - final int dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius); - final int dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small); + maxWidth = windowWidth - margin - dmRadiusSmall; incomingRoundingParams = RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius); outgoingRoundingParams = RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius); setItemView(binding.getRoot()); @@ -67,7 +58,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder { final Pair widthHeight = NumberUtils.calculateWidthHeight( media.getOriginalHeight(), media.getOriginalWidth(), - maxHeight, + mediaImageMaxHeight, maxWidth ); final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams(); 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 e29b8837..abe9182f 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 @@ -49,7 +49,6 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder { binding.preview6 ); final Resources resources = itemView.getResources(); - final int dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius); binding.preview4.setHierarchy(new GenericDraweeHierarchyBuilder(resources) .setRoundingParams(RoundingParams.fromCornersRadii(0, 0, 0, dmRadius)) .build()); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java index f150a515..5df62cc9 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java @@ -11,7 +11,6 @@ import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; -import awais.instagrabber.R; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmRavenMediaBinding; import awais.instagrabber.interfaces.MentionClickListener; @@ -25,15 +24,11 @@ import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.ImageVersions2; import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.ResponseBodyUtils; -import awais.instagrabber.utils.Utils; public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder { private final LayoutDmRavenMediaBinding binding; - private final int maxHeight; private final int maxWidth; - private final int dmRadius; - private final int dmRadiusSmall; public DirectItemRavenMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmRavenMediaBinding binding, @@ -44,11 +39,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; final Resources resources = itemView.getResources(); - maxHeight = resources.getDimensionPixelSize(R.dimen.dm_media_img_max_height); - final int margin = resources.getDimensionPixelSize(R.dimen.dm_message_item_margin); - maxWidth = Utils.displayMetrics.widthPixels - margin - Utils.convertDpToPx(8); - dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius); - dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small); + maxWidth = windowWidth - margin - dmRadiusSmall; setItemView(binding.getRoot()); } @@ -182,7 +173,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder { final Pair widthHeight = NumberUtils.calculateWidthHeight( media.getOriginalHeight(), media.getOriginalWidth(), - maxHeight, + mediaImageMaxHeight, maxWidth ); final ViewGroup.LayoutParams layoutParams = binding.preview.getLayoutParams(); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java index 62fa1c2c..f0faf3c3 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java @@ -23,15 +23,10 @@ import awais.instagrabber.repositories.responses.directmessages.DirectUser; import awais.instagrabber.repositories.responses.directmessages.ImageVersions2; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.TextUtils; -import awais.instagrabber.utils.Utils; public class DirectItemReelShareViewHolder extends DirectItemViewHolder { private final LayoutDmReelShareBinding binding; - // private final int maxHeight; - // private final int maxWidth; - private final int dmRadiusSmall; - private final int messageMargin; public DirectItemReelShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmReelShareBinding binding, @@ -41,9 +36,6 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - dmRadiusSmall = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_card_radius_small); - // binding.tvMessage.setMentionClickListener(mentionClickListener); - messageMargin = Utils.convertDpToPx(4); setItemView(binding.getRoot()); } @@ -97,8 +89,8 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { final ConstraintLayout.LayoutParams messageLayoutParams = (ConstraintLayout.LayoutParams) binding.message.getLayoutParams(); messageLayoutParams.startToStart = isIncoming ? ConstraintLayout.LayoutParams.PARENT_ID : ConstraintLayout.LayoutParams.UNSET; messageLayoutParams.endToEnd = isIncoming ? ConstraintLayout.LayoutParams.UNSET : ConstraintLayout.LayoutParams.PARENT_ID; - messageLayoutParams.setMarginStart(isIncoming ? messageMargin : 0); - messageLayoutParams.setMarginEnd(isIncoming ? 0 : messageMargin); + messageLayoutParams.setMarginStart(isIncoming ? messageInfoPaddingSmall : 0); + messageLayoutParams.setMarginEnd(isIncoming ? 0 : messageInfoPaddingSmall); final ConstraintLayout.LayoutParams reactionLayoutParams = (ConstraintLayout.LayoutParams) binding.reaction.getLayoutParams(); final int previewId = binding.preview.getId(); if (isIncoming) { 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 5ab88afd..89f63239 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 @@ -1,6 +1,5 @@ package awais.instagrabber.adapters.viewholder.directmessages; -import android.content.res.Resources; import android.view.View; import android.view.ViewGroup; @@ -11,7 +10,6 @@ import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.RoundingParams; -import awais.instagrabber.R; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmStoryShareBinding; import awais.instagrabber.interfaces.MentionClickListener; @@ -25,15 +23,11 @@ import awais.instagrabber.repositories.responses.directmessages.ImageVersions2; import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.TextUtils; -import awais.instagrabber.utils.Utils; public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { private final LayoutDmStoryShareBinding binding; - private final int maxHeight; private final int maxWidth; - private final int dmRadius; - private final int dmRadiusSmall; public DirectItemStoryShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, @NonNull final LayoutDmStoryShareBinding binding, @@ -43,12 +37,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { final View.OnClickListener onClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height); - final Resources resources = itemView.getResources(); - final int margin = resources.getDimensionPixelSize(R.dimen.dm_message_item_margin); - maxWidth = Utils.displayMetrics.widthPixels - margin - Utils.convertDpToPx(8); - dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius); - dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small); + maxWidth = windowWidth - margin - dmRadiusSmall; setItemView(binding.getRoot()); } @@ -89,7 +78,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder { final Pair widthHeight = NumberUtils.calculateWidthHeight( storyShareMedia.getOriginalHeight(), storyShareMedia.getOriginalWidth(), - maxHeight, + mediaImageMaxHeight, maxWidth ); final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams(); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java index 0c2c8462..75473e8a 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java @@ -23,22 +23,13 @@ public class DirectItemTextViewHolder extends DirectItemViewHolder { final MentionClickListener mentionClickListener) { super(baseBinding, currentUser, thread, onClickListener); this.binding = binding; - // this.binding.tvMessage.setMentionClickListener(mentionClickListener); setItemView(binding.getRoot()); } @Override public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) { - // final Context context = itemView.getContext(); final String text = directItemModel.getText(); if (text == null) return; binding.tvMessage.setText(text); - // text = TextUtils.getSpannableUrl(text.toString()); // for urls - // if (TextUtils.hasMentions(text)) text = TextUtils.getMentionText(text); // for mentions - // if (text instanceof Spanned) - // binding.tvMessage.setText(text, TextView.BufferType.SPANNABLE); - // else if (text == "") { - // binding.tvMessage.setText(context.getText(R.string.dms_inbox_raven_message_unknown)); - // } else binding.tvMessage.setText(text); } } 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 efffd226..de80a758 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,7 +4,6 @@ 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; @@ -31,7 +30,6 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItemReacti import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectUser; import awais.instagrabber.utils.ResponseBodyUtils; -import awais.instagrabber.utils.Utils; public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { private static final String TAG = DirectItemViewHolder.class.getSimpleName(); @@ -39,12 +37,15 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { private final LayoutDmBaseBinding binding; private final DirectUser currentUser; private final DirectThread thread; - private final int margin; - private final int dmRadius; - private final int messageInfoPaddingSmall; - private final int dmRadiusSmall; + protected final int margin; + protected final int dmRadius; + protected final int dmRadiusSmall; + protected final int messageInfoPaddingSmall; private final int groupMessageWidth; private final List userIds; + protected final int mediaImageMaxHeight; + protected final int windowWidth; + protected final int mediaImageMaxWidth; public DirectItemViewHolder(@NonNull final LayoutDmBaseBinding binding, @NonNull final ProfileModel currentUser, @@ -61,15 +62,17 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { binding.ivProfilePic.setVisibility(thread.isGroup() ? View.VISIBLE : View.GONE); 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(); + margin = resources.getDimensionPixelSize(R.dimen.dm_message_item_margin); + final int avatarSize = resources.getDimensionPixelSize(R.dimen.dm_message_item_avatar_size); 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 = 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; // messageInfoPaddingSmall is used cuz it's also 4dp, 1 avatar margin + 2 paddings = 3 - groupMessageWidth = displayMetrics.widthPixels - margin - avatarSize - messageInfoPaddingSmall * 3; + groupMessageWidth = windowWidth - margin - avatarSize - messageInfoPaddingSmall * 3; } public void bind(final DirectItem item) { diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVoiceMediaViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVoiceMediaViewHolder.java index ab2b88e3..49e73a0d 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVoiceMediaViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVoiceMediaViewHolder.java @@ -1,7 +1,6 @@ package awais.instagrabber.adapters.viewholder.directmessages; import android.os.Handler; -import android.os.Looper; import android.util.Log; import android.view.View; @@ -52,8 +51,7 @@ public class DirectItemVoiceMediaViewHolder extends DirectItemViewHolder { this.binding = binding; this.dataSourceFactory = new DefaultDataSourceFactory(binding.getRoot().getContext(), "instagram"); setItemView(binding.getRoot()); - final int margin = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_item_margin); - binding.waveformSeekBar.getLayoutParams().width = Utils.displayMetrics.widthPixels - margin - Utils.convertDpToPx(56); + binding.waveformSeekBar.getLayoutParams().width = windowWidth - margin - Utils.convertDpToPx(56); } @Override diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 6467148d..303acf3d 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -29,7 +29,9 @@ 150dp 16dp 8dp - 120dp + 80dp + 48dp + 4dp 32dp 200dp