From bf9dcacd40c38d865a8db495ef9bc85ee5859e0f Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Wed, 4 Nov 2020 13:02:23 -0500 Subject: [PATCH] add #122 point 2 --- .../fragments/StoryViewerFragment.java | 32 +++++++++++++----- .../main/res/layout/fragment_post_view.xml | 4 --- .../main/res/layout/fragment_story_viewer.xml | 33 +++++++++++++++++-- app/src/main/res/layout/item_story.xml | 2 +- 4 files changed, 55 insertions(+), 16 deletions(-) delete mode 100644 app/src/main/res/layout/fragment_post_view.xml diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index c0bb18c5..aa9ae2bd 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -319,15 +319,7 @@ public class StoryViewerFragment extends Fragment { final Object feedStoryModel = isRightSwipe ? finalModels.get(index - 1) : finalModels.size() == index + 1 ? null : finalModels.get(index + 1); - if (feedStoryModel != null) { - if (fetching) { - Toast.makeText(context, R.string.be_patient, Toast.LENGTH_SHORT).show(); - return; - } - fetching = true; - currentFeedStoryIndex = isRightSwipe ? (index - 1) : (index + 1); - resetView(); - } + paginateStories(feedStoryModel, context, isRightSwipe, currentFeedStoryIndex == finalModels.size() - 2); return; } if (isRightSwipe) { @@ -362,6 +354,14 @@ public class StoryViewerFragment extends Fragment { return false; } }; + + if (hasFeedStories) { + binding.btnBackward.setVisibility(currentFeedStoryIndex == 0 ? View.INVISIBLE : View.VISIBLE); + binding.btnForward.setVisibility(currentFeedStoryIndex == finalModels.size() - 1 ? View.INVISIBLE : View.VISIBLE); + binding.btnBackward.setOnClickListener(v -> paginateStories(finalModels.get(currentFeedStoryIndex - 1), context, true, false)); + binding.btnForward.setOnClickListener(v -> paginateStories(finalModels.get(currentFeedStoryIndex + 1), context, false, currentFeedStoryIndex == finalModels.size() - 2)); + } + binding.imageViewer.setTapListener(simpleOnGestureListener); binding.spotify.setOnClickListener(v -> { final Object tag = v.getTag(); @@ -780,4 +780,18 @@ public class StoryViewerFragment extends Fragment { try { player.release(); } catch (Exception ignored) { } player = null; } + + private void paginateStories(Object feedStory, Context context, boolean backward, boolean last) { + if (feedStory != null) { + if (fetching) { + Toast.makeText(context, R.string.be_patient, Toast.LENGTH_SHORT).show(); + return; + } + fetching = true; + binding.btnBackward.setVisibility(currentFeedStoryIndex == 1 && backward ? View.INVISIBLE : View.VISIBLE); + binding.btnForward.setVisibility(last ? View.INVISIBLE : View.VISIBLE); + currentFeedStoryIndex = backward ? (currentFeedStoryIndex - 1) : (currentFeedStoryIndex + 1); + resetView(); + } + } } diff --git a/app/src/main/res/layout/fragment_post_view.xml b/app/src/main/res/layout/fragment_post_view.xml deleted file mode 100644 index 7ce45884..00000000 --- a/app/src/main/res/layout/fragment_post_view.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_story_viewer.xml b/app/src/main/res/layout/fragment_story_viewer.xml index d666260f..fb16343a 100644 --- a/app/src/main/res/layout/fragment_story_viewer.xml +++ b/app/src/main/res/layout/fragment_story_viewer.xml @@ -116,12 +116,41 @@ + + + + + app:layout_constraintStart_toEndOf="@id/storiesList" + app:layout_constraintTop_toTopOf="@id/storiesList" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_story.xml b/app/src/main/res/layout/item_story.xml index be2bd4ee..94044d02 100755 --- a/app/src/main/res/layout/item_story.xml +++ b/app/src/main/res/layout/item_story.xml @@ -5,7 +5,7 @@ android:layout_height="@dimen/story_item_height" android:clickable="true" android:focusable="true" - android:layout_margin="8dp" + android:layout_margin="4dp" android:foreground="?android:selectableItemBackground">