From 4b055c80502aeba87b675784f0b62d71c603134f Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 10 Jan 2021 18:45:17 +0900 Subject: [PATCH] Support opening story from direct thread --- .../adapters/DirectItemsAdapter.java | 3 +++ .../DirectItemStoryShareViewHolder.java | 5 +++-- .../directmessages/DirectItemViewHolder.java | 5 +++++ .../DirectMessageThreadFragment.java | 18 ++++++++++++++++++ .../webservices/StoriesService.java | 8 +------- .../navigation/direct_messages_nav_graph.xml | 12 ++++++++++++ app/src/main/res/navigation/feed_nav_graph.xml | 1 + 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java index 3d386857..7f4622f7 100644 --- a/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java @@ -50,6 +50,7 @@ import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; +import awais.instagrabber.repositories.responses.directmessages.DirectItemStoryShare; import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.DateUtils; @@ -369,5 +370,7 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter openMedia(media)); + itemView.setOnClickListener(v -> openStory(storyShare)); } private void setupPreview(final MessageDirection messageDirection, final Media storyShareMedia) { 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 9eb223ca..072e9b8c 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 @@ -29,6 +29,7 @@ import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; import awais.instagrabber.repositories.responses.directmessages.DirectItemEmojiReaction; import awais.instagrabber.repositories.responses.directmessages.DirectItemReactions; +import awais.instagrabber.repositories.responses.directmessages.DirectItemStoryShare; import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.DeepLinkParser; import awais.instagrabber.utils.ResponseBodyUtils; @@ -394,6 +395,10 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder { callback.onMediaClick(media); } + protected void openStory(final DirectItemStoryShare storyShare) { + callback.onStoryClick(storyShare); + } + protected void handleDeepLink(final String deepLinkText) { if (deepLinkText == null) return; final DeepLinkParser.DeepLink deepLink = DeepLinkParser.parse(deepLinkText); 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 ac2a0fe6..2328098b 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -70,9 +70,11 @@ import awais.instagrabber.databinding.FragmentDirectMessagesThreadBinding; import awais.instagrabber.dialogs.MediaPickerBottomDialogFragment; import awais.instagrabber.fragments.PostViewV2Fragment; import awais.instagrabber.models.Resource; +import awais.instagrabber.repositories.requests.StoryViewerOptions; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.directmessages.DirectItem; +import awais.instagrabber.repositories.responses.directmessages.DirectItemStoryShare; import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.utils.AppExecutors; import awais.instagrabber.utils.PermissionUtils; @@ -170,6 +172,22 @@ public class DirectMessageThreadFragment extends Fragment { final PostViewV2Fragment.Builder builder = PostViewV2Fragment.builder(media); builder.build().show(getChildFragmentManager(), "post_view"); } + + @Override + public void onStoryClick(final DirectItemStoryShare storyShare) { + final String pk = storyShare.getReelId(); + try { + final long mediaId = Long.parseLong(pk); + final User user = storyShare.getMedia().getUser(); + if (user == null) return; + final String username = user.getUsername(); + final NavDirections action = DirectMessageThreadFragmentDirections + .actionThreadToStory(StoryViewerOptions.forUser(mediaId, username)); + NavHostFragment.findNavController(DirectMessageThreadFragment.this).navigate(action); + } catch (NumberFormatException e) { + Log.e(TAG, "onStoryClick: ", e); + } + } }; @Override diff --git a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java index e6c4e39f..7ed4e75b 100644 --- a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java +++ b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java @@ -113,12 +113,6 @@ public class StoriesService extends BaseService { for (int i = 0; i < feedStoriesReel.length(); ++i) { final JSONObject node = feedStoriesReel.getJSONObject(i); final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner"); - // final ProfileModel profileModel = new ProfileModel(false, false, false, - // user.getString("pk"), - // user.getString("username"), - // null, null, null, - // user.getString("profile_pic_url"), - // null, 0, 0, 0, false, false, false, false, false); final User user = new User(userJson.getLong("pk"), userJson.getString("username"), userJson.optString("full_name"), @@ -350,7 +344,7 @@ public class StoriesService extends BaseService { if (!isHighlight) { data = data.optJSONObject((isLoc || isHashtag) ? "story" : "reel"); - } else if (isHighlight) { + } else { data = data.getJSONObject("reels").optJSONObject(options.getName()); } diff --git a/app/src/main/res/navigation/direct_messages_nav_graph.xml b/app/src/main/res/navigation/direct_messages_nav_graph.xml index 0c5ed261..40a49c52 100644 --- a/app/src/main/res/navigation/direct_messages_nav_graph.xml +++ b/app/src/main/res/navigation/direct_messages_nav_graph.xml @@ -130,6 +130,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/feed_nav_graph.xml b/app/src/main/res/navigation/feed_nav_graph.xml index 1efbc946..bda25b4e 100644 --- a/app/src/main/res/navigation/feed_nav_graph.xml +++ b/app/src/main/res/navigation/feed_nav_graph.xml @@ -101,6 +101,7 @@ android:id="@+id/action_feedFragment_to_storyViewerFragment" app:destination="@id/storyViewerFragment" /> +