From 18e38f652792d0ddf57cfa0146ed29e388b9d70c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 6 Jul 2020 15:40:29 +0800 Subject: [PATCH] Add two more comments in theme preview. --- .../Activity/ThemePreviewActivity.java | 26 +- .../CommentAndPostRecyclerViewAdapter.java | 2 +- .../ThemePreviewCommentsFragment.java | 63 +++- .../fragment_theme_preview_comments.xml | 269 +++++++++++++++++- .../layout/item_comment_fully_collapsed.xml | 2 +- 5 files changed, 356 insertions(+), 6 deletions(-) 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_comment_fully_collapsed.xml b/app/src/main/res/layout/item_comment_fully_collapsed.xml index d6e5110c..f572c49f 100644 --- a/app/src/main/res/layout/item_comment_fully_collapsed.xml +++ b/app/src/main/res/layout/item_comment_fully_collapsed.xml @@ -51,7 +51,7 @@