1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-16 11:47:29 +00:00

Support opening story from direct thread

This commit is contained in:
Ammar Githam 2021-01-10 18:45:17 +09:00
parent ba10f8b410
commit 4b055c8050
7 changed files with 43 additions and 9 deletions

View File

@ -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<RecyclerView.
void onEmailClick(String email);
void onMediaClick(Media media);
void onStoryClick(DirectItemStoryShare storyShare);
}
}

View File

@ -49,7 +49,8 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
if (reelType.equals("highlight_reel")) {
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.text.setVisibility(View.GONE);
binding.ivMediaPreview.setController(null);
@ -58,7 +59,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
setText(storyShare);
final Media media = storyShare.getMedia();
setupPreview(messageDirection, media);
itemView.setOnClickListener(v -> openMedia(media));
itemView.setOnClickListener(v -> openStory(storyShare));
}
private void setupPreview(final MessageDirection messageDirection, final Media storyShareMedia) {

View File

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

View File

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

View File

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

View File

@ -130,6 +130,9 @@
<action
android:id="@+id/action_thread_to_image_edit"
app:destination="@id/imageEditFragment" />
<action
android:id="@+id/action_thread_to_story"
app:destination="@id/storyViewerFragment" />
</fragment>
<fragment
android:id="@+id/directMessagesSettingsFragment"
@ -163,4 +166,13 @@
app:argType="android.net.Uri"
app:nullable="false" />
</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>

View File

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