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

v16.6-a8: INFINITE STORY SCROLL

This commit is contained in:
Austin Huang 2020-07-21 19:54:42 -04:00
parent be45f52f7e
commit eb387d9c81
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
5 changed files with 59 additions and 8 deletions

View File

@ -10,7 +10,7 @@ android {
targetSdkVersion 29 targetSdkVersion 29
versionCode 27 versionCode 27
versionName '16.6-a7' versionName '16.6-a8'
multiDexEnabled true multiDexEnabled true

View File

@ -88,6 +88,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
private static AsyncTask<?, ?, ?> currentlyExecuting; private static AsyncTask<?, ?, ?> currentlyExecuting;
private AsyncTask<Void, Void, FeedStoryModel[]> prevStoriesFetcher; private AsyncTask<Void, Void, FeedStoryModel[]> prevStoriesFetcher;
private final boolean autoloadPosts; private final boolean autoloadPosts;
private FeedStoryModel[] stories;
private boolean hasNextPage = false, feedHasNextPage = false, discoverHasMore = false; private boolean hasNextPage = false, feedHasNextPage = false, discoverHasMore = false;
private String endCursor = null, feedEndCursor = null, discoverEndMaxId = null; private String endCursor = null, feedEndCursor = null, discoverEndMaxId = null;
private final FetchListener<PostModel[]> postsFetchListener = new FetchListener<PostModel[]>() { private final FetchListener<PostModel[]> postsFetchListener = new FetchListener<PostModel[]>() {
@ -206,6 +207,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
feedStoriesAdapter.setData(result); feedStoriesAdapter.setData(result);
if (result != null && result.length > 0) if (result != null && result.length > 0)
main.mainBinding.feedStories.setVisibility(View.VISIBLE); main.mainBinding.feedStories.setVisibility(View.VISIBLE);
stories = result;
} }
}; };
private final MentionClickListener mentionClickListener = new MentionClickListener() { private final MentionClickListener mentionClickListener = new MentionClickListener() {
@ -224,10 +226,13 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
if (tag instanceof FeedStoryModel) { if (tag instanceof FeedStoryModel) {
final FeedStoryModel feedStoryModel = (FeedStoryModel) tag; final FeedStoryModel feedStoryModel = (FeedStoryModel) tag;
final StoryModel[] storyModels = feedStoryModel.getStoryModels(); final StoryModel[] storyModels = feedStoryModel.getStoryModels();
final int index = indexOfIntArray(stories, feedStoryModel);
main.startActivity(new Intent(main, StoryViewer.class) main.startActivity(new Intent(main, StoryViewer.class)
.putExtra(Constants.EXTRAS_STORIES, storyModels) .putExtra(Constants.EXTRAS_STORIES, storyModels)
.putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) .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(); 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;
}
} }

View File

@ -215,7 +215,7 @@ public final class Main extends BaseLanguageActivity {
final boolean isQueryNull = userQuery == null; final boolean isQueryNull = userQuery == null;
if (isQueryNull) allItems.clear(); 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(); if (!mainBinding.swipeRefreshLayout.isRefreshing() && userQuery != null) mainHelper.onRefresh();
mainHelper.onIntent(getIntent()); mainHelper.onIntent(getIntent());

View File

@ -46,6 +46,7 @@ import awais.instagrabber.asyncs.DownloadAsync;
import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.customviews.helpers.SwipeGestureListener;
import awais.instagrabber.databinding.ActivityStoryViewerBinding; import awais.instagrabber.databinding.ActivityStoryViewerBinding;
import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.interfaces.SwipeEvent;
import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.PostModel; import awais.instagrabber.models.PostModel;
import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.MediaItemType;
@ -121,6 +122,26 @@ public final class StoryViewer extends BaseLanguageActivity {
@Override @Override
public void onSwipe(final boolean isRightSwipe) { public void onSwipe(final boolean isRightSwipe) {
if (storyModels != null && storiesLen > 0) { if (storyModels != null && storiesLen > 0) {
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 (isRightSwipe) {
if (--slidePos <= 0) slidePos = 0; if (--slidePos <= 0) slidePos = 0;
} else if (++slidePos >= storiesLen) slidePos = storiesLen - 1; } else if (++slidePos >= storiesLen) slidePos = storiesLen - 1;
@ -130,6 +151,7 @@ public final class StoryViewer extends BaseLanguageActivity {
refreshStory(); refreshStory();
} }
} }
}
}; };
gestureDetector = new GestureDetectorCompat(this, new SwipeGestureListener(swipeEvent)); gestureDetector = new GestureDetectorCompat(this, new SwipeGestureListener(swipeEvent));
@ -364,4 +386,15 @@ public final class StoryViewer extends BaseLanguageActivity {
player = null; 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;
}
} }

View File

@ -38,6 +38,8 @@ public final class Constants {
public static final String EXTRAS_FOLLOWERS = "followers"; public static final String EXTRAS_FOLLOWERS = "followers";
public static final String EXTRAS_SHORTCODE = "shortcode"; public static final String EXTRAS_SHORTCODE = "shortcode";
public static final String EXTRAS_END_CURSOR = "endCursor"; public static final String EXTRAS_END_CURSOR = "endCursor";
public static final String FEED = "feed";
public static final String FEED_ORDER = "feedOrder";
//////////////////////// EXTRAS //////////////////////// //////////////////////// EXTRAS ////////////////////////
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 " +