From 5e3eaafe268fc64e8c7d92187e6c2447addc410d Mon Sep 17 00:00:00 2001 From: Sergei Kozelko Date: Sat, 22 Oct 2022 13:37:31 +0700 Subject: Add view that can lock swipe-to-close gesture (#1140) Slidr works by adding its own view in the hierarchy and listening to touch events in `onInterceptTouchEvent`. Once it detects movement in the correct direction, it returns `true` and handles all the events itself. Adding scrollable view detection to Slidr would solve the problem, but it is not possible and would probably have performance impact. Fortunately Slidr does not intercept the very first event, which is ACTION_DOWN, and it reaches scrollable view. So the scrollable view itself can decide if it should disallow the swipe. This also has a performance benefit over `OnScrollChangedListener` because the listener is triggered for every scroll of every view even if the child we are interested in did not scroll. On the other hand `on(Intercept)TouchEvent` is triggered only when the view is touched. There is a possibility that swipe won't be unlocked if view never receives ACTION_UP or ACTION_CANCEL. However the docs say nothing about the probability of this happening. Anyways, one possible solution is to post a runnable that will unlock swipe soon after locking. --- .../activities/FullMarkdownActivity.java | 7 +- .../infinityforreddit/activities/WikiActivity.java | 7 +- .../CommentsListingRecyclerViewAdapter.java | 7 +- .../adapters/CommentsRecyclerViewAdapter.java | 7 +- .../adapters/PostDetailRecyclerViewAdapter.java | 7 +- .../adapters/RulesRecyclerViewAdapter.java | 7 +- .../customviews/MarkwonLinearLayoutManager.java | 32 +++------ .../customviews/SwipeLockScrollView.java | 78 ++++++++++++++++++++++ app/src/main/res/layout/adapter_table_block.xml | 5 +- 9 files changed, 114 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 782441dc..2ded838c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -42,6 +42,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -150,16 +151,16 @@ public class FullMarkdownActivity extends BaseActivity { miscPlugin, markdownColor, spoilerBackgroundColor, null); MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(); - LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { + LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new SwipeLockScrollView.SwipeLockInterface() { @Override - public void onScrolledLeft() { + public void lockSwipe() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } @Override - public void onScrolledRight() { + public void unlockSwipe() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 8f8e902b..6cb65b28 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -51,6 +51,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSh import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.utils.JSONUtils; @@ -183,16 +184,16 @@ public class WikiActivity extends BaseActivity { miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); markwonAdapter = MarkdownUtils.createTablesAdapter(); - LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { + LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new SwipeLockScrollView.SwipeLockInterface() { @Override - public void onScrolledLeft() { + public void lockSwipe() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } @Override - public void onScrolledRight() { + public void unlockSwipe() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); } 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 1782a0a4..1503a469 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -55,6 +55,7 @@ import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -507,9 +508,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter - - \ No newline at end of file + -- cgit v1.2.3