diff options
Diffstat (limited to 'app/src/main')
13 files changed, 206 insertions, 92 deletions
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 b394cfa0..c2951c14 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.Activity; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; @@ -9,7 +8,6 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import android.os.Vibrator; import android.util.DisplayMetrics; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; @@ -229,11 +227,13 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS private SlidrInterface mSlidrInterface; private Drawable mSavedIcon; private Drawable mUnsavedIcon; - private ColorDrawable backgroundLeft; - private ColorDrawable backgroundRight; - private Drawable drawableLeft; - private Drawable drawableRight; - private float swipeActionThreshold = 0.3f; + private ColorDrawable backgroundSwipeRight; + private ColorDrawable backgroundSwipeLeft; + private Drawable drawableSwipeRight; + private Drawable drawableSwipeLeft; + private int swipeLeftAction; + private int swipeRightAction; + private float swipeActionThreshold; private ItemTouchHelper touchHelper; @Override @@ -392,11 +392,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS boolean enableSwipeAction = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false); boolean vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true); - Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); - backgroundLeft = new ColorDrawable(mCustomThemeWrapper.getDownvoted()); - backgroundRight = new ColorDrawable(mCustomThemeWrapper.getUpvoted()); - drawableLeft = ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_downward_black_24dp, null); - drawableRight = ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_upward_black_24dp, null); + swipeActionThreshold = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_ACTION_THRESHOLD, "0.3")); + swipeRightAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_RIGHT_ACTION, "1")); + swipeLeftAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_LEFT_ACTION, "0")); + initializeSwipeActionDrawable(); touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() { boolean exceedThreshold = false; @@ -426,7 +425,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS touchHelper.attachToRecyclerView(null); touchHelper.attachToRecyclerView(mRecyclerView); if (mAdapter != null) { - mAdapter.onItemSwipe(viewHolder, direction); + mAdapter.onItemSwipe(viewHolder, direction, swipeLeftAction, swipeRightAction); } } } @@ -441,39 +440,43 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { if (!exceedThreshold) { exceedThreshold = true; - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + if (vibrateWhenActionTriggered) { + viewHolder.itemView.setHapticFeedbackEnabled(true); + viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } } - backgroundLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); + backgroundSwipeRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); } else { exceedThreshold = false; - backgroundLeft.setBounds(0, 0, 0, 0); + backgroundSwipeRight.setBounds(0, 0, 0, 0); } - drawableLeft.setBounds(itemView.getLeft() + ((int) dX) - horizontalOffset - drawableLeft.getIntrinsicWidth(), - (itemView.getBottom() + itemView.getTop() - drawableLeft.getIntrinsicHeight()) / 2, + 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() + drawableLeft.getIntrinsicHeight()) / 2); - backgroundLeft.draw(c); - drawableLeft.draw(c); + (itemView.getBottom() + itemView.getTop() + drawableSwipeRight.getIntrinsicHeight()) / 2); + backgroundSwipeRight.draw(c); + drawableSwipeRight.draw(c); } else if (dX < 0) { if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { if (!exceedThreshold) { exceedThreshold = true; - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + if (vibrateWhenActionTriggered) { + viewHolder.itemView.setHapticFeedbackEnabled(true); + viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } } - backgroundRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); + backgroundSwipeLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); } else { exceedThreshold = false; - backgroundRight.setBounds(0, 0, 0, 0); + backgroundSwipeLeft.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); - backgroundRight.draw(c); - drawableRight.draw(c); + 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); } } @@ -534,6 +537,24 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mPostCommentSortTypeBottomSheetFragment = new PostCommentSortTypeBottomSheetFragment(); } + private void initializeSwipeActionDrawable() { + if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + backgroundSwipeRight = new ColorDrawable(mCustomThemeWrapper.getDownvoted()); + drawableSwipeRight = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_arrow_downward_black_24dp, null); + } else { + backgroundSwipeRight = new ColorDrawable(mCustomThemeWrapper.getUpvoted()); + drawableSwipeRight = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_arrow_upward_black_24dp, null); + } + + if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + backgroundSwipeLeft = new ColorDrawable(mCustomThemeWrapper.getUpvoted()); + drawableSwipeLeft = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_arrow_upward_black_24dp, null); + } else { + backgroundSwipeLeft = new ColorDrawable(mCustomThemeWrapper.getDownvoted()); + drawableSwipeLeft = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_arrow_downward_black_24dp, null); + } + } + @Override protected void onResume() { super.onResume(); 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 66c4ba8e..b063ddb5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1883,18 +1883,34 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mDataSavingMode = dataSavingMode; } - public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction) { + public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction, int swipeLeftAction, int swipeRightAction) { if (viewHolder instanceof PostDetailBaseViewHolder) { if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) { - ((PostDetailBaseViewHolder) viewHolder).mUpvoteButton.performClick(); + if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + ((PostDetailBaseViewHolder) viewHolder).mUpvoteButton.performClick(); + } else if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + ((PostDetailBaseViewHolder) viewHolder).mDownvoteButton.performClick(); + } } else { - ((PostDetailBaseViewHolder) viewHolder).mDownvoteButton.performClick(); + if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + ((PostDetailBaseViewHolder) viewHolder).mUpvoteButton.performClick(); + } else if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + ((PostDetailBaseViewHolder) viewHolder).mDownvoteButton.performClick(); + } } } else if (viewHolder instanceof CommentViewHolder) { if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) { - ((CommentViewHolder) viewHolder).upvoteButton.performClick(); + if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + ((CommentViewHolder) viewHolder).upvoteButton.performClick(); + } else if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + ((CommentViewHolder) viewHolder).downvoteButton.performClick(); + } } else { - ((CommentViewHolder) viewHolder).downvoteButton.performClick(); + if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + ((CommentViewHolder) viewHolder).upvoteButton.performClick(); + } else if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + ((CommentViewHolder) viewHolder).downvoteButton.performClick(); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java index 147a13d1..3ab89e83 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java @@ -353,12 +353,20 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment } } - public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction) { + public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction, int swipeLeftAction, int swipeRightAction) { if (viewHolder instanceof CommentViewHolder) { if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) { - ((CommentViewHolder) viewHolder).upvoteButton.performClick(); + if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + ((CommentViewHolder) viewHolder).upvoteButton.performClick(); + } else if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + ((CommentViewHolder) viewHolder).downvoteButton.performClick(); + } } else { - ((CommentViewHolder) viewHolder).downvoteButton.performClick(); + if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + ((CommentViewHolder) viewHolder).upvoteButton.performClick(); + } else if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + ((CommentViewHolder) viewHolder).downvoteButton.performClick(); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java index 4fcbba0e..e04b3716 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java @@ -10,7 +10,6 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import android.os.Vibrator; import android.view.HapticFeedbackConstants; import android.view.LayoutInflater; import android.view.View; @@ -105,11 +104,13 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni private LinearLayoutManager mLinearLayoutManager; private CommentsListingRecyclerViewAdapter mAdapter; private SortType sortType; - private ColorDrawable backgroundLeft; - private ColorDrawable backgroundRight; - private Drawable drawableLeft; - private Drawable drawableRight; - private float swipeActionThreshold = 0.3f; + private ColorDrawable backgroundSwipeRight; + private ColorDrawable backgroundSwipeLeft; + private Drawable drawableSwipeRight; + private Drawable drawableSwipeLeft; + private int swipeLeftAction; + private int swipeRightAction; + private float swipeActionThreshold; private ItemTouchHelper touchHelper; public CommentsListingFragment() { @@ -144,11 +145,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni boolean enableSwipeAction = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false); boolean vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true); - Vibrator v = (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE); - backgroundLeft = new ColorDrawable(customThemeWrapper.getDownvoted()); - backgroundRight = new ColorDrawable(customThemeWrapper.getUpvoted()); - drawableLeft = ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_downward_black_24dp, null); - drawableRight = ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_upward_black_24dp, null); + swipeActionThreshold = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_ACTION_THRESHOLD, "0.3")); + swipeRightAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_RIGHT_ACTION, "1")); + swipeLeftAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_LEFT_ACTION, "0")); + initializeSwipeActionDrawable(); touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() { boolean exceedThreshold = false; @@ -177,7 +177,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni touchHelper.attachToRecyclerView(null); touchHelper.attachToRecyclerView(mCommentRecyclerView); if (mAdapter != null) { - mAdapter.onItemSwipe(viewHolder, direction); + mAdapter.onItemSwipe(viewHolder, direction, swipeLeftAction, swipeRightAction); } } } @@ -192,39 +192,43 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { if (!exceedThreshold) { exceedThreshold = true; - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + if (vibrateWhenActionTriggered) { + viewHolder.itemView.setHapticFeedbackEnabled(true); + viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } } - backgroundLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); + backgroundSwipeRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); } else { exceedThreshold = false; - backgroundLeft.setBounds(0, 0, 0, 0); + backgroundSwipeRight.setBounds(0, 0, 0, 0); } - drawableLeft.setBounds(itemView.getLeft() + ((int) dX) - horizontalOffset - drawableLeft.getIntrinsicWidth(), - (itemView.getBottom() + itemView.getTop() - drawableLeft.getIntrinsicHeight()) / 2, + 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() + drawableLeft.getIntrinsicHeight()) / 2); - backgroundLeft.draw(c); - drawableLeft.draw(c); + (itemView.getBottom() + itemView.getTop() + drawableSwipeRight.getIntrinsicHeight()) / 2); + backgroundSwipeRight.draw(c); + drawableSwipeRight.draw(c); } else if (dX < 0) { if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { if (!exceedThreshold) { exceedThreshold = true; - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + if (vibrateWhenActionTriggered) { + viewHolder.itemView.setHapticFeedbackEnabled(true); + viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } } - backgroundRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); + backgroundSwipeLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); } else { exceedThreshold = false; - backgroundRight.setBounds(0, 0, 0, 0); + backgroundSwipeLeft.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); - backgroundRight.draw(c); - drawableRight.draw(c); + 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); } } @@ -334,6 +338,24 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni this.sortType = sortType; } + private void initializeSwipeActionDrawable() { + if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) { + backgroundSwipeRight = new ColorDrawable(customThemeWrapper.getDownvoted()); + drawableSwipeRight = ResourcesCompat.getDrawable(mActivity.getResources(), R.drawable.ic_arrow_downward_black_24dp, null); + } else { + backgroundSwipeRight = new ColorDrawable(customThemeWrapper.getUpvoted()); + drawableSwipeRight = ResourcesCompat.getDrawable(mActivity.getResources(), R.drawable.ic_arrow_upward_black_24dp, null); + } + + if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) { + backgroundSwipeLeft = new ColorDrawable(customThemeWrapper.getUpvoted()); + drawableSwipeLeft = ResourcesCompat.getDrawable(mActivity.getResources(), R.drawable.ic_arrow_upward_black_24dp, null); + } else { + backgroundSwipeLeft = new ColorDrawable(customThemeWrapper.getDownvoted()); + drawableSwipeLeft = ResourcesCompat.getDrawable(mActivity.getResources(), R.drawable.ic_arrow_downward_black_24dp, null); + } + } + @Override public void onAttach(@NonNull Context context) { super.onAttach(context); 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 d5ad7878..c0b00a18 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -187,7 +187,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private boolean hasPost = false; private boolean isShown = false; private boolean savePostFeedScrolledPosition; - private boolean vibrateWhenActionTriggered; private PostRecyclerViewAdapter mAdapter; private RecyclerView.SmoothScroller smoothScroller; private Window window; @@ -208,6 +207,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private Drawable drawableSwipeLeft; private int swipeLeftAction; private int swipeRightAction; + private boolean vibrateWhenActionTriggered; private float swipeActionThreshold; private ItemTouchHelper touchHelper; private ArrayList<SubredditFilter> subredditFilterList; @@ -415,9 +415,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0")); savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false); - vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true); - boolean enableSwipeAction = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false); - swipeActionThreshold = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_ACTION_THRESHOLD, "0.3")); Locale locale = getResources().getConfiguration().locale; if (postType == PostDataSource.TYPE_SEARCH) { @@ -692,6 +689,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { ((ActivityToolbarInterface) activity).displaySortType(); } + vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true); + swipeActionThreshold = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_ACTION_THRESHOLD, "0.3")); swipeRightAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_RIGHT_ACTION, "1")); swipeLeftAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_LEFT_ACTION, "0")); initializeSwipeActionDrawable(); @@ -740,8 +739,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { if (!exceedThreshold) { exceedThreshold = true; - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + 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 { @@ -759,8 +760,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { if (!exceedThreshold) { exceedThreshold = true; - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + 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 { @@ -782,7 +785,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } }); - if (enableSwipeAction) { + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false)) { touchHelper.attachToRecyclerView(mPostRecyclerView); } mPostRecyclerView.setAdapter(mAdapter); diff --git a/app/src/main/res/drawable-night/ic_about_24dp.xml b/app/src/main/res/drawable-night/ic_about_24dp.xml new file mode 100644 index 00000000..e0580503 --- /dev/null +++ b/app/src/main/res/drawable-night/ic_about_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FFFFFF" + android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"/> +</vector> diff --git a/app/src/main/res/drawable-night/ic_advanced_24dp.xml b/app/src/main/res/drawable-night/ic_advanced_24dp.xml new file mode 100644 index 00000000..f4fbd6c9 --- /dev/null +++ b/app/src/main/res/drawable-night/ic_advanced_24dp.xml @@ -0,0 +1,12 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FFFFFF" + android:pathData="M21.67,18.17l-5.3,-5.3h-0.99l-2.54,2.54v0.99l5.3,5.3c0.39,0.39 1.02,0.39 1.41,0l2.12,-2.12C22.06,19.2 22.06,18.56 21.67,18.17zM18.84,19.59l-4.24,-4.24l0.71,-0.71l4.24,4.24L18.84,19.59z"/> + <path + android:fillColor="#FFFFFF" + android:pathData="M17.34,10.19l1.41,-1.41l2.12,2.12c1.17,-1.17 1.17,-3.07 0,-4.24l-3.54,-3.54l-1.41,1.41V1.71L15.22,1l-3.54,3.54l0.71,0.71h2.83l-1.41,1.41l1.06,1.06l-2.89,2.89L7.85,6.48V5.06L4.83,2.04L2,4.87l3.03,3.03h1.41l4.13,4.13l-0.85,0.85H7.6l-5.3,5.3c-0.39,0.39 -0.39,1.02 0,1.41l2.12,2.12c0.39,0.39 1.02,0.39 1.41,0l5.3,-5.3v-2.12l5.15,-5.15L17.34,10.19zM9.36,15.34l-4.24,4.24l-0.71,-0.71l4.24,-4.24l0,0L9.36,15.34L9.36,15.34z"/> +</vector> diff --git a/app/src/main/res/drawable/ic_about_24dp.xml b/app/src/main/res/drawable/ic_about_24dp.xml new file mode 100644 index 00000000..58603013 --- /dev/null +++ b/app/src/main/res/drawable/ic_about_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#000000" + android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"/> +</vector> diff --git a/app/src/main/res/drawable/ic_advanced_24dp.xml b/app/src/main/res/drawable/ic_advanced_24dp.xml new file mode 100644 index 00000000..146913cd --- /dev/null +++ b/app/src/main/res/drawable/ic_advanced_24dp.xml @@ -0,0 +1,12 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#000000" + android:pathData="M21.67,18.17l-5.3,-5.3h-0.99l-2.54,2.54v0.99l5.3,5.3c0.39,0.39 1.02,0.39 1.41,0l2.12,-2.12C22.06,19.2 22.06,18.56 21.67,18.17zM18.84,19.59l-4.24,-4.24l0.71,-0.71l4.24,4.24L18.84,19.59z"/> + <path + android:fillColor="#000000" + android:pathData="M17.34,10.19l1.41,-1.41l2.12,2.12c1.17,-1.17 1.17,-3.07 0,-4.24l-3.54,-3.54l-1.41,1.41V1.71L15.22,1l-3.54,3.54l0.71,0.71h2.83l-1.41,1.41l1.06,1.06l-2.89,2.89L7.85,6.48V5.06L4.83,2.04L2,4.87l3.03,3.03h1.41l4.13,4.13l-0.85,0.85H7.6l-5.3,5.3c-0.39,0.39 -0.39,1.02 0,1.41l2.12,2.12c0.39,0.39 1.02,0.39 1.41,0l5.3,-5.3v-2.12l5.15,-5.15L17.34,10.19zM9.36,15.34l-4.24,4.24l-0.71,-0.71l4.24,-4.24l0,0L9.36,15.34L9.36,15.34z"/> +</vector> diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4bc9fc5e..4da4cef0 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -854,7 +854,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd <string name="settings_video_download_location_title">"動画ダウンロード先のフォルダー"</string> <string name="settings_separate_folder_for_each_subreddit">"Subreddit毎にフォルダーを分ける"</string> <string name="settings_swipe_action_title">"スワイプアクション"</string> - <string name="settings_vibrate_when_action_triggered_title">"アクションが実行される際にデバイスをバイブ"</string> + <string name="settings_swipe_action_haptic_feedback_title">"アクションが実行される際にデバイスをバイブ"</string> <string name="settings_disable_swiping_between_tabs_title">"スワイプによるタブ切り替えを無効化"</string> <string name="settings_enable_swipe_action_title">"スワイプアクションを有効化"</string> <string name="settings_swipe_action_threshold">"しきい値"</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 19768479..02dfa6f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -471,7 +471,7 @@ <string name="settings_video_download_location_title">Video Download Location</string> <string name="settings_separate_folder_for_each_subreddit">Separate Folder for Each Subreddit</string> <string name="settings_swipe_action_title">Swipe Action</string> - <string name="settings_vibrate_when_action_triggered_title">Vibrate the phone when an action is triggered</string> + <string name="settings_swipe_action_haptic_feedback_title">Haptic Feedback</string> <string name="settings_disable_swiping_between_tabs_title">Disable Swiping Between Tabs</string> <string name="settings_enable_swipe_action_title">Enable Swipe Action</string> <string name="settings_swipe_action_threshold">Threshold</string> @@ -490,7 +490,7 @@ <string name="settings_bottom_app_bar_option_4">Option 4</string> <string name="settings_bottom_app_bar_fab">Floating Action Button</string> <string name="settings_data_saving_mode">Data Saving Mode</string> - <string name="settings_data_saving_mode_info_summary">In data saving mode:\nPreview images are in lower resolution.\nReddit videos are in lower resolution.</string> + <string name="settings_data_saving_mode_info_summary">In data saving mode:\nPreview images are in lower resolution.\nReddit videos are in lower resolution.\nVideo autoplay is disabled.</string> <string name="settings_translation_title">Translation</string> <string name="settings_translation_summary">Translate this app on POEditor. Thanks to all contributors.</string> <string name="settings_credits_national_flags">National Flags</string> diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index 1dea4177..f318d83d 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -69,10 +69,12 @@ app:fragment="ml.docilealligator.infinityforreddit.Settings.MiscellaneousPreferenceFragment"/> <Preference + android:icon="@drawable/ic_advanced_24dp" app:title="@string/settings_advanced_master_title" app:fragment="ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment" /> <Preference + android:icon="@drawable/ic_about_24dp" app:title="@string/settings_about_master_title" app:fragment="ml.docilealligator.infinityforreddit.Settings.AboutPreferenceFragment" /> diff --git a/app/src/main/res/xml/swipe_action_preferences.xml b/app/src/main/res/xml/swipe_action_preferences.xml index 36326765..c15330b6 100644 --- a/app/src/main/res/xml/swipe_action_preferences.xml +++ b/app/src/main/res/xml/swipe_action_preferences.xml @@ -22,22 +22,22 @@ app:title="@string/settings_swipe_action_swipe_right_title" app:useSimpleSummaryProvider="true" /> + <ListPreference + app:defaultValue="0.3" + app:entries="@array/settings_swipe_action_threshold" + app:entryValues="@array/settings_swipe_action_threshold" + app:key="swipe_action_threshold" + app:title="@string/settings_swipe_action_threshold" + app:useSimpleSummaryProvider="true" /> + <SwitchPreference app:defaultValue="true" app:key="vibrate_when_action_triggered" - app:title="@string/settings_vibrate_when_action_triggered_title" /> + app:title="@string/settings_swipe_action_haptic_feedback_title" /> <SwitchPreference app:defaultValue="false" app:key="disable_swiping_between_tabs" app:title="@string/settings_disable_swiping_between_tabs_title" /> - <ListPreference - app:defaultValue="0.3" - app:entries="@array/settings_swipe_action_threshold" - app:entryValues="@array/settings_swipe_action_threshold" - app:key="swipe_action_threshold" - app:title="@string/settings_swipe_action_threshold" - app:useSimpleSummaryProvider="true" /> - </PreferenceScreen>
\ No newline at end of file |