From d65a355bdce31a7c3659477ae786712f433b609c Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Fri, 28 Apr 2023 22:21:15 +0800 Subject: Fixed gallery images swipe gesture and Slidr gesture conflicts in all places. --- .../activities/AccountSavedThingActivity.java | 2 + .../infinityforreddit/activities/BaseActivity.java | 2 + .../activities/HistoryActivity.java | 2 + .../infinityforreddit/activities/MainActivity.java | 2 + .../activities/SearchResultActivity.java | 3 +- .../activities/ViewPostDetailActivity.java | 19 +----- .../activities/ViewSubredditDetailActivity.java | 2 + .../activities/ViewUserDetailActivity.java | 2 + .../CommentsListingRecyclerViewAdapter.java | 14 +---- .../adapters/HistoryPostRecyclerViewAdapter.java | 73 ++++++++++------------ .../adapters/PostDetailRecyclerViewAdapter.java | 27 +++++--- .../adapters/PostRecyclerViewAdapter.java | 73 ++++++++++------------ .../res/layout/item_gallery_image_in_post_feed.xml | 4 +- 13 files changed, 105 insertions(+), 120 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index 46c16e92..cc4e3eb6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -91,6 +91,8 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT mSliderPanel = Slidr.attach(this); } + mViewPager2 = binding.accountSavedThingViewPager2; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Window window = getWindow(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index 32cbdd4c..deebb612 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -73,6 +73,8 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo public Typeface contentTypeface; @Nullable public SliderPanel mSliderPanel; + @Nullable + public ViewPager2 mViewPager2; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java index 73ef6914..986e82f8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java @@ -94,6 +94,8 @@ public class HistoryActivity extends BaseActivity implements ActivityToolbarInte mSliderPanel = Slidr.attach(this); } + //mViewPager2 = viewPager2; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Window window = getWindow(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 4326a0a3..5b4f1ff5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -316,6 +316,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); toggle.syncState(); + mViewPager2 = viewPager2; + mBackButtonAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_BACK_BUTTON_ACTION, "0")); mLockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); mDisableSwipingBetweenTabs = mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index d31e8c34..2a9b3fe2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -63,7 +63,6 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchUserAndSu import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; -import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; @@ -158,6 +157,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect mSliderPanel = Slidr.attach(this); } + mViewPager2 = viewPager2; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Window window = getWindow(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 5ff1f7c4..2321b328 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -70,8 +70,6 @@ import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; import ml.docilealligator.infinityforreddit.comment.Comment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; -import ml.docilealligator.infinityforreddit.customviews.slidr.model.SlidrInterface; -import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel; import ml.docilealligator.infinityforreddit.events.NeedForPostListFromPostFragmentEvent; import ml.docilealligator.infinityforreddit.events.ProvidePostListToViewPostDetailActivityEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; @@ -186,7 +184,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele private boolean mVolumeKeysNavigateComments; private boolean isNsfwSubreddit; - @Override protected void onCreate(Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); @@ -240,6 +237,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele mSliderPanel = Slidr.attach(this); } viewPager2.setUserInputEnabled(false); + } else { + super.mViewPager2 = viewPager2; } postFragmentId = getIntent().getLongExtra(EXTRA_POST_FRAGMENT_ID, -1); if (swipeBetweenPosts && posts == null && postFragmentId > 0) { @@ -860,20 +859,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } - @Override - public void lockSwipeRightToGoBack() { - if (mSliderPanel != null) { - mSliderPanel.lock(); - } - } - - @Override - public void unlockSwipeRightToGoBack() { - if (mSliderPanel != null) { - mSliderPanel.unlock(); - } - } - @Override public void onLongPress() { ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 779a82a5..1c4e340e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -252,6 +252,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp mSliderPanel = Slidr.attach(this); } + mViewPager2 = viewPager2; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Window window = getWindow(); if (isImmersiveInterface()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index bbc78737..84eb24ff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -256,6 +256,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele mSliderPanel = Slidr.attach(this); } + mViewPager2 = viewPager2; + username = getIntent().getStringExtra(EXTRA_USER_NAME_KEY); fragmentManager = getSupportFragmentManager(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 51a60082..658fd10c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -40,12 +40,10 @@ import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; -import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; -import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CommentMoreBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.comment.Comment; @@ -506,20 +504,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { - if (mActivity.mSliderPanel != null) { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); - } else { + } + + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(true); + } + mActivity.unlockSwipeRightToGoBack(); + swipeLocked = false; + } else { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } + mActivity.lockSwipeRightToGoBack(); + swipeLocked = true; } return false; @@ -3168,25 +3180,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter { - if (mActivity.mSliderPanel != null) { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); - } else { + } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(true); + } + mActivity.unlockSwipeRightToGoBack(); + } else { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } + mActivity.lockSwipeRightToGoBack(); } return false; @@ -4239,18 +4243,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mActivity.mSliderPanel != null) { + mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); + } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(true); + } + mActivity.unlockSwipeRightToGoBack(); + } else { + if (mActivity.mSliderPanel != null) { + mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); + } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } mActivity.lockSwipeRightToGoBack(); } - @Override - public void unlockSwipe() { - mActivity.unlockSwipeRightToGoBack(); - } + return false; }); + LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false); galleryRecyclerView.setLayoutManager(layoutManager); galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 4c2e8c0d..ee94325f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -88,8 +88,7 @@ import ml.docilealligator.infinityforreddit.apis.StreamableAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; -import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; -import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; +import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.databinding.ItemPostCard2GalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryTypeBinding; @@ -3293,37 +3292,32 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - if (mActivity.mSliderPanel != null) { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); - } else { + } + + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(true); + } + mActivity.unlockSwipeRightToGoBack(); + swipeLocked = false; + } else { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } + mActivity.lockSwipeRightToGoBack(); + swipeLocked = true; } return false; }); new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView); galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool); - SwipeLockLinearLayoutManager layoutManager = new SwipeLockLinearLayoutManager( - mActivity, RecyclerView.HORIZONTAL, false, new SwipeLockInterface() { - @Override - public void lockSwipe() { - mActivity.lockSwipeRightToGoBack(); - swipeLocked = true; - } - - @Override - public void unlockSwipe() { - mActivity.unlockSwipeRightToGoBack(); - swipeLocked = false; - } - - @Override - public void setSwipeLocked(boolean swipeLocked) { - PostBaseGalleryTypeViewHolder.this.swipeLocked = swipeLocked; - } - }); + LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false); galleryRecyclerView.setLayoutManager(layoutManager); galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override @@ -4377,7 +4371,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - if (mActivity.mSliderPanel != null) { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); - } else { + } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(true); + } + mActivity.unlockSwipeRightToGoBack(); + } else { + if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } + mActivity.lockSwipeRightToGoBack(); } return false; @@ -4424,18 +4428,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter - - \ No newline at end of file + \ No newline at end of file -- cgit v1.2.3