From 3c32daaca2c3b3fbd826a927e60c87a57ef57ff2 Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 21:26:55 +0200 Subject: [PATCH] Add swap tap and long click option. --- .../CommentAndPostRecyclerViewAdapter.java | 65 ++++++++++++------- .../Utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + .../xml/gestures_and_buttons_preference.xml | 5 ++ 4 files changed, 47 insertions(+), 25 deletions(-) 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 674dff72..f2a12781 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -150,6 +150,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter authorTextView.performClick()); - View.OnClickListener hideToolbarOnClickListener = view -> { - if (mCommentToolbarHideOnClick) { - if (bottomConstraintLayout.getLayoutParams().height == 0) { - bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT; - topScoreTextView.setVisibility(View.GONE); - ((ViewPostDetailActivity) mActivity).delayTransition(); - } else { - ((ViewPostDetailActivity) mActivity).delayTransition(); - bottomConstraintLayout.getLayoutParams().height = 0; - topScoreTextView.setVisibility(View.VISIBLE); - } - } - }; - linearLayout.setOnClickListener(hideToolbarOnClickListener); - commentMarkdownView.setOnClickListener(hideToolbarOnClickListener); - commentTimeTextView.setOnClickListener(hideToolbarOnClickListener); - moreButton.setOnClickListener(view -> { CommentData comment = getCurrentComment(); Bundle bundle = new Bundle(); @@ -2961,15 +2946,45 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - expandButton.performClick(); - return true; - }); + if (mSwapTapAndLong) { + if (mCommentToolbarHideOnClick) { + View.OnLongClickListener hideToolbarOnLongClickListener = view -> hideToolbar(); + linearLayout.setOnLongClickListener(hideToolbarOnLongClickListener); + commentMarkdownView.setOnLongClickListener(hideToolbarOnLongClickListener); + commentTimeTextView.setOnLongClickListener(hideToolbarOnLongClickListener); + } + View.OnClickListener expandCommentsOnClickListener = view -> expandComments(); + commentMarkdownView.setOnClickListener(expandCommentsOnClickListener); + itemView.setOnClickListener(expandCommentsOnClickListener); + } else { + if (mCommentToolbarHideOnClick) { + View.OnClickListener hideToolbarOnClickListener = view -> hideToolbar(); + linearLayout.setOnClickListener(hideToolbarOnClickListener); + commentMarkdownView.setOnClickListener(hideToolbarOnClickListener); + commentTimeTextView.setOnClickListener(hideToolbarOnClickListener); + } + View.OnLongClickListener expandsCommentsOnLongClickListener = view -> expandComments(); + commentMarkdownView.setOnLongClickListener(expandsCommentsOnLongClickListener); + itemView.setOnLongClickListener(expandsCommentsOnLongClickListener); + } + } - itemView.setOnLongClickListener(view -> { - expandButton.performClick(); - return true; - }); + private boolean expandComments() { + expandButton.performClick(); + return true; + } + + private boolean hideToolbar() { + if (bottomConstraintLayout.getLayoutParams().height == 0) { + bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT; + topScoreTextView.setVisibility(View.GONE); + ((ViewPostDetailActivity) mActivity).delayTransition(); + } else { + ((ViewPostDetailActivity) mActivity).delayTransition(); + bottomConstraintLayout.getLayoutParams().height = 0; + topScoreTextView.setVisibility(View.VISIBLE); + } + return true; } private CommentData getCurrentComment() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 63ab550e..538e5899 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -81,6 +81,7 @@ public class SharedPreferencesUtils { public static final String VIDEO_AUTOPLAY_VALUE_ON_WIFI = "1"; public static final String VIDEO_AUTOPLAY_VALUE_NEVER = "0"; public static final String LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "lock_jump_to_next_top_level_comment_button"; + public static final String SWAP_TAP_AND_LONG_COMMENTS = "swap_tap_and_long_in_comments"; public static final String SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "swipe_up_to_hide_jump_to_next_top_level_comments_button"; public static final String SHOW_TOP_LEVEL_COMMENTS_FIRST = "show_top_level_comments_first"; public static final String CONFIRM_TO_EXIT = "confirm_to_exit"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c12d7105..52ec8509 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -336,6 +336,7 @@ Show Elapsed Time in Posts and Comments Default Post Layout Show Divider in Compact Layout + Swap Tap and Long Press in Comments Swipe Right to Go Back From Comments Lock Jump to Next Top-level Comment Button Lock Bottom Navigation Bar diff --git a/app/src/main/res/xml/gestures_and_buttons_preference.xml b/app/src/main/res/xml/gestures_and_buttons_preference.xml index 4d111187..8cd307e0 100644 --- a/app/src/main/res/xml/gestures_and_buttons_preference.xml +++ b/app/src/main/res/xml/gestures_and_buttons_preference.xml @@ -33,4 +33,9 @@ app:key="volume_keys_navigate_posts" app:title="@string/settings_volume_keys_navigate_posts_title" /> + + \ No newline at end of file