diff options
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java | 7 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java | 34 |
2 files changed, 32 insertions, 9 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 13fa5d90..7c7d8f53 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -10,7 +10,6 @@ import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -511,12 +510,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView switch (post.getVoteType()) { case 1: //Upvoted - Log.i("asdasdf", "upvoted"); ((PostBaseViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); break; case -1: - Log.i("asdasdf", "downvoted"); //Downvoted ((PostBaseViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); @@ -1527,14 +1524,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (previousVoteType != 1) { //Not upvoted before - Log.i("asdasdf", "not 1 before"); post.setVoteType(1); newVoteType = APIUtils.DIR_UPVOTE; upvoteButton .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); scoreTextView.setTextColor(mUpvotedColor); } else { - Log.i("asdasdf", "1 before"); //Upvoted before post.setVoteType(0); newVoteType = APIUtils.DIR_UNVOTE; @@ -1548,13 +1543,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView @Override public void onVoteThingSuccess(int position1) { if (newVoteType.equals(APIUtils.DIR_UPVOTE)) { - Log.i("asdasdf", "1"); post.setVoteType(1); upvoteButton .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); scoreTextView.setTextColor(mUpvotedColor); } else { - Log.i("asdasdf", "0"); post.setVoteType(0); upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); scoreTextView.setTextColor(mPostIconAndInfoColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index fe33e43a..7727964a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -14,6 +14,8 @@ import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; +import android.os.VibrationEffect; +import android.os.Vibrator; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -621,11 +623,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator { ((ActivityToolbarInterface) activity).displaySortType(); } + Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); + // Vibrate for 500 milliseconds backgroundLeft = new ColorDrawable(customThemeWrapper.getDownvoted()); backgroundRight = new ColorDrawable(customThemeWrapper.getUpvoted()); drawableLeft = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_downward_black_24dp, null); drawableRight = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_upward_black_24dp, null); touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() { + boolean exceedThreshold = false; + @Override public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; @@ -660,18 +666,42 @@ public class PostFragment extends Fragment implements FragmentCommunicator { View itemView = viewHolder.itemView; int horizontalOffset = (int) Utils.convertDpToPixel(16, activity); if (dX > 0) { - if (dX > (itemView.getRight() - itemView.getLeft()) * 0.3) { + if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { + if (!exceedThreshold) { + exceedThreshold = true; + if (v != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + v.vibrate(VibrationEffect.createOneShot(10, 175)); + } else { + //deprecated in API 26 + v.vibrate(50); + } + } + } backgroundLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); } else { + exceedThreshold = false; backgroundLeft.setBounds(0, 0, 0, 0); } drawableLeft.setBounds(itemView.getLeft() + ((int) dX) - horizontalOffset - drawableLeft.getIntrinsicWidth(), (itemView.getBottom() - itemView.getTop() - drawableLeft.getIntrinsicHeight()) / 2, itemView.getLeft() + ((int) dX) - horizontalOffset, (itemView.getBottom() - itemView.getTop() + drawableLeft.getIntrinsicHeight()) / 2); backgroundLeft.draw(c); drawableLeft.draw(c); } else if (dX < 0) { - if (-dX > (itemView.getRight() - itemView.getLeft()) * 0.3) { + if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { + if (!exceedThreshold) { + exceedThreshold = true; + if (v != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + v.vibrate(VibrationEffect.createOneShot(10, 175)); + } else { + //deprecated in API 26 + v.vibrate(50); + } + } + } backgroundRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); } else { + exceedThreshold = false; backgroundRight.setBounds(0, 0, 0, 0); } drawableRight.setBounds(itemView.getRight() + ((int) dX) + horizontalOffset, (itemView.getBottom() - itemView.getTop() - drawableRight.getIntrinsicHeight()) / 2, itemView.getRight() + ((int) dX) + horizontalOffset + drawableRight.getIntrinsicWidth(), (itemView.getBottom() - itemView.getTop() + drawableRight.getIntrinsicHeight()) / 2); |