diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-17 13:38:50 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-17 13:38:50 +0000 |
commit | 366660a6d019355e1166f0e7f590ca41eb3df6b4 (patch) | |
tree | 42ff5948674442df49d1f53e61286c91a85df10b /app/src/main | |
parent | 38ce4db31164fece7f26c7b2a84cbc6f2091cacf (diff) | |
download | infinity-for-reddit-366660a6d019355e1166f0e7f590ca41eb3df6b4.tar infinity-for-reddit-366660a6d019355e1166f0e7f590ca41eb3df6b4.tar.gz infinity-for-reddit-366660a6d019355e1166f0e7f590ca41eb3df6b4.tar.bz2 infinity-for-reddit-366660a6d019355e1166f0e7f590ca41eb3df6b4.tar.lz infinity-for-reddit-366660a6d019355e1166f0e7f590ca41eb3df6b4.tar.xz infinity-for-reddit-366660a6d019355e1166f0e7f590ca41eb3df6b4.tar.zst infinity-for-reddit-366660a6d019355e1166f0e7f590ca41eb3df6b4.zip |
Support swipe action in PostCompactBaseViewHolder.
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java | 15 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java | 4 |
2 files changed, 16 insertions, 3 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 a815302f..d9b3da20 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -1306,6 +1306,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostBaseViewHolder) viewHolder).downvoteButton.performClick(); } } + } else if (viewHolder instanceof PostCompactBaseViewHolder) { + Post post = getItem(viewHolder.getAdapterPosition()); + if (post != null) { + if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) { + ((PostCompactBaseViewHolder) viewHolder).upvoteButton.performClick(); + } else { + ((PostCompactBaseViewHolder) viewHolder).downvoteButton.performClick(); + } + } } } @@ -1317,7 +1326,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView void currentlyBindItem(int position); } - class PostBaseViewHolder extends RecyclerView.ViewHolder { + public class PostBaseViewHolder extends RecyclerView.ViewHolder { MaterialCardView cardView; AspectRatioGifImageView iconGifImageView; TextView subredditTextView; @@ -2658,7 +2667,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } } - class PostCompactBaseViewHolder extends RecyclerView.ViewHolder { + public class PostCompactBaseViewHolder extends RecyclerView.ViewHolder { AspectRatioGifImageView iconGifImageView; TextView nameTextView; ImageView stickiedPostImageView; @@ -2760,7 +2769,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView constraintSet.applyTo(bottomConstraintLayout); } - itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + itemView.setBackgroundColor(mCardViewBackgroundColor); postTimeTextView.setTextColor(mSecondaryTextColor); titleTextView.setTextColor(mPostTitleColor); stickiedPostImageView.setColorFilter(mStickiedPostIconTint, PorterDuff.Mode.SRC_IN); 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 e04e1dde..37264783 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -645,6 +645,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { + if (!(viewHolder instanceof PostRecyclerViewAdapter.PostBaseViewHolder) && + !(viewHolder instanceof PostRecyclerViewAdapter.PostCompactBaseViewHolder)) { + return makeMovementFlags(0, 0); + } int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; return makeMovementFlags(0, swipeFlags); } |