diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-16 11:32:23 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-16 11:32:23 +0000 |
commit | 9b9a1aa308659fc2f031f468002eeff15323b9d6 (patch) | |
tree | e63cd913653d889c7d429861b88bc7c8f383c33b | |
parent | 9efeeb88ac1fde770ccd7506f7c6667c0d333f1e (diff) | |
download | infinity-for-reddit-9b9a1aa308659fc2f031f468002eeff15323b9d6.tar infinity-for-reddit-9b9a1aa308659fc2f031f468002eeff15323b9d6.tar.gz infinity-for-reddit-9b9a1aa308659fc2f031f468002eeff15323b9d6.tar.bz2 infinity-for-reddit-9b9a1aa308659fc2f031f468002eeff15323b9d6.tar.lz infinity-for-reddit-9b9a1aa308659fc2f031f468002eeff15323b9d6.tar.xz infinity-for-reddit-9b9a1aa308659fc2f031f468002eeff15323b9d6.tar.zst infinity-for-reddit-9b9a1aa308659fc2f031f468002eeff15323b9d6.zip |
Continue adding Gallery Layout.
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index b4230074..4cbd3254 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -1056,6 +1056,21 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } else if (holder instanceof PostGalleryViewHolder) { Post post = getItem(position); if (post != null) { + if (post.isRead()) { + if ((mHideReadPostsAutomatically && !post.isHiddenManuallyByUser()) || position < mHideReadPostsIndex) { + post.hidePostInRecyclerView(); + holder.itemView.setVisibility(View.GONE); + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams(); + params.height = 0; + params.topMargin = 0; + params.bottomMargin = 0; + holder.itemView.setLayoutParams(params); + return; + } + holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + ((PostGalleryViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor); + } + switch (post.getPostType()) { case Post.IMAGE_TYPE: { ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); @@ -1625,6 +1640,22 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostCompactBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor); ((PostCompactBaseViewHolder) holder).downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); } else if (holder instanceof PostGalleryViewHolder) { + if (mMarkPostsAsReadOnScroll) { + int position = holder.getBindingAdapterPosition(); + if (position < super.getItemCount() && position >= 0) { + Post post = getItem(position); + ((PostGalleryViewHolder) holder).markPostRead(post, false); + } + } + ((PostGalleryViewHolder) holder).itemView.setVisibility(View.VISIBLE); + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams(); + params.height = ViewGroup.LayoutParams.WRAP_CONTENT; + int marginPixel = (int) Utils.convertDpToPixel(8, mActivity); + params.topMargin = marginPixel; + params.bottomMargin = marginPixel; + holder.itemView.setLayoutParams(params); + ((PostGalleryViewHolder) holder).itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + ((PostGalleryViewHolder) holder).titleTextView.setText(""); ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.GONE); mGlide.clear(((PostGalleryViewHolder) holder).imageView); @@ -3442,7 +3473,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (position >= 0 && canStartActivity) { Post post = getItem(position); if (post != null) { - //markPostRead(post, true); + markPostRead(post, true); canStartActivity = false; Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); @@ -3454,6 +3485,19 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } }); } + + void markPostRead(Post post, boolean changePostItemColor) { + if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) { + post.markAsRead(true); + if (changePostItemColor) { + itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + titleTextView.setTextColor(mReadPostTitleColor); + } + if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { + ((MarkPostAsReadInterface) mActivity).markPostAsRead(post); + } + } + } } class ErrorViewHolder extends RecyclerView.ViewHolder { |