diff options
author | Docile-Alligator <chineseperson5@gmail.com> | 2020-06-20 04:24:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-20 04:24:58 +0000 |
commit | 02af3edd094955802bd063d2f79ceb2bd21b2e8b (patch) | |
tree | 480f224b7475cd713265b65e226baafda7e7ff03 /app | |
parent | f3862e1c8ad10f0019ad18c733012029494ba078 (diff) | |
parent | cad9912edaa2c7ce4e6714b36c3b58a0f6ab2560 (diff) | |
download | infinity-for-reddit-02af3edd094955802bd063d2f79ceb2bd21b2e8b.tar infinity-for-reddit-02af3edd094955802bd063d2f79ceb2bd21b2e8b.tar.gz infinity-for-reddit-02af3edd094955802bd063d2f79ceb2bd21b2e8b.tar.bz2 infinity-for-reddit-02af3edd094955802bd063d2f79ceb2bd21b2e8b.tar.lz infinity-for-reddit-02af3edd094955802bd063d2f79ceb2bd21b2e8b.tar.xz infinity-for-reddit-02af3edd094955802bd063d2f79ceb2bd21b2e8b.tar.zst infinity-for-reddit-02af3edd094955802bd063d2f79ceb2bd21b2e8b.zip |
Merge pull request #133 from OHermesJunior/fix-slide
Fix swipe on two missed activities.
Diffstat (limited to '')
2 files changed, 46 insertions, 12 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java index 52a3d489..42e89abc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -22,6 +22,7 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.tabs.TabLayout; import com.r0adkll.slidr.Slidr; +import com.r0adkll.slidr.model.SlidrInterface; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -76,6 +77,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT @Inject CustomThemeWrapper mCustomThemeWrapper; private SectionsPagerAdapter sectionsPagerAdapter; + private SlidrInterface mSlidrInterface; private Menu mMenu; private AppBarLayout.LayoutParams params; private boolean mNullAccessToken = false; @@ -98,7 +100,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT 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) { @@ -179,12 +181,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT viewPager.setOffscreenPageLimit(2); tabLayout.setupWithViewPager(viewPager); - viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - + viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (isInLazyMode) { @@ -194,11 +191,12 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT sectionsPagerAdapter.pauseLazyMode(); } } - } - - @Override - public void onPageScrollStateChanged(int state) { + if (position == 0) { + unlockSwipeRightToGoBack(); + } else { + lockSwipeRightToGoBack(); + } } }); } @@ -290,6 +288,18 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT } } + private void lockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.lock(); + } + } + + private void unlockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.unlock(); + } + } + private class SectionsPagerAdapter extends FragmentPagerAdapter { private PostFragment postFragment; private CommentsListingFragment commentsListingFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java index 4546ac10..994d19e7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -21,6 +21,7 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.tabs.TabLayout; import com.r0adkll.slidr.Slidr; +import com.r0adkll.slidr.model.SlidrInterface; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -86,6 +87,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti SharedPreferences mSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + private SlidrInterface mSlidrInterface; private boolean mNullAccessToken = false; private String mAccessToken; private String mAccountName; @@ -109,7 +111,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti 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) { @@ -179,6 +181,16 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOffscreenPageLimit(3); + viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + if (position == 0) { + unlockSwipeRightToGoBack(); + } else { + lockSwipeRightToGoBack(); + } + } + }); tabLayout.setupWithViewPager(viewPager); if (showMultiReddits) { @@ -316,6 +328,18 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } } + private void lockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.lock(); + } + } + + private void unlockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.unlock(); + } + } + private class SectionsPagerAdapter extends FragmentPagerAdapter { private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment; |