add #122 point 2

This commit is contained in:
Austin Huang 2020-11-04 13:02:23 -05:00
parent 66d5ec7c2f
commit bf9dcacd40
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
4 changed files with 55 additions and 16 deletions

View File

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

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.viewpager2.widget.ViewPager2 xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -116,12 +116,41 @@
</androidx.appcompat.widget.LinearLayoutCompat>
</FrameLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnBackward"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="40dp"
android:layout_height="0dp"
android:visibility="visible"
app:icon="@drawable/exo_ic_skip_previous"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/storiesList"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/storiesList" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/storiesList"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:layout_constraintTop_toBottomOf="@id/story_container"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/btnForward"
app:layout_constraintStart_toEndOf="@id/btnBackward" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnForward"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="40dp"
android:layout_height="0dp"
android:visibility="visible"
app:icon="@drawable/exo_ic_skip_next"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toEndOf="@id/storiesList"
app:layout_constraintTop_toTopOf="@id/storiesList" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -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">
<com.facebook.drawee.view.SimpleDraweeView