diff --git a/app/build.gradle b/app/build.gradle index 190cd7de..dbc5f87d 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { targetSdkVersion 29 versionCode 27 - versionName '16.6-a7' + versionName '16.6-a8' multiDexEnabled true diff --git a/app/src/main/java/awais/instagrabber/MainHelper.java b/app/src/main/java/awais/instagrabber/MainHelper.java index 20193206..3c8aa786 100755 --- a/app/src/main/java/awais/instagrabber/MainHelper.java +++ b/app/src/main/java/awais/instagrabber/MainHelper.java @@ -88,6 +88,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { private static AsyncTask currentlyExecuting; private AsyncTask prevStoriesFetcher; private final boolean autoloadPosts; + private FeedStoryModel[] stories; private boolean hasNextPage = false, feedHasNextPage = false, discoverHasMore = false; private String endCursor = null, feedEndCursor = null, discoverEndMaxId = null; private final FetchListener postsFetchListener = new FetchListener() { @@ -206,6 +207,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { feedStoriesAdapter.setData(result); if (result != null && result.length > 0) main.mainBinding.feedStories.setVisibility(View.VISIBLE); + stories = result; } }; private final MentionClickListener mentionClickListener = new MentionClickListener() { @@ -224,10 +226,13 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { if (tag instanceof FeedStoryModel) { final FeedStoryModel feedStoryModel = (FeedStoryModel) tag; final StoryModel[] storyModels = feedStoryModel.getStoryModels(); + final int index = indexOfIntArray(stories, feedStoryModel); main.startActivity(new Intent(main, StoryViewer.class) .putExtra(Constants.EXTRAS_STORIES, storyModels) .putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) + .putExtra(Constants.FEED, stories) + .putExtra(Constants.FEED_ORDER, index) ); } } @@ -861,4 +866,15 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { currentFeedPlayer.getPlaybackState(); } } + + public static int indexOfIntArray(Object[] array, Object key) { + int returnvalue = -1; + for (int i = 0; i < array.length; ++i) { + if (key == array[i]) { + returnvalue = i; + break; + } + } + return returnvalue; + } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/activities/Main.java b/app/src/main/java/awais/instagrabber/activities/Main.java index 188abc6d..69963e9e 100755 --- a/app/src/main/java/awais/instagrabber/activities/Main.java +++ b/app/src/main/java/awais/instagrabber/activities/Main.java @@ -215,7 +215,7 @@ public final class Main extends BaseLanguageActivity { final boolean isQueryNull = userQuery == null; if (isQueryNull) allItems.clear(); - if (BuildConfig.DEBUG && isQueryNull) userQuery = "the.badak"; // todo + if (BuildConfig.DEBUG && isQueryNull) userQuery = "austinhuang.me"; if (!mainBinding.swipeRefreshLayout.isRefreshing() && userQuery != null) mainHelper.onRefresh(); mainHelper.onIntent(getIntent()); diff --git a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java index 6128dd16..bd747c45 100755 --- a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java @@ -46,6 +46,7 @@ import awais.instagrabber.asyncs.DownloadAsync; import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.ActivityStoryViewerBinding; import awais.instagrabber.interfaces.SwipeEvent; +import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.PostModel; import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.enums.MediaItemType; @@ -121,13 +122,34 @@ public final class StoryViewer extends BaseLanguageActivity { @Override public void onSwipe(final boolean isRightSwipe) { if (storyModels != null && storiesLen > 0) { - if (isRightSwipe) { - if (--slidePos <= 0) slidePos = 0; - } else if (++slidePos >= storiesLen) slidePos = storiesLen - 1; - - currentStory = storyModels[slidePos]; - slidePos = currentStory.getPosition(); - refreshStory(); + if (((slidePos == storiesLen - 1 && isRightSwipe == false) || (slidePos == 0 && isRightSwipe == true)) + && intent.hasExtra(Constants.FEED)) { + final FeedStoryModel[] storyFeed = (FeedStoryModel[]) intent.getSerializableExtra(Constants.FEED); + final int index = intent.getIntExtra(Constants.FEED_ORDER, 1738); + final FeedStoryModel feedStoryModel = isRightSwipe ? + (storyFeed.length == 0 ? null : storyFeed[index-1]) : + (storyFeed.length == index+1 ? null : storyFeed[index+1]); + final StoryModel[] nextStoryModels = feedStoryModel.getStoryModels(); + + if (feedStoryModel != null) { + final Intent newIntent = new Intent(getApplicationContext(), StoryViewer.class) + .putExtra(Constants.EXTRAS_STORIES, nextStoryModels) + .putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) + .putExtra(Constants.FEED, storyFeed) + .putExtra(Constants.FEED_ORDER, isRightSwipe ? (index-1) : (index+1)); + newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(newIntent); + } + } + else { + if (isRightSwipe) { + if (--slidePos <= 0) slidePos = 0; + } else if (++slidePos >= storiesLen) slidePos = storiesLen - 1; + + currentStory = storyModels[slidePos]; + slidePos = currentStory.getPosition(); + refreshStory(); + } } } }; @@ -364,4 +386,15 @@ public final class StoryViewer extends BaseLanguageActivity { player = null; } } + + public static int indexOfIntArray(Object[] array, Object key) { + int returnvalue = -1; + for (int i = 0; i < array.length; ++i) { + if (key == array[i]) { + returnvalue = i; + break; + } + } + return returnvalue; + } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index 3286aed2..ccda3664 100755 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -38,6 +38,8 @@ public final class Constants { public static final String EXTRAS_FOLLOWERS = "followers"; public static final String EXTRAS_SHORTCODE = "shortcode"; public static final String EXTRAS_END_CURSOR = "endCursor"; + public static final String FEED = "feed"; + public static final String FEED_ORDER = "feedOrder"; //////////////////////// EXTRAS //////////////////////// 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 " +