Browse Source

Support opening story from direct thread

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
4b055c8050
  1. 3
      app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java
  2. 5
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java
  3. 5
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java
  4. 18
      app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
  5. 8
      app/src/main/java/awais/instagrabber/webservices/StoriesService.java
  6. 12
      app/src/main/res/navigation/direct_messages_nav_graph.xml
  7. 1
      app/src/main/res/navigation/feed_nav_graph.xml

3
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.Media;
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.DirectItemStoryShare;
import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.DateUtils; import awais.instagrabber.utils.DateUtils;
@ -369,5 +370,7 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
void onEmailClick(String email); void onEmailClick(String email);
void onMediaClick(Media media); void onMediaClick(Media media);
void onStoryClick(DirectItemStoryShare storyShare);
} }
} }

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

@ -49,7 +49,8 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
if (reelType.equals("highlight_reel")) { if (reelType.equals("highlight_reel")) {
format = "@%s's story highlight"; format = "@%s's story highlight";
} }
final String info = String.format(format, item.getStoryShare().getMedia().getUser().getUsername());
final User user = item.getStoryShare().getMedia().getUser();
final String info = String.format(format, user != null ? user.getUsername() : "");
binding.shareInfo.setText(info); binding.shareInfo.setText(info);
binding.text.setVisibility(View.GONE); binding.text.setVisibility(View.GONE);
binding.ivMediaPreview.setController(null); binding.ivMediaPreview.setController(null);
@ -58,7 +59,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
setText(storyShare); setText(storyShare);
final Media media = storyShare.getMedia(); final Media media = storyShare.getMedia();
setupPreview(messageDirection, media); setupPreview(messageDirection, media);
itemView.setOnClickListener(v -> openMedia(media));
itemView.setOnClickListener(v -> openStory(storyShare));
} }
private void setupPreview(final MessageDirection messageDirection, final Media storyShareMedia) { private void setupPreview(final MessageDirection messageDirection, final Media storyShareMedia) {

5
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.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemEmojiReaction; import awais.instagrabber.repositories.responses.directmessages.DirectItemEmojiReaction;
import awais.instagrabber.repositories.responses.directmessages.DirectItemReactions; import awais.instagrabber.repositories.responses.directmessages.DirectItemReactions;
import awais.instagrabber.repositories.responses.directmessages.DirectItemStoryShare;
import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.DeepLinkParser; import awais.instagrabber.utils.DeepLinkParser;
import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.ResponseBodyUtils;
@ -394,6 +395,10 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
callback.onMediaClick(media); callback.onMediaClick(media);
} }
protected void openStory(final DirectItemStoryShare storyShare) {
callback.onStoryClick(storyShare);
}
protected void handleDeepLink(final String deepLinkText) { protected void handleDeepLink(final String deepLinkText) {
if (deepLinkText == null) return; if (deepLinkText == null) return;
final DeepLinkParser.DeepLink deepLink = DeepLinkParser.parse(deepLinkText); final DeepLinkParser.DeepLink deepLink = DeepLinkParser.parse(deepLinkText);

18
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.dialogs.MediaPickerBottomDialogFragment;
import awais.instagrabber.fragments.PostViewV2Fragment; import awais.instagrabber.fragments.PostViewV2Fragment;
import awais.instagrabber.models.Resource; import awais.instagrabber.models.Resource;
import awais.instagrabber.repositories.requests.StoryViewerOptions;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
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.DirectItemStoryShare;
import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.AppExecutors; import awais.instagrabber.utils.AppExecutors;
import awais.instagrabber.utils.PermissionUtils; import awais.instagrabber.utils.PermissionUtils;
@ -170,6 +172,22 @@ public class DirectMessageThreadFragment extends Fragment {
final PostViewV2Fragment.Builder builder = PostViewV2Fragment.builder(media); final PostViewV2Fragment.Builder builder = PostViewV2Fragment.builder(media);
builder.build().show(getChildFragmentManager(), "post_view"); 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 @Override

8
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) { for (int i = 0; i < feedStoriesReel.length(); ++i) {
final JSONObject node = feedStoriesReel.getJSONObject(i); final JSONObject node = feedStoriesReel.getJSONObject(i);
final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner"); 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"), final User user = new User(userJson.getLong("pk"),
userJson.getString("username"), userJson.getString("username"),
userJson.optString("full_name"), userJson.optString("full_name"),
@ -350,7 +344,7 @@ public class StoriesService extends BaseService {
if (!isHighlight) { if (!isHighlight) {
data = data.optJSONObject((isLoc || isHashtag) ? "story" : "reel"); data = data.optJSONObject((isLoc || isHashtag) ? "story" : "reel");
} else if (isHighlight) {
} else {
data = data.getJSONObject("reels").optJSONObject(options.getName()); data = data.getJSONObject("reels").optJSONObject(options.getName());
} }

12
app/src/main/res/navigation/direct_messages_nav_graph.xml

@ -130,6 +130,9 @@
<action <action
android:id="@+id/action_thread_to_image_edit" android:id="@+id/action_thread_to_image_edit"
app:destination="@id/imageEditFragment" /> app:destination="@id/imageEditFragment" />
<action
android:id="@+id/action_thread_to_story"
app:destination="@id/storyViewerFragment" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/directMessagesSettingsFragment" android:id="@+id/directMessagesSettingsFragment"
@ -163,4 +166,13 @@
app:argType="android.net.Uri" app:argType="android.net.Uri"
app:nullable="false" /> app:nullable="false" />
</fragment> </fragment>
<fragment
android:id="@+id/storyViewerFragment"
android:name="awais.instagrabber.fragments.StoryViewerFragment"
android:label="StoryViewerFragment"
tools:layout="@layout/fragment_story_viewer">
<argument
android:name="options"
app:argType="awais.instagrabber.repositories.requests.StoryViewerOptions" />
</fragment>
</navigation> </navigation>

1
app/src/main/res/navigation/feed_nav_graph.xml

@ -101,6 +101,7 @@
android:id="@+id/action_feedFragment_to_storyViewerFragment" android:id="@+id/action_feedFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" /> app:destination="@id/storyViewerFragment" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/storyViewerFragment" android:id="@+id/storyViewerFragment"
android:name="awais.instagrabber.fragments.StoryViewerFragment" android:name="awais.instagrabber.fragments.StoryViewerFragment"

Loading…
Cancel
Save