From d74c7f50fa95220671326d83314235ca8aacc428 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 29 Dec 2019 21:38:30 +0800 Subject: Prevent activity from sliding right when the markdown table is swiping left by user by using a custom LinearLayoutManager instead of setting the sensitivity of the Slidr library. --- .../Activity/ViewPostDetailActivity.java | 20 +++++++---- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 27 ++++++++++++-- .../CustomView/MarkwonLinearLayoutManager.java | 42 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/CustomView/MarkwonLinearLayoutManager.java (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index c51c2bc5..11cc629d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -37,7 +37,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import com.livefront.bridge.Bridge; import com.r0adkll.slidr.Slidr; -import com.r0adkll.slidr.model.SlidrConfig; +import com.r0adkll.slidr.model.SlidrInterface; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -176,7 +176,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS private LinearLayoutManager mLinearLayoutManager; private CommentAndPostRecyclerViewAdapter mAdapter; private RecyclerView.SmoothScroller mSmoothScroller; - private PostCommentSortTypeBottomSheetFragment postCommentSortTypeBottomSheetFragment; + private PostCommentSortTypeBottomSheetFragment mPostCommentSortTypeBottomSheetFragment; + private SlidrInterface mSlidrInterface; @Override protected void onCreate(Bundle savedInstanceState) { @@ -193,8 +194,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS EventBus.getDefault().register(this); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) { - SlidrConfig config = new SlidrConfig.Builder().sensitivity(0.1f).build(); - Slidr.attach(this, config); + mSlidrInterface = Slidr.attach(this); } Resources resources = getResources(); @@ -349,7 +349,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS postListPosition = getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, -1); } - postCommentSortTypeBottomSheetFragment = new PostCommentSortTypeBottomSheetFragment(); + mPostCommentSortTypeBottomSheetFragment = new PostCommentSortTypeBottomSheetFragment(); } @Override @@ -1306,7 +1306,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS return true; case R.id.action_sort_view_post_detail_activity: if (mPost != null) { - postCommentSortTypeBottomSheetFragment.show(getSupportFragmentManager(), postCommentSortTypeBottomSheetFragment.getTag()); + mPostCommentSortTypeBottomSheetFragment.show(getSupportFragmentManager(), mPostCommentSortTypeBottomSheetFragment.getTag()); } return true; case R.id.action_view_crosspost_parent_view_post_detail_activity: @@ -1524,4 +1524,12 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS fetchComments(false, false, sortType.getType().value); mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply(); } + + public void lockSwipeRightToGoBack() { + mSlidrInterface.lock(); + } + + public void unlockSwipeRightToGoBack() { + mSlidrInterface.unlock(); + } } 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 806d60a7..cd56c175 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -72,6 +72,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask import ml.docilealligator.infinityforreddit.AsyncTask.LoadUserDataAsyncTask; import ml.docilealligator.infinityforreddit.CommentData; import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView; +import ml.docilealligator.infinityforreddit.CustomView.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.FetchComment; import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment; import ml.docilealligator.infinityforreddit.Post; @@ -507,7 +508,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter