From 18e38f652792d0ddf57cfa0146ed29e388b9d70c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 6 Jul 2020 15:40:29 +0800 Subject: Add two more comments in theme preview. --- .../Activity/ThemePreviewActivity.java | 26 ++++++++- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 2 +- .../Fragment/ThemePreviewCommentsFragment.java | 63 +++++++++++++++++++++- 3 files changed, 88 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java index ed20127b..79f1a8b3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java @@ -33,6 +33,7 @@ import com.google.android.material.chip.Chip; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; import com.r0adkll.slidr.Slidr; +import com.r0adkll.slidr.model.SlidrInterface; import java.util.ArrayList; @@ -115,6 +116,7 @@ public class ThemePreviewActivity extends AppCompatActivity { private int subscribedColor; private int systemVisibilityToolbarExpanded = 0; private int systemVisibilityToolbarCollapsed = 0; + private SlidrInterface mSlidrInterface; @Override protected void onCreate(Bundle savedInstanceState) { @@ -220,7 +222,7 @@ public class ThemePreviewActivity extends AppCompatActivity { applyCustomTheme(); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) { - Slidr.attach(this); + mSlidrInterface = Slidr.attach(this); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -307,6 +309,16 @@ public class ThemePreviewActivity extends AppCompatActivity { SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOffscreenPageLimit(2); + viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + if (position == 0) { + unlockSwipeRightToGoBack(); + } else { + lockSwipeRightToGoBack(); + } + } + }); tabLayout.setupWithViewPager(viewPager); } @@ -393,6 +405,18 @@ public class ThemePreviewActivity extends AppCompatActivity { return false; } + private void lockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.lock(); + } + } + + private void unlockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.unlock(); + } + } + private class SectionsPagerAdapter extends FragmentPagerAdapter { private ThemePreviewPostsFragment themePreviewPostsFragment; private ThemePreviewCommentsFragment themePreviewCommentsFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 9ffa7d11..1a02476c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -3126,7 +3126,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter