1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 13:26:59 +00:00

Move almost all dimens to parent class

This commit is contained in:
Ammar Githam 2021-01-03 20:29:13 +09:00
parent f1721c37ec
commit 33ec122a94
12 changed files with 31 additions and 96 deletions

View File

@ -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<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
fixedHeight.getHeight(),
fixedHeight.getWidth(),
maxHeight,
maxWidth
mediaImageMaxHeight,
mediaImageMaxWidth
);
binding.ivAnimatedMessage.setVisibility(View.VISIBLE);
final ViewGroup.LayoutParams layoutParams = binding.ivAnimatedMessage.getLayoutParams();

View File

@ -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();

View File

@ -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<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
media.getOriginalHeight(),
media.getOriginalWidth(),
maxHeight,
mediaImageMaxHeight,
maxWidth
);
final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams();

View File

@ -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<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
media.getOriginalHeight(),
media.getOriginalWidth(),
maxHeight,
mediaImageMaxHeight,
maxWidth
);
final ViewGroup.LayoutParams layoutParams = binding.mediaPreview.getLayoutParams();

View File

@ -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());

View File

@ -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<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
media.getOriginalHeight(),
media.getOriginalWidth(),
maxHeight,
mediaImageMaxHeight,
maxWidth
);
final ViewGroup.LayoutParams layoutParams = binding.preview.getLayoutParams();

View File

@ -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) {

View File

@ -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<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight(
storyShareMedia.getOriginalHeight(),
storyShareMedia.getOriginalWidth(),
maxHeight,
mediaImageMaxHeight,
maxWidth
);
final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams();

View File

@ -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);
}
}

View File

@ -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<Long> 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) {

View File

@ -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

View File

@ -29,7 +29,9 @@
<dimen name="dm_link_image_size">150dp</dimen>
<dimen name="dm_message_card_radius">16dp</dimen>
<dimen name="dm_message_card_radius_small">8dp</dimen>
<dimen name="dm_message_item_margin">120dp</dimen>
<dimen name="dm_message_item_margin">80dp</dimen>
<dimen name="dm_message_item_avatar_size">48dp</dimen>
<dimen name="dm_message_info_padding_small">4dp</dimen>
<dimen name="feed_item_bottom_icon_size">32dp</dimen>
<dimen name="keyboard_height">200dp</dimen>