From 8bf9f5f2cca0d9d26f55b11ce0631b099ab75ae8 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 28 Jun 2021 16:14:28 -0400 Subject: [PATCH] reading exact child from dm media shares https://t.me/barinsta_app/21890 --- .../adapters/DirectItemsAdapter.java | 2 +- .../DirectItemMediaShareViewHolder.java | 25 +++++++++++++------ .../DirectItemMediaViewHolder.java | 2 +- .../DirectItemRavenMediaViewHolder.java | 2 +- .../DirectItemReelShareViewHolder.java | 2 +- .../directmessages/DirectItemViewHolder.java | 4 +-- .../DirectMessageThreadFragment.java | 3 ++- .../repositories/responses/Media.kt | 3 ++- .../instagrabber/utils/ResponseBodyUtils.java | 1 + 9 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java index 40624082..49339863 100644 --- a/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java @@ -401,7 +401,7 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter media.getCarouselShareChildMediaId() != null && + media.getCarouselShareChildMediaId().equals(m.getId())) + .findAny() + .orElse(media.getCarouselMedia().get(0)); + index = media.getCarouselMedia().indexOf(toDisplay); + break; + default: + toDisplay = media; + index = 0; + } itemView.post(() -> { - final MediaItemType mediaType = media.getMediaType(); setupTypeIndicator(mediaType); - if (mediaType == MediaItemType.MEDIA_TYPE_SLIDER) { - setupPreview(media.getCarouselMedia().get(0), messageDirection); - return; - } - setupPreview(media, messageDirection); + setupPreview(toDisplay, messageDirection); }); - itemView.setOnClickListener(v -> openMedia(media)); + itemView.setOnClickListener(v -> openMedia(media, index)); } private void setupTypeIndicator(final MediaItemType mediaType) { 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 769548a8..d2a7a5ee 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 @@ -47,7 +47,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder { .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP) .build()); final Media media = directItemModel.getMedia(); - itemView.setOnClickListener(v -> openMedia(media)); + itemView.setOnClickListener(v -> openMedia(media, -1)); final MediaItemType modelMediaType = media.getMediaType(); binding.typeIcon.setVisibility(modelMediaType == MediaItemType.MEDIA_TYPE_VIDEO || modelMediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE 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 9778d046..3f8f0ed7 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 @@ -50,7 +50,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder { setPreview(visualMedia, messageDirection); final boolean expired = TextUtils.isEmpty(media.getId()); if (expired) return; - itemView.setOnClickListener(v -> openMedia(media)); + itemView.setOnClickListener(v -> openMedia(media, -1)); /*final boolean isExpired = visualMedia == null || (mediaModel = visualMedia.getMedia()) == null || TextUtils.isEmpty(mediaModel.getThumbUrl()) && mediaModel.getPk() < 1; 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 aa1666ab..1c755881 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 @@ -76,7 +76,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder { } if (!expired) { setPreview(media); - itemView.setOnClickListener(v -> openMedia(media)); + itemView.setOnClickListener(v -> openMedia(media, -1)); } } 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 f61c45ef..e969e183 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 @@ -501,8 +501,8 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple callback.onURLClick(url); } - protected void openMedia(final Media media) { - callback.onMediaClick(media); + protected void openMedia(final Media media, final int index) { + callback.onMediaClick(media, index); } protected void openStory(final DirectItemStoryShare storyShare) { diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index b9b91fa1..21fea718 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -220,7 +220,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact } @Override - public void onMediaClick(final Media media) { + public void onMediaClick(final Media media, final int index) { if (media.isReelMedia()) { final String pk = media.getPk(); try { @@ -239,6 +239,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact final NavController navController = NavHostFragment.findNavController(DirectMessageThreadFragment.this); final Bundle bundle = new Bundle(); bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, media); + bundle.putInt(PostViewV2Fragment.ARG_SLIDER_POSITION, index); try { navController.navigate(R.id.action_global_post_view, bundle); } catch (Exception e) { diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/Media.kt b/app/src/main/java/awais/instagrabber/repositories/responses/Media.kt index 03d8aba2..05fd19c9 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/Media.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/Media.kt @@ -38,7 +38,8 @@ data class Media( var isSidecarChild: Boolean = false, var hasViewerSaved: Boolean = false, private val injected: Map? = null, - val endOfFeedDemarcator: EndOfFeedDemarcator? = null + val endOfFeedDemarcator: EndOfFeedDemarcator? = null, + val carouselShareChildMediaId: String? = null // which specific child should dm show first ) : Serializable { private var dateString: String? = null diff --git a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java index 0330d6e2..530dd208 100644 --- a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java @@ -271,6 +271,7 @@ public final class ResponseBodyUtils { false, false, null, + null, null ); }