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

restore location & hashtag stories

This commit is contained in:
Austin Huang 2020-09-25 20:15:46 -04:00
parent 96a25f0d35
commit 6bd0b811b1
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
14 changed files with 229 additions and 91 deletions

View File

@ -79,7 +79,8 @@ public final class PostsFetcher extends AsyncTask<Void, Void, List<PostModel>> {
"{\"id\":\"" + id + "\",\"first\":150,\"after\":\"" + endCursor + "\"}"; "{\"id\":\"" + id + "\",\"first\":150,\"after\":\"" + endCursor + "\"}";
break; break;
default: default:
url = "https://www.instagram.com/graphql/query/?query_id=17880160963012870&id=" + id + "&first=50&after=" + endCursor; url = "https://www.instagram.com/graphql/query/?query_hash=18a7b935ab438c4514b1f742d8fa07a7&variables=" +
"{\"id\":\"" + id + "\",\"first\":150,\"after\":\"" + endCursor + "\"}";
} }
List<PostModel> result = new ArrayList<>(); List<PostModel> result = new ArrayList<>();
try { try {
@ -153,8 +154,7 @@ public final class PostsFetcher extends AsyncTask<Void, Void, List<PostModel>> {
mediaNode.getLong("taken_at_timestamp"), mediaNode.getLong("taken_at_timestamp"),
mediaNode.optBoolean("viewer_has_liked"), mediaNode.optBoolean("viewer_has_liked"),
mediaNode.optBoolean("viewer_has_saved"), mediaNode.optBoolean("viewer_has_saved"),
mediaNode.getJSONObject("edge_liked_by") mediaNode.isNull("edge_liked_by") ? 0 : mediaNode.getJSONObject("edge_liked_by").getLong("count")
.getLong("count")
); );
result.add(model); result.add(model);
DownloadUtils.checkExistence(downloadDir, customDir, isSlider, model); DownloadUtils.checkExistence(downloadDir, customDir, isSlider, model);

View File

@ -1,6 +1,7 @@
package awais.instagrabber.fragments; package awais.instagrabber.fragments;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -21,6 +22,7 @@ import androidx.activity.OnBackPressedDispatcher;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavDirections; import androidx.navigation.NavDirections;
@ -40,7 +42,6 @@ import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.adapters.PostsAdapter; import awais.instagrabber.adapters.PostsAdapter;
import awais.instagrabber.asyncs.HashtagFetcher; import awais.instagrabber.asyncs.HashtagFetcher;
import awais.instagrabber.asyncs.PostsFetcher; import awais.instagrabber.asyncs.PostsFetcher;
import awais.instagrabber.asyncs.i.iStoryStatusFetcher;
import awais.instagrabber.customviews.PrimaryActionModeCallback; import awais.instagrabber.customviews.PrimaryActionModeCallback;
import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager;
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
@ -50,6 +51,7 @@ import awais.instagrabber.databinding.FragmentHashtagBinding;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.HashtagModel; import awais.instagrabber.models.HashtagModel;
import awais.instagrabber.models.PostModel; import awais.instagrabber.models.PostModel;
import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.DownloadMethod; import awais.instagrabber.models.enums.DownloadMethod;
import awais.instagrabber.models.enums.FavoriteType; import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.models.enums.PostItemType; import awais.instagrabber.models.enums.PostItemType;
@ -61,6 +63,7 @@ import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.PostsViewModel; import awais.instagrabber.viewmodels.PostsViewModel;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService;
import awais.instagrabber.webservices.TagsService; import awais.instagrabber.webservices.TagsService;
import awaisomereport.LogCollector; import awaisomereport.LogCollector;
@ -73,12 +76,13 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private MainActivity fragmentActivity; private MainActivity fragmentActivity;
private FragmentHashtagBinding binding; private FragmentHashtagBinding binding;
private NestedCoordinatorLayout root; private NestedCoordinatorLayout root;
private boolean shouldRefresh = true; private boolean shouldRefresh = true, hasStories = false;
private String hashtag; private String hashtag;
private HashtagModel hashtagModel; private HashtagModel hashtagModel;
private PostsViewModel postsViewModel; private PostsViewModel postsViewModel;
private PostsAdapter postsAdapter; private PostsAdapter postsAdapter;
private ActionMode actionMode; private ActionMode actionMode;
private StoriesService storiesService;
private boolean hasNextPage; private boolean hasNextPage;
private String endCursor; private String endCursor;
private AsyncTask<?, ?, ?> currentlyExecuting; private AsyncTask<?, ?, ?> currentlyExecuting;
@ -155,6 +159,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
fragmentActivity = (MainActivity) requireActivity(); fragmentActivity = (MainActivity) requireActivity();
tagsService = TagsService.getInstance(); tagsService = TagsService.getInstance();
storiesService = StoriesService.getInstance();
} }
@Nullable @Nullable
@ -184,6 +189,12 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
fetchHashtagModel(); fetchHashtagModel();
} }
@Override
public void onResume() {
super.onResume();
setTitle();
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -286,11 +297,25 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
if (isLoggedIn) { if (isLoggedIn) {
new iStoryStatusFetcher(hashtagModel.getName(), null, false, true, false, stories -> { storiesService.getUserStory(hashtagModel.getName(),
if (stories != null && stories.length > 0) { null,
false,
true,
false,
new ServiceCallback<List<StoryModel>>() {
@Override
public void onSuccess(final List<StoryModel> storyModels) {
if (storyModels != null && !storyModels.isEmpty()) {
binding.mainHashtagImage.setStoriesBorder(); binding.mainHashtagImage.setStoriesBorder();
hasStories = true;
} }
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t);
}
});
binding.btnFollowTag.setVisibility(View.VISIBLE); binding.btnFollowTag.setVisibility(View.VISIBLE);
binding.btnFollowTag.setText(hashtagModel.getFollowing() ? R.string.unfollow : R.string.follow); binding.btnFollowTag.setText(hashtagModel.getFollowing() ? R.string.unfollow : R.string.follow);
binding.btnFollowTag.setChipIconResource(hashtagModel.getFollowing() binding.btnFollowTag.setChipIconResource(hashtagModel.getFollowing()
@ -394,6 +419,15 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0);
binding.mainTagPostCount.setText(span); binding.mainTagPostCount.setText(span);
binding.mainTagPostCount.setVisibility(View.VISIBLE); binding.mainTagPostCount.setVisibility(View.VISIBLE);
binding.mainHashtagImage.setOnClickListener(v -> {
if (hasStories) {
// show stories
final NavDirections action = HashTagFragmentDirections
.actionHashtagFragmentToStoryViewerFragment(-1, null, true, false, hashtagModel.getName(), hashtagModel.getName());
NavHostFragment.findNavController(this).navigate(action);
return;
}
});
} }
public void stopCurrentExecutor() { public void stopCurrentExecutor() {

View File

@ -52,6 +52,7 @@ import awais.instagrabber.databinding.FragmentLocationBinding;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.LocationModel; import awais.instagrabber.models.LocationModel;
import awais.instagrabber.models.PostModel; import awais.instagrabber.models.PostModel;
import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.DownloadMethod; import awais.instagrabber.models.enums.DownloadMethod;
import awais.instagrabber.models.enums.FavoriteType; import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.models.enums.PostItemType; import awais.instagrabber.models.enums.PostItemType;
@ -62,6 +63,8 @@ import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.PostsViewModel; import awais.instagrabber.viewmodels.PostsViewModel;
import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService;
import awaisomereport.LogCollector; import awaisomereport.LogCollector;
import static awais.instagrabber.utils.Utils.logCollector; import static awais.instagrabber.utils.Utils.logCollector;
@ -73,12 +76,13 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private MainActivity fragmentActivity; private MainActivity fragmentActivity;
private FragmentLocationBinding binding; private FragmentLocationBinding binding;
private NestedCoordinatorLayout root; private NestedCoordinatorLayout root;
private boolean shouldRefresh = true; private boolean shouldRefresh = true, hasStories = false;
private String locationId; private String locationId;
private LocationModel locationModel; private LocationModel locationModel;
private PostsViewModel postsViewModel; private PostsViewModel postsViewModel;
private PostsAdapter postsAdapter; private PostsAdapter postsAdapter;
private ActionMode actionMode; private ActionMode actionMode;
private StoriesService storiesService;
private boolean hasNextPage; private boolean hasNextPage;
private String endCursor; private String endCursor;
private AsyncTask<?, ?, ?> currentlyExecuting; private AsyncTask<?, ?, ?> currentlyExecuting;
@ -155,6 +159,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
fragmentActivity = (MainActivity) requireActivity(); fragmentActivity = (MainActivity) requireActivity();
storiesService = StoriesService.getInstance();
} }
@Nullable @Nullable
@ -186,6 +191,12 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
fetchLocationModel(); fetchLocationModel();
} }
@Override
public void onResume() {
super.onResume();
setTitle();
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -287,17 +298,25 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
final String locationId = locationModel.getId(); final String locationId = locationModel.getId();
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
if (isLoggedIn) { if (isLoggedIn) {
new iStoryStatusFetcher( storiesService.getUserStory(locationId,
locationId,
null, null,
true, true,
false, false,
false, false,
stories -> { new ServiceCallback<List<StoryModel>>() {
if (stories != null && stories.length > 0) { @Override
public void onSuccess(final List<StoryModel> storyModels) {
if (storyModels != null && !storyModels.isEmpty()) {
binding.mainLocationImage.setStoriesBorder(); binding.mainLocationImage.setStoriesBorder();
hasStories = true;
} }
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t);
}
});
} }
binding.mainLocationImage.setImageURI(locationModel.getSdProfilePic()); binding.mainLocationImage.setImageURI(locationModel.getSdProfilePic());
final String postCount = String.valueOf(locationModel.getPostCount()); final String postCount = String.valueOf(locationModel.getPostCount());
@ -381,6 +400,15 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
.setAnchorView(fragmentActivity.getBottomNavView()) .setAnchorView(fragmentActivity.getBottomNavView())
.show(); .show();
}); });
binding.mainLocationImage.setOnClickListener(v -> {
if (hasStories) {
// show stories
final NavDirections action = LocationFragmentDirections
.actionLocationFragmentToStoryViewerFragment(-1, null, false, true, locationId, locationModel.getName());
NavHostFragment.findNavController(this).navigate(action);
return;
}
});
} }
private void fetchPosts() { private void fetchPosts() {

View File

@ -71,12 +71,12 @@ import awais.instagrabber.asyncs.direct_messages.CreateThreadAction;
import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster; import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster;
import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.customviews.helpers.SwipeGestureListener;
import awais.instagrabber.databinding.FragmentStoryViewerBinding; import awais.instagrabber.databinding.FragmentStoryViewerBinding;
import awais.instagrabber.fragments.main.ProfileFragmentDirections;
import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.interfaces.SwipeEvent;
import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.HighlightModel;
import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.models.enums.StoryViewerChoice;
import awais.instagrabber.models.stickers.PollModel; import awais.instagrabber.models.stickers.PollModel;
import awais.instagrabber.models.stickers.QuestionModel; import awais.instagrabber.models.stickers.QuestionModel;
import awais.instagrabber.models.stickers.QuizModel; import awais.instagrabber.models.stickers.QuizModel;
@ -115,7 +115,7 @@ public class StoryViewerFragment extends Fragment {
private StoryModel currentStory; private StoryModel currentStory;
private int slidePos; private int slidePos;
private int lastSlidePos; private int lastSlidePos;
private String url; private String url, username;
private PollModel poll; private PollModel poll;
private QuestionModel question; private QuestionModel question;
private String[] mentions; private String[] mentions;
@ -123,7 +123,7 @@ public class StoryViewerFragment extends Fragment {
private MenuItem menuDownload; private MenuItem menuDownload;
private MenuItem menuDm; private MenuItem menuDm;
private SimpleExoPlayer player; private SimpleExoPlayer player;
private boolean isHashtag; private boolean isHashtag, isLoc;
private String highlight; private String highlight;
private boolean fetching = false; private boolean fetching = false;
private int currentFeedStoryIndex; private int currentFeedStoryIndex;
@ -439,7 +439,7 @@ public class StoryViewerFragment extends Fragment {
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setTitle(R.string.story_mentions) .setTitle(R.string.story_mentions)
.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, mentions), (d, w) -> { .setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, mentions), (d, w) -> {
// searchUsername(mentions[w]); openProfile(mentions[w]);
}) })
.setPositiveButton(R.string.cancel, null) .setPositiveButton(R.string.cancel, null)
.show(); .show();
@ -479,7 +479,6 @@ public class StoryViewerFragment extends Fragment {
binding.imageViewer.setController(null); binding.imageViewer.setController(null);
releasePlayer(); releasePlayer();
String currentStoryMediaId = null; String currentStoryMediaId = null;
String username = null;
if (currentFeedStoryIndex >= 0) { if (currentFeedStoryIndex >= 0) {
if (isHighlight) { if (isHighlight) {
final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel;
@ -501,20 +500,13 @@ public class StoryViewerFragment extends Fragment {
username = fragmentArgs.getUsername(); username = fragmentArgs.getUsername();
} }
isHashtag = fragmentArgs.getIsHashtag(); isHashtag = fragmentArgs.getIsHashtag();
isLoc = fragmentArgs.getIsLoc();
final boolean hasUsername = !TextUtils.isEmpty(currentStoryUsername); final boolean hasUsername = !TextUtils.isEmpty(currentStoryUsername);
if (hasUsername) { if (hasUsername) {
currentStoryUsername = currentStoryUsername.replace("@", ""); currentStoryUsername = currentStoryUsername.replace("@", "");
final ActionBar actionBar = fragmentActivity.getSupportActionBar(); final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
actionBar.setTitle(currentStoryUsername); actionBar.setTitle(currentStoryUsername);
// actionBar.setOnClickListener(v -> {
// searchUsername(username);
// });
// if (isHighlight) {
// actionBar.setSubtitle(getString(R.string.title_highlight, highlight));
// } else {
// actionBar.setSubtitle(R.string.title_user_story);
// }
} }
} }
storiesViewModel.getList().setValue(Collections.emptyList()); storiesViewModel.getList().setValue(Collections.emptyList());
@ -542,8 +534,8 @@ public class StoryViewerFragment extends Fragment {
}; };
storiesService.getUserStory(currentStoryMediaId, storiesService.getUserStory(currentStoryMediaId,
username, username,
false, isLoc,
false, isHashtag,
isHighlight, isHighlight,
storyCallback); storyCallback);
} }
@ -596,14 +588,11 @@ public class StoryViewerFragment extends Fragment {
binding.quiz.setTag(quiz); binding.quiz.setTag(quiz);
releasePlayer(); releasePlayer();
if (isHashtag) { if (isHashtag || isLoc) {
final ActionBar actionBar = fragmentActivity.getSupportActionBar(); final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
actionBar.setTitle(currentStory.getUsername() + " (" + currentStoryUsername + ")"); actionBar.setTitle(currentStory.getUsername());
} }
// binding.toolbar.toolbar.setOnClickListener(v -> {
// searchUsername(currentStory.getUsername());
// });
} }
if (itemType == MediaItemType.MEDIA_TYPE_VIDEO) setupVideo(); if (itemType == MediaItemType.MEDIA_TYPE_VIDEO) setupVideo();
else setupImage(); else setupImage();
@ -755,6 +744,19 @@ public class StoryViewerFragment extends Fragment {
}); });
} }
private void openProfile(final String username) {
final char t = username.charAt(0);
Log.d("austin_debug", username);
if (t == '@') {
final NavDirections action = HashTagFragmentDirections.actionGlobalProfileFragment(username);
NavHostFragment.findNavController(this).navigate(action);
}
else if (t == '#') {
final NavDirections action = HashTagFragmentDirections.actionGlobalHashTagFragment(username.substring(1));
NavHostFragment.findNavController(this).navigate(action);
}
}
private void releasePlayer() { private void releasePlayer() {
if (player == null) return; if (player == null) return;
try { player.stop(true); } catch (Exception ignored) { } try { player.stop(true); } catch (Exception ignored) { }

View File

@ -371,7 +371,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private void setupFeedStories() { private void setupFeedStories() {
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter((model, position) -> { final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter((model, position) -> {
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false, null, null); final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false, false, null, null);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
}); });
final Context context = getContext(); final Context context = getContext();

View File

@ -74,7 +74,6 @@ import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.DownloadMethod; import awais.instagrabber.models.enums.DownloadMethod;
import awais.instagrabber.models.enums.FavoriteType; import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.models.enums.PostItemType; import awais.instagrabber.models.enums.PostItemType;
import awais.instagrabber.models.enums.StoryViewerChoice;
import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse; import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
import awais.instagrabber.repositories.responses.FriendshipRepoRestrictRootResponse; import awais.instagrabber.repositories.responses.FriendshipRepoRestrictRootResponse;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
@ -87,6 +86,7 @@ import awais.instagrabber.viewmodels.HighlightsViewModel;
import awais.instagrabber.viewmodels.PostsViewModel; import awais.instagrabber.viewmodels.PostsViewModel;
import awais.instagrabber.webservices.FriendshipService; import awais.instagrabber.webservices.FriendshipService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService;
import awaisomereport.LogCollector; import awaisomereport.LogCollector;
import static awais.instagrabber.utils.Utils.logCollector; import static awais.instagrabber.utils.Utils.logCollector;
@ -107,8 +107,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private ActionMode actionMode; private ActionMode actionMode;
private Handler usernameSettingHandler; private Handler usernameSettingHandler;
private FriendshipService friendshipService; private FriendshipService friendshipService;
private boolean shouldRefresh = true; private StoriesService storiesService;
private StoryModel[] storyModels; private boolean shouldRefresh = true, hasStories = false;
private boolean hasNextPage; private boolean hasNextPage;
private String endCursor; private String endCursor;
private AsyncTask<Void, Void, List<PostModel>> currentlyExecuting; private AsyncTask<Void, Void, List<PostModel>> currentlyExecuting;
@ -172,6 +172,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
binding.privatePage.setVisibility(View.VISIBLE); binding.privatePage.setVisibility(View.VISIBLE);
return; return;
} }
else {
binding.privatePage.setVisibility(View.GONE);
}
binding.mainPosts.post(() -> binding.mainPosts.setVisibility(View.VISIBLE)); binding.mainPosts.post(() -> binding.mainPosts.setVisibility(View.VISIBLE));
final List<PostModel> postModels = postsViewModel.getList().getValue(); final List<PostModel> postModels = postsViewModel.getList().getValue();
List<PostModel> finalList = postModels == null || postModels.isEmpty() ? new ArrayList<>() List<PostModel> finalList = postModels == null || postModels.isEmpty() ? new ArrayList<>()
@ -214,6 +217,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
fragmentActivity = (MainActivity) requireActivity(); fragmentActivity = (MainActivity) requireActivity();
friendshipService = FriendshipService.getInstance(); friendshipService = FriendshipService.getInstance();
storiesService = StoriesService.getInstance();
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@ -439,18 +443,28 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
} }
binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
final String profileId = profileModel.getId(); final String profileId = profileModel.getId();
final String myId = CookieUtils.getUserIdFromCookie(cookie);
if (isLoggedIn) { if (isLoggedIn) {
new iStoryStatusFetcher(profileId, storiesService.getUserStory(profileId,
profileModel.getUsername(), profileModel.getUsername(),
false, false,
false, false,
false, false,
result -> { new ServiceCallback<List<StoryModel>>() {
storyModels = result; @Override
if (result != null && result.length > 0) { public void onSuccess(final List<StoryModel> storyModels) {
if (storyModels != null && !storyModels.isEmpty()) {
binding.mainProfileImage.setStoriesBorder(); binding.mainProfileImage.setStoriesBorder();
hasStories = true;
} }
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t);
}
});
new HighlightsFetcher(profileId, new HighlightsFetcher(profileId,
result -> { result -> {
if (result != null) { if (result != null) {
@ -458,10 +472,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
highlightsViewModel.getList().postValue(result); highlightsViewModel.getList().postValue(result);
} else binding.highlightsList.setVisibility(View.GONE); } else binding.highlightsList.setVisibility(View.GONE);
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
final String myId = CookieUtils.getUserIdFromCookie(cookie);
if (isLoggedIn) {
if (profileId.equals(myId)) { if (profileId.equals(myId)) {
binding.btnTagged.setVisibility(View.VISIBLE); binding.btnTagged.setVisibility(View.VISIBLE);
binding.btnSaved.setVisibility(View.VISIBLE); binding.btnSaved.setVisibility(View.VISIBLE);
@ -675,7 +685,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}).execute(); }).execute();
}); });
binding.mainProfileImage.setOnClickListener(v -> { binding.mainProfileImage.setOnClickListener(v -> {
if (storyModels == null || storyModels.length <= 0) { if (!hasStories) {
// show profile pic // show profile pic
showProfilePicDialog(); showProfilePicDialog();
return; return;
@ -690,7 +700,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (which == 1) { if (which == 1) {
// show stories // show stories
final NavDirections action = ProfileFragmentDirections final NavDirections action = ProfileFragmentDirections
.actionProfileFragmentToStoryViewerFragment(-1, null, false, profileModel.getId(), username); .actionProfileFragmentToStoryViewerFragment(-1, null, false, false, profileModel.getId(), username);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
return; return;
} }
@ -819,7 +829,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
highlightsViewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class); highlightsViewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class);
highlightsAdapter = new HighlightsAdapter((model, position) -> { highlightsAdapter = new HighlightsAdapter((model, position) -> {
final NavDirections action = ProfileFragmentDirections final NavDirections action = ProfileFragmentDirections
.actionProfileFragmentToStoryViewerFragment(position, model.getTitle(), false, null, null); .actionProfileFragmentToStoryViewerFragment(position, model.getTitle(), false, false, null, null);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
}); });
final Context context = getContext(); final Context context = getContext();
@ -831,6 +841,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
} }
private void fetchPosts() { private void fetchPosts() {
Log.d("austin_debug", "fp");
stopCurrentExecutor(); stopCurrentExecutor();
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
currentlyExecuting = new PostsFetcher(profileModel.getId(), PostItemType.MAIN, endCursor, postsFetchListener) currentlyExecuting = new PostsFetcher(profileModel.getId(), PostItemType.MAIN, endCursor, postsFetchListener)

View File

@ -1,19 +0,0 @@
package awais.instagrabber.models.enums;
import java.io.Serializable;
public enum StoryViewerChoice implements Serializable {
NONE(0),
ALOINSTAGRAM(1),
INSTADP(2);
private int value;
StoryViewerChoice(int value) {
this.value = value;
}
public String getValue() {
return String.valueOf(value);
}
}

View File

@ -54,9 +54,9 @@ public final class Constants {
// spoof // spoof
public static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 8.1.0; motorola one Build/OPKS28.63-18-3; wv) " + public static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 8.1.0; motorola one Build/OPKS28.63-18-3; wv) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.80 Mobile Safari/537.36 " + "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.80 Mobile Safari/537.36 " +
"Instagram 156.0.0.26.109 Android (27/8.1.0; 320dpi; 720x1362; motorola; motorola one; deen_sprout; qcom; pt_BR; 240726452)"; "Instagram 160.0.0.25.132 Android (27/8.1.0; 320dpi; 720x1362; motorola; motorola one; deen_sprout; qcom; pt_BR; 246889068)";
public static final String I_USER_AGENT = public static final String I_USER_AGENT =
"Instagram 156.0.0.26.109 Android (27/8.1.0; 320dpi; 720x1362; motorola; motorola one; deen_sprout; qcom; pt_BR; 240726452)"; "Instagram 160.0.0.25.132 Android (27/8.1.0; 320dpi; 720x1362; motorola; motorola one; deen_sprout; qcom; pt_BR; 246889068)";
public static final String A_USER_AGENT = "https://InstaGrabber.AustinHuang.me / mailto:InstaGrabber@AustinHuang.me"; public static final String A_USER_AGENT = "https://InstaGrabber.AustinHuang.me / mailto:InstaGrabber@AustinHuang.me";
// see https://github.com/dilame/instagram-private-api/blob/master/src/core/constants.ts // see https://github.com/dilame/instagram-private-api/blob/master/src/core/constants.ts
public static final String SUPPORTED_CAPABILITIES = "[ { \"name\": \"SUPPORTED_SDK_VERSIONS\", \"value\":" + public static final String SUPPORTED_CAPABILITIES = "[ { \"name\": \"SUPPORTED_SDK_VERSIONS\", \"value\":" +

View File

@ -153,6 +153,7 @@ public class StoriesService extends BaseService {
model.setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_id")); model.setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_id"));
} }
// TODO: this may not be limited to spotify
if (!data.isNull("story_app_attribution")) if (!data.isNull("story_app_attribution"))
model.setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]); model.setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]);
@ -173,7 +174,7 @@ public class StoriesService extends BaseService {
)); ));
} }
if (data.has("story_questions")) { if (data.has("story_questions")) {
JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0).optJSONObject("question_sticker"); final JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0).optJSONObject("question_sticker");
if (tappableObject != null && !tappableObject.getString("question_type").equals("music")) if (tappableObject != null && !tappableObject.getString("question_type").equals("music"))
model.setQuestion(new QuestionModel( model.setQuestion(new QuestionModel(
String.valueOf(tappableObject.getLong("question_id")), String.valueOf(tappableObject.getLong("question_id")),
@ -229,6 +230,9 @@ public class StoriesService extends BaseService {
} }
callback.onSuccess(models); callback.onSuccess(models);
} }
else {
callback.onSuccess(null);
}
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "Error parsing string"); Log.e(TAG, "Error parsing string");
} }
@ -248,12 +252,13 @@ public class StoriesService extends BaseService {
if (isLoc) { if (isLoc) {
builder.append("locations/"); builder.append("locations/");
} }
if (isHashtag) { else if (isHashtag) {
builder.append("tags/"); builder.append("tags/");
} }
if (highlight) { else if (highlight) {
builder.append("feed/reels_media?user_ids="); builder.append("feed/reels_media?user_ids=");
} else { }
else {
builder.append("feed/user/"); builder.append("feed/user/");
} }
builder.append(userId); builder.append(userId);

View File

@ -20,8 +20,8 @@
<com.facebook.drawee.view.SimpleDraweeView <com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/ivMediaPreview" android:id="@+id/ivMediaPreview"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:maxHeight="@dimen/dm_media_img_max_height" /> android:maxHeight="@dimen/dm_media_img_max_height" />

View File

@ -98,6 +98,9 @@
<argument <argument
android:name="isHashtag" android:name="isHashtag"
app:argType="boolean" /> app:argType="boolean" />
<argument
android:name="isLoc"
app:argType="boolean" />
<argument <argument
android:name="profileId" android:name="profileId"
app:argType="string" app:argType="string"

View File

@ -19,6 +19,15 @@
app:argType="boolean" /> app:argType="boolean" />
</action> </action>
<action
android:id="@+id/action_global_profileFragment"
app:destination="@id/profile_nav_graph">
<argument
android:name="username"
app:argType="string"
app:nullable="false" />
</action>
<fragment <fragment
android:id="@+id/hashTagFragment" android:id="@+id/hashTagFragment"
android:name="awais.instagrabber.fragments.HashTagFragment" android:name="awais.instagrabber.fragments.HashTagFragment"
@ -28,6 +37,37 @@
android:name="hashtag" android:name="hashtag"
app:argType="string" app:argType="string"
app:nullable="false" /> app:nullable="false" />
<action
android:id="@+id/action_hashtagFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" />
</fragment>
<fragment
android:id="@+id/storyViewerFragment"
android:name="awais.instagrabber.fragments.StoryViewerFragment"
android:label="StoryViewerFragment"
tools:layout="@layout/fragment_story_viewer">
<argument
android:name="feedStoryIndex"
app:argType="integer"
app:nullable="false" />
<argument
android:name="highlight"
app:argType="string"
app:nullable="true" />
<argument
android:name="isHashtag"
app:argType="boolean" />
<argument
android:name="isLoc"
app:argType="boolean" />
<argument
android:name="profileId"
app:argType="string"
app:nullable="true" />
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
</fragment> </fragment>
<action <action
android:id="@+id/action_global_hashTagFragment" android:id="@+id/action_global_hashTagFragment"

View File

@ -30,6 +30,9 @@
android:name="locationId" android:name="locationId"
app:argType="string" app:argType="string"
app:nullable="false" /> app:nullable="false" />
<action
android:id="@+id/action_locationFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" />
</fragment> </fragment>
<action <action
android:id="@+id/action_global_locationFragment" android:id="@+id/action_global_locationFragment"
@ -39,4 +42,32 @@
app:argType="string" app:argType="string"
app:nullable="false" /> app:nullable="false" />
</action> </action>
<fragment
android:id="@+id/storyViewerFragment"
android:name="awais.instagrabber.fragments.StoryViewerFragment"
android:label="StoryViewerFragment"
tools:layout="@layout/fragment_story_viewer">
<argument
android:name="feedStoryIndex"
app:argType="integer"
app:nullable="false" />
<argument
android:name="highlight"
app:argType="string"
app:nullable="true" />
<argument
android:name="isHashtag"
app:argType="boolean" />
<argument
android:name="isLoc"
app:argType="boolean" />
<argument
android:name="profileId"
app:argType="string"
app:nullable="true" />
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
</fragment>
</navigation> </navigation>

View File

@ -139,6 +139,9 @@
<argument <argument
android:name="isHashtag" android:name="isHashtag"
app:argType="boolean" /> app:argType="boolean" />
<argument
android:name="isLoc"
app:argType="boolean" />
<argument <argument
android:name="profileId" android:name="profileId"
app:argType="string" app:argType="string"