Browse Source

Organise dm view holders bind logic and fix some views

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
8937918064
  1. 10
      app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java
  2. 10
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemActionLogViewHolder.java
  3. 1
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemAnimatedMediaViewHolder.java
  4. 8
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLikeViewHolder.java
  5. 5
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java
  6. 31
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java
  7. 5
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemPlaceholderViewHolder.java
  8. 2
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemProfileViewHolder.java
  9. 5
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java
  10. 1
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java
  11. 28
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java
  12. 10
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVideoCallEventViewHolder.java
  13. 126
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java
  14. 6
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVoiceMediaViewHolder.java
  15. 3
      app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java
  16. 8
      app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
  17. 4
      app/src/main/res/layout/layout_dm_voice_media.xml

10
app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java

@ -128,11 +128,11 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
switch (directItemType) { switch (directItemType) {
case TEXT: { case TEXT: {
final LayoutDmTextBinding binding = LayoutDmTextBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmTextBinding binding = LayoutDmTextBinding.inflate(layoutInflater, baseBinding.message, false);
return new DirectItemTextViewHolder(baseBinding, binding, currentUser, thread, null, null);
return new DirectItemTextViewHolder(baseBinding, binding, currentUser, thread, null);
} }
case LIKE: { case LIKE: {
final LayoutDmLikeBinding binding = LayoutDmLikeBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmLikeBinding binding = LayoutDmLikeBinding.inflate(layoutInflater, baseBinding.message, false);
return new DirectItemLikeViewHolder(baseBinding, binding, currentUser, thread, null, null);
return new DirectItemLikeViewHolder(baseBinding, binding, currentUser, thread, null);
} }
case LINK: { case LINK: {
final LayoutDmLinkBinding binding = LayoutDmLinkBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmLinkBinding binding = LayoutDmLinkBinding.inflate(layoutInflater, baseBinding.message, false);
@ -156,12 +156,12 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
} }
case VOICE_MEDIA: { case VOICE_MEDIA: {
final LayoutDmVoiceMediaBinding binding = LayoutDmVoiceMediaBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmVoiceMediaBinding binding = LayoutDmVoiceMediaBinding.inflate(layoutInflater, baseBinding.message, false);
return new DirectItemVoiceMediaViewHolder(baseBinding, binding, currentUser, thread, null, null);
return new DirectItemVoiceMediaViewHolder(baseBinding, binding, currentUser, thread, null);
} }
case LOCATION: case LOCATION:
case PROFILE: { case PROFILE: {
final LayoutDmProfileBinding binding = LayoutDmProfileBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmProfileBinding binding = LayoutDmProfileBinding.inflate(layoutInflater, baseBinding.message, false);
return new DirectItemProfileViewHolder(baseBinding, binding, currentUser, thread, null, null);
return new DirectItemProfileViewHolder(baseBinding, binding, currentUser, thread, null);
} }
case MEDIA: { case MEDIA: {
final LayoutDmMediaBinding binding = LayoutDmMediaBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmMediaBinding binding = LayoutDmMediaBinding.inflate(layoutInflater, baseBinding.message, false);
@ -183,7 +183,7 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
} }
case RAVEN_MEDIA: { case RAVEN_MEDIA: {
final LayoutDmRavenMediaBinding binding = LayoutDmRavenMediaBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmRavenMediaBinding binding = LayoutDmRavenMediaBinding.inflate(layoutInflater, baseBinding.message, false);
return new DirectItemRavenMediaViewHolder(baseBinding, binding, currentUser, thread, null, null);
return new DirectItemRavenMediaViewHolder(baseBinding, binding, currentUser, thread, null);
} }
default: { default: {
final LayoutDmTextBinding binding = LayoutDmTextBinding.inflate(layoutInflater, baseBinding.message, false); final LayoutDmTextBinding binding = LayoutDmTextBinding.inflate(layoutInflater, baseBinding.message, false);

10
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemActionLogViewHolder.java

@ -69,4 +69,14 @@ public class DirectItemActionLogViewHolder extends DirectItemViewHolder {
} }
binding.tvMessage.setText(sb); binding.tvMessage.setText(sb);
} }
@Override
protected boolean allowMessageDirectionGravity() {
return false;
}
@Override
protected boolean showMessageInfo() {
return false;
}
} }

1
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemAnimatedMediaViewHolder.java

@ -36,7 +36,6 @@ public class DirectItemAnimatedMediaViewHolder extends DirectItemViewHolder {
@Override @Override
public void bindItem(final DirectItem item, final MessageDirection messageDirection) { public void bindItem(final DirectItem item, final MessageDirection messageDirection) {
removeBg();
final DirectItemAnimatedMedia animatedMediaModel = item.getAnimatedMedia(); final DirectItemAnimatedMedia animatedMediaModel = item.getAnimatedMedia();
final AnimatedMediaImages images = animatedMediaModel.getImages(); final AnimatedMediaImages images = animatedMediaModel.getImages();
if (images == null) return; if (images == null) return;

8
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLikeViewHolder.java

@ -6,7 +6,6 @@ import androidx.annotation.NonNull;
import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmLikeBinding; import awais.instagrabber.databinding.LayoutDmLikeBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -17,14 +16,11 @@ public class DirectItemLikeViewHolder extends DirectItemViewHolder {
@NonNull final LayoutDmLikeBinding binding, @NonNull final LayoutDmLikeBinding binding,
final User currentUser, final User currentUser,
final DirectThread thread, final DirectThread thread,
final View.OnClickListener onClickListener,
final MentionClickListener mentionClickListener) {
final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
setItemView(binding.getRoot()); setItemView(binding.getRoot());
} }
@Override @Override
public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) {
removeBg();
}
public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) {}
} }

5
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java

@ -65,4 +65,9 @@ public class DirectItemLinkViewHolder extends DirectItemViewHolder {
} }
binding.text.setText(link.getText()); binding.text.setText(link.getText());
} }
@Override
protected boolean showBackground() {
return true;
}
} }

31
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java

@ -5,6 +5,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair; import androidx.core.util.Pair;
import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.drawable.ScalingUtils;
@ -56,18 +57,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
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);
Media media = null;
if (item.getItemType() == DirectItemType.MEDIA_SHARE) {
media = item.getMediaShare();
} else if (item.getItemType() == DirectItemType.CLIP) {
final DirectItemClip clip = item.getClip();
if (clip == null) return;
media = clip.getClip();
} else if (item.getItemType() == DirectItemType.FELIX_SHARE) {
final DirectItemFelixShare felixShare = item.getFelixShare();
if (felixShare == null) return;
media = felixShare.getVideo();
}
Media media = getMedia(item);
if (media == null) return; if (media == null) return;
final User user = media.getUser(); final User user = media.getUser();
if (user != null) { if (user != null) {
@ -121,4 +111,21 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
? R.drawable.ic_video_24 ? R.drawable.ic_video_24
: R.drawable.ic_checkbox_multiple_blank_stroke); : R.drawable.ic_checkbox_multiple_blank_stroke);
} }
@Nullable
private Media getMedia(@NonNull final DirectItem item) {
Media media = null;
if (item.getItemType() == DirectItemType.MEDIA_SHARE) {
media = item.getMediaShare();
} else if (item.getItemType() == DirectItemType.CLIP) {
final DirectItemClip clip = item.getClip();
if (clip == null) return null;
media = clip.getClip();
} else if (item.getItemType() == DirectItemType.FELIX_SHARE) {
final DirectItemFelixShare felixShare = item.getFelixShare();
if (felixShare == null) return null;
media = felixShare.getVideo();
}
return media;
}
} }

5
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemPlaceholderViewHolder.java

@ -31,4 +31,9 @@ public class DirectItemPlaceholderViewHolder extends DirectItemViewHolder {
final String text = String.format("%s: %s", directItemModel.getPlaceholder().getTitle(), directItemModel.getPlaceholder().getMessage()); final String text = String.format("%s: %s", directItemModel.getPlaceholder().getTitle(), directItemModel.getPlaceholder().getMessage());
binding.tvMessage.setText(text); binding.tvMessage.setText(text);
} }
@Override
protected boolean showBackground() {
return true;
}
} }

2
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemProfileViewHolder.java

@ -15,7 +15,6 @@ import java.util.List;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmProfileBinding; import awais.instagrabber.databinding.LayoutDmProfileBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.repositories.responses.ImageVersions2; import awais.instagrabber.repositories.responses.ImageVersions2;
import awais.instagrabber.repositories.responses.Location; import awais.instagrabber.repositories.responses.Location;
@ -35,7 +34,6 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
@NonNull final LayoutDmProfileBinding binding, @NonNull final LayoutDmProfileBinding binding,
final User currentUser, final User currentUser,
final DirectThread thread, final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) { final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding; this.binding = binding;

5
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java

@ -1,6 +1,5 @@
package awais.instagrabber.adapters.viewholder.directmessages; package awais.instagrabber.adapters.viewholder.directmessages;
import android.content.res.Resources;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,7 +12,6 @@ import com.facebook.drawee.generic.RoundingParams;
import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmRavenMediaBinding; import awais.instagrabber.databinding.LayoutDmRavenMediaBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.models.enums.RavenMediaViewMode; import awais.instagrabber.models.enums.RavenMediaViewMode;
import awais.instagrabber.repositories.responses.ImageVersions2; import awais.instagrabber.repositories.responses.ImageVersions2;
@ -34,18 +32,15 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder {
@NonNull final LayoutDmRavenMediaBinding binding, @NonNull final LayoutDmRavenMediaBinding binding,
final User currentUser, final User currentUser,
final DirectThread thread, final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) { final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding; this.binding = binding;
final Resources resources = itemView.getResources();
maxWidth = windowWidth - margin - dmRadiusSmall; maxWidth = windowWidth - margin - dmRadiusSmall;
setItemView(binding.getRoot()); setItemView(binding.getRoot());
} }
@Override @Override
public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) { public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) {
removeBg();
final DirectItemVisualMedia visualMedia = directItemModel.getVisualMedia(); final DirectItemVisualMedia visualMedia = directItemModel.getVisualMedia();
final Media media = visualMedia.getMedia(); final Media media = visualMedia.getMedia();
if (media == null) return; if (media == null) return;

1
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java

@ -40,7 +40,6 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder {
@Override @Override
public void bindItem(final DirectItem item, final MessageDirection messageDirection) { public void bindItem(final DirectItem item, final MessageDirection messageDirection) {
removeBg();
final DirectItemReelShare reelShare = item.getReelShare(); final DirectItemReelShare reelShare = item.getReelShare();
final String type = reelShare.getType(); final String type = reelShare.getType();
if (type == null) return; if (type == null) return;

28
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java

@ -6,7 +6,6 @@ import androidx.annotation.NonNull;
import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmTextBinding; import awais.instagrabber.databinding.LayoutDmTextBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -19,8 +18,7 @@ public class DirectItemTextViewHolder extends DirectItemViewHolder {
@NonNull final LayoutDmTextBinding binding, @NonNull final LayoutDmTextBinding binding,
final User currentUser, final User currentUser,
final DirectThread thread, final DirectThread thread,
final View.OnClickListener onClickListener,
final MentionClickListener mentionClickListener) {
final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding; this.binding = binding;
setItemView(binding.getRoot()); setItemView(binding.getRoot());
@ -31,5 +29,29 @@ public class DirectItemTextViewHolder extends DirectItemViewHolder {
final String text = directItemModel.getText(); final String text = directItemModel.getText();
if (text == null) return; if (text == null) return;
binding.tvMessage.setText(text); binding.tvMessage.setText(text);
// setupListeners();
} }
@Override
protected boolean showBackground() {
return true;
}
// private void setupListeners() {
// binding.tvMessage.addOnHashtagListener(autoLinkItem -> {
// final String hashtag = autoLinkItem.getOriginalText().trim();
// });
// binding.tvMessage.addOnMentionClickListener(autoLinkItem -> {
// final String mention = autoLinkItem.getOriginalText().trim();
// });
// binding.tvMessage.addOnEmailClickListener(autoLinkItem -> {
// final String email = autoLinkItem.getOriginalText().trim();
// });
// binding.tvMessage.addOnURLClickListener(autoLinkItem -> {
// final String url = autoLinkItem.getOriginalText().trim();
// });
// binding.tvMessage.setOnLongClickListener(v -> {
// return true;
// });
// }
} }

10
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVideoCallEventViewHolder.java

@ -62,4 +62,14 @@ public class DirectItemVideoCallEventViewHolder extends DirectItemViewHolder {
binding.tvMessage.setMaxLines(1); binding.tvMessage.setMaxLines(1);
binding.tvMessage.setText(sb); binding.tvMessage.setText(sb);
} }
@Override
protected boolean allowMessageDirectionGravity() {
return false;
}
@Override
protected boolean showMessageInfo() {
return false;
}
} }

126
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java

@ -77,16 +77,41 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
public void bind(final DirectItem item) { public void bind(final DirectItem item) {
final MessageDirection messageDirection = isSelf(item) ? MessageDirection.OUTGOING : MessageDirection.INCOMING; final MessageDirection messageDirection = isSelf(item) ? MessageDirection.OUTGOING : MessageDirection.INCOMING;
itemView.post(() -> bindBase(item, messageDirection));
itemView.post(() -> bindItem(item, messageDirection));
}
private void bindBase(final DirectItem item, final MessageDirection messageDirection) {
final FrameLayout.LayoutParams containerLayoutParams = (FrameLayout.LayoutParams) binding.container.getLayoutParams(); final FrameLayout.LayoutParams containerLayoutParams = (FrameLayout.LayoutParams) binding.container.getLayoutParams();
final DirectItemType itemType = item.getItemType(); final DirectItemType itemType = item.getItemType();
binding.messageInfo.setVisibility(View.VISIBLE);
binding.deliveryStatus.setVisibility(messageDirection == MessageDirection.OUTGOING ? View.VISIBLE : View.GONE);
if (itemType != DirectItemType.ACTION_LOG && itemType != DirectItemType.VIDEO_CALL_EVENT) {
containerLayoutParams.setMarginStart(messageDirection == MessageDirection.OUTGOING ? margin : 0);
containerLayoutParams.setMarginEnd(messageDirection == MessageDirection.INCOMING ? margin : 0);
containerLayoutParams.gravity = messageDirection == MessageDirection.INCOMING ? Gravity.START : Gravity.END;
setMessageDirectionGravity(messageDirection, containerLayoutParams);
setGroupUserDetails(item, messageDirection);
setBackground(messageDirection);
setMessageInfo(item, messageDirection);
if (itemType == DirectItemType.REEL_SHARE) {
containerLayoutParams.setMarginStart(0);
containerLayoutParams.setMarginEnd(0);
}
if (itemType == DirectItemType.TEXT || itemType == DirectItemType.LINK) {
binding.messageInfo.setPadding(0, 0, dmRadius, dmRadiusSmall);
} else {
binding.messageInfo.setPadding(0, 0, messageInfoPaddingSmall, dmRadiusSmall);
}
setupReply(item, messageDirection);
setReactions(item, thread.getUsers());
}
private void setBackground(final MessageDirection messageDirection) {
if (showBackground()) {
binding.background.setBackgroundResource(messageDirection == MessageDirection.INCOMING ? R.drawable.bg_speech_bubble_incoming binding.background.setBackgroundResource(messageDirection == MessageDirection.INCOMING ? R.drawable.bg_speech_bubble_incoming
: R.drawable.bg_speech_bubble_outgoing); : R.drawable.bg_speech_bubble_outgoing);
return;
}
binding.background.setBackgroundResource(0);
}
private void setGroupUserDetails(final DirectItem item, final MessageDirection messageDirection) {
if (showUserDetailsInGroup()) {
binding.ivProfilePic.setVisibility(messageDirection == MessageDirection.INCOMING && thread.isGroup() ? View.VISIBLE : View.GONE); binding.ivProfilePic.setVisibility(messageDirection == MessageDirection.INCOMING && thread.isGroup() ? View.VISIBLE : View.GONE);
binding.tvUsername.setVisibility(messageDirection == MessageDirection.INCOMING && thread.isGroup() ? View.VISIBLE : View.GONE); binding.tvUsername.setVisibility(messageDirection == MessageDirection.INCOMING && thread.isGroup() ? View.VISIBLE : View.GONE);
if (messageDirection == MessageDirection.INCOMING && thread.isGroup()) { if (messageDirection == MessageDirection.INCOMING && thread.isGroup()) {
@ -99,45 +124,46 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
layoutParams.matchConstraintMaxWidth = groupMessageWidth; layoutParams.matchConstraintMaxWidth = groupMessageWidth;
binding.chatMessageLayout.setLayoutParams(layoutParams); binding.chatMessageLayout.setLayoutParams(layoutParams);
} }
} else {
binding.ivProfilePic.setVisibility(View.GONE);
binding.tvUsername.setVisibility(View.GONE);
containerLayoutParams.gravity = Gravity.CENTER;
binding.messageInfo.setVisibility(View.GONE);
}
if (itemType == DirectItemType.REEL_SHARE) {
containerLayoutParams.setMarginStart(0);
containerLayoutParams.setMarginEnd(0);
}
if (itemType == DirectItemType.TEXT || itemType == DirectItemType.LINK) {
binding.messageInfo.setPadding(0,
0,
dmRadius,
dmRadiusSmall);
} else {
binding.messageInfo.setPadding(0,
0,
messageInfoPaddingSmall,
dmRadiusSmall);
return;
} }
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);
binding.ivProfilePic.setVisibility(View.GONE);
binding.tvUsername.setVisibility(View.GONE);
}
private void setMessageDirectionGravity(final MessageDirection messageDirection,
final FrameLayout.LayoutParams containerLayoutParams) {
if (allowMessageDirectionGravity()) {
containerLayoutParams.setMarginStart(messageDirection == MessageDirection.OUTGOING ? margin : 0);
containerLayoutParams.setMarginEnd(messageDirection == MessageDirection.INCOMING ? margin : 0);
containerLayoutParams.gravity = messageDirection == MessageDirection.INCOMING ? Gravity.START : Gravity.END;
return;
} }
binding.messageTime.setText(DateFormat.getTimeFormat(itemView.getContext()).format(item.getDate()));
if (messageDirection == MessageDirection.OUTGOING) {
if (item.isPending()) {
binding.deliveryStatus.setImageResource(R.drawable.ic_check_24);
} else {
final boolean read = ResponseBodyUtils.isRead(item, thread.getLastSeenAt(), userIds, null);
binding.deliveryStatus.setImageResource(R.drawable.ic_check_all_24);
ImageViewCompat.setImageTintList(
binding.deliveryStatus,
ColorStateList.valueOf(itemView.getResources().getColor(read ? R.color.blue_500 : R.color.grey_500))
);
containerLayoutParams.gravity = Gravity.CENTER;
}
private void setMessageInfo(final DirectItem item, final MessageDirection messageDirection) {
if (showMessageInfo()) {
binding.messageInfo.setVisibility(View.VISIBLE);
binding.deliveryStatus.setVisibility(messageDirection == MessageDirection.OUTGOING ? View.VISIBLE : View.GONE);
binding.messageTime.setText(DateFormat.getTimeFormat(itemView.getContext()).format(item.getDate()));
if (messageDirection == MessageDirection.OUTGOING) {
if (item.isPending()) {
binding.deliveryStatus.setImageResource(R.drawable.ic_check_24);
} else {
final boolean read = ResponseBodyUtils.isRead(item, thread.getLastSeenAt(), userIds, null);
binding.deliveryStatus.setImageResource(R.drawable.ic_check_all_24);
ImageViewCompat.setImageTintList(
binding.deliveryStatus,
ColorStateList.valueOf(itemView.getResources().getColor(read ? R.color.blue_500 : R.color.grey_500))
);
}
} }
return;
} }
binding.messageInfo.setVisibility(View.GONE);
}
private void setupReply(final DirectItem item, final MessageDirection messageDirection) {
if (item.getRepliedToMessage() != null) { if (item.getRepliedToMessage() != null) {
setReply(item, messageDirection, thread.getUsers()); setReply(item, messageDirection, thread.getUsers());
} else { } else {
@ -145,8 +171,6 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
binding.replyContainer.setVisibility(View.GONE); binding.replyContainer.setVisibility(View.GONE);
binding.replyInfo.setVisibility(View.GONE); binding.replyInfo.setVisibility(View.GONE);
} }
setReactions(item, thread.getUsers());
bindItem(item, messageDirection);
} }
private void setReply(final DirectItem item, private void setReply(final DirectItem item,
@ -324,8 +348,20 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
return null; return null;
} }
protected void removeBg() {
binding.background.setBackground(null);
protected boolean allowMessageDirectionGravity() {
return true;
}
protected boolean showUserDetailsInGroup() {
return true;
}
protected boolean showBackground() {
return false;
}
protected boolean showMessageInfo() {
return true;
} }
public void cleanup() {} public void cleanup() {}

6
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVoiceMediaViewHolder.java

@ -19,7 +19,6 @@ import java.util.List;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmVoiceMediaBinding; import awais.instagrabber.databinding.LayoutDmVoiceMediaBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.repositories.responses.Audio; import awais.instagrabber.repositories.responses.Audio;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.User;
@ -27,7 +26,6 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemVoiceMedia; import awais.instagrabber.repositories.responses.directmessages.DirectItemVoiceMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import static com.google.android.exoplayer2.C.TIME_UNSET; import static com.google.android.exoplayer2.C.TIME_UNSET;
@ -45,18 +43,16 @@ public class DirectItemVoiceMediaViewHolder extends DirectItemViewHolder {
@NonNull final LayoutDmVoiceMediaBinding binding, @NonNull final LayoutDmVoiceMediaBinding binding,
final User currentUser, final User currentUser,
final DirectThread thread, final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) { final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener); super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding; this.binding = binding;
this.dataSourceFactory = new DefaultDataSourceFactory(binding.getRoot().getContext(), "instagram"); this.dataSourceFactory = new DefaultDataSourceFactory(binding.getRoot().getContext(), "instagram");
setItemView(binding.getRoot()); setItemView(binding.getRoot());
binding.waveformSeekBar.getLayoutParams().width = windowWidth - margin - Utils.convertDpToPx(56);
binding.voiceMedia.getLayoutParams().width = mediaImageMaxWidth;
} }
@Override @Override
public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) { public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) {
removeBg();
final DirectItemVoiceMedia voiceMedia = directItemModel.getVoiceMedia(); final DirectItemVoiceMedia voiceMedia = directItemModel.getVoiceMedia();
if (voiceMedia == null) return; if (voiceMedia == null) return;
final Media media = voiceMedia.getMedia(); final Media media = voiceMedia.getMedia();

3
app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java

@ -92,7 +92,8 @@ 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 || firstChildId == R.id.story_container) {
} else if (firstChildId == R.id.raven_media_container || firstChildId == R.id.profile_container || firstChildId == R.id.voice_media
|| firstChildId == R.id.story_container || firstChildId == R.id.media_share_container) {
widthSize += viewPartMainWidth; widthSize += viewPartMainWidth;
heightSize += viewPartMainHeight + viewPartInfoHeight; heightSize += viewPartMainHeight + viewPartInfoHeight;
} else { } else {

8
app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java

@ -545,14 +545,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
new ProfileFetcher(username.trim().substring(1), profileModel -> { new ProfileFetcher(username.trim().substring(1), profileModel -> {
if (getContext() == null) return; if (getContext() == null) return;
this.profileModel = profileModel; this.profileModel = profileModel;
// final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
// final boolean isSelf = isLoggedIn
// && profileModel != null
// && userIdFromCookie != null
// && userIdFromCookie.equals(profileModel.getId());
// if (favMenuItem != null) {
// favMenuItem.setVisible(isSelf);
// }
setProfileDetails(); setProfileDetails();
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

4
app/src/main/res/layout/layout_dm_voice_media.xml

@ -3,7 +3,7 @@
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/voice_media" android:id="@+id/voice_media"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<FrameLayout <FrameLayout
@ -62,7 +62,7 @@
<awais.instagrabber.customviews.masoudss_waveform.WaveformSeekBar <awais.instagrabber.customviews.masoudss_waveform.WaveformSeekBar
android:id="@+id/waveformSeekBar" android:id="@+id/waveformSeekBar"
android:layout_width="200dp"
android:layout_width="0dp"
android:layout_height="54dp" android:layout_height="54dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="4dp" android:layout_marginEnd="4dp"

Loading…
Cancel
Save