aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-10-22 20:27:56 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-10-22 20:27:56 +0000
commit66d146a34aa54b72dbc22d51a4af255516f4e050 (patch)
tree1566a39d445854de5d38de1a918c8aabdae8cf1a /app
parent451a5947fd318f01eee53960c2249bc10d205c33 (diff)
downloadinfinity-for-reddit-66d146a34aa54b72dbc22d51a4af255516f4e050.tar
infinity-for-reddit-66d146a34aa54b72dbc22d51a4af255516f4e050.tar.gz
infinity-for-reddit-66d146a34aa54b72dbc22d51a4af255516f4e050.tar.bz2
infinity-for-reddit-66d146a34aa54b72dbc22d51a4af255516f4e050.tar.lz
infinity-for-reddit-66d146a34aa54b72dbc22d51a4af255516f4e050.tar.xz
infinity-for-reddit-66d146a34aa54b72dbc22d51a4af255516f4e050.tar.zst
infinity-for-reddit-66d146a34aa54b72dbc22d51a4af255516f4e050.zip
Refine ItemTouchHelper onChildDraw in PostFragmentBase.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java88
1 files changed, 43 insertions, 45 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java
index 7a7c2a67..c2e0a470 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java
@@ -248,58 +248,56 @@ public abstract class PostFragmentBase extends Fragment {
@Override
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
- if (isCurrentlyActive) {
- View itemView = viewHolder.itemView;
- int horizontalOffset = (int) Utils.convertDpToPixel(16, activity);
- if (dX > 0) {
- if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
- dX = (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold;
- if (!exceedThreshold) {
- exceedThreshold = true;
- if (vibrateWhenActionTriggered) {
- viewHolder.itemView.setHapticFeedbackEnabled(true);
- viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
- }
+ View itemView = viewHolder.itemView;
+ int horizontalOffset = (int) Utils.convertDpToPixel(16, activity);
+ if (dX > 0) {
+ if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
+ dX = (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold;
+ if (!exceedThreshold && isCurrentlyActive) {
+ exceedThreshold = true;
+ if (vibrateWhenActionTriggered) {
+ viewHolder.itemView.setHapticFeedbackEnabled(true);
+ viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
- backgroundSwipeRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
- } else {
- exceedThreshold = false;
- backgroundSwipeRight.setBounds(0, 0, 0, 0);
}
+ backgroundSwipeRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
+ } else {
+ exceedThreshold = false;
+ backgroundSwipeRight.setBounds(0, 0, 0, 0);
+ }
- drawableSwipeRight.setBounds(itemView.getLeft() + ((int) dX) - horizontalOffset - drawableSwipeRight.getIntrinsicWidth(),
- (itemView.getBottom() + itemView.getTop() - drawableSwipeRight.getIntrinsicHeight()) / 2,
- itemView.getLeft() + ((int) dX) - horizontalOffset,
- (itemView.getBottom() + itemView.getTop() + drawableSwipeRight.getIntrinsicHeight()) / 2);
- backgroundSwipeRight.draw(c);
- drawableSwipeRight.draw(c);
- } else if (dX < 0) {
- if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
- dX = -(viewHolder.itemView.getRight() - viewHolder.itemView.getLeft()) * swipeActionThreshold;
- if (!exceedThreshold) {
- exceedThreshold = true;
- if (vibrateWhenActionTriggered) {
- viewHolder.itemView.setHapticFeedbackEnabled(true);
- viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
- }
+ drawableSwipeRight.setBounds(itemView.getLeft() + ((int) dX) - horizontalOffset - drawableSwipeRight.getIntrinsicWidth(),
+ (itemView.getBottom() + itemView.getTop() - drawableSwipeRight.getIntrinsicHeight()) / 2,
+ itemView.getLeft() + ((int) dX) - horizontalOffset,
+ (itemView.getBottom() + itemView.getTop() + drawableSwipeRight.getIntrinsicHeight()) / 2);
+ backgroundSwipeRight.draw(c);
+ drawableSwipeRight.draw(c);
+ } else if (dX < 0) {
+ if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
+ dX = -(viewHolder.itemView.getRight() - viewHolder.itemView.getLeft()) * swipeActionThreshold;
+ if (!exceedThreshold && isCurrentlyActive) {
+ exceedThreshold = true;
+ if (vibrateWhenActionTriggered) {
+ viewHolder.itemView.setHapticFeedbackEnabled(true);
+ viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
- backgroundSwipeLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
- } else {
- exceedThreshold = false;
- backgroundSwipeLeft.setBounds(0, 0, 0, 0);
}
- drawableSwipeLeft.setBounds(itemView.getRight() + ((int) dX) + horizontalOffset,
- (itemView.getBottom() + itemView.getTop() - drawableSwipeLeft.getIntrinsicHeight()) / 2,
- itemView.getRight() + ((int) dX) + horizontalOffset + drawableSwipeLeft.getIntrinsicWidth(),
- (itemView.getBottom() + itemView.getTop() + drawableSwipeLeft.getIntrinsicHeight()) / 2);
- backgroundSwipeLeft.draw(c);
- drawableSwipeLeft.draw(c);
- }
- } else {
- if (exceedThreshold && getPostAdapter() != null) {
- getPostAdapter().onItemSwipe(viewHolder, dX > 0 ? ItemTouchHelper.END : ItemTouchHelper.START, swipeLeftAction, swipeRightAction);
+ backgroundSwipeLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
+ } else {
exceedThreshold = false;
+ backgroundSwipeLeft.setBounds(0, 0, 0, 0);
}
+ drawableSwipeLeft.setBounds(itemView.getRight() + ((int) dX) + horizontalOffset,
+ (itemView.getBottom() + itemView.getTop() - drawableSwipeLeft.getIntrinsicHeight()) / 2,
+ itemView.getRight() + ((int) dX) + horizontalOffset + drawableSwipeLeft.getIntrinsicWidth(),
+ (itemView.getBottom() + itemView.getTop() + drawableSwipeLeft.getIntrinsicHeight()) / 2);
+ backgroundSwipeLeft.draw(c);
+ drawableSwipeLeft.draw(c);
+ }
+
+ if (!isCurrentlyActive && exceedThreshold && getPostAdapter() != null) {
+ getPostAdapter().onItemSwipe(viewHolder, dX > 0 ? ItemTouchHelper.END : ItemTouchHelper.START, swipeLeftAction, swipeRightAction);
+ exceedThreshold = false;
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}