mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Rewrite code related to hiding read posts.
This commit is contained in:
parent
50a3572679
commit
48a8076fc0
@ -169,7 +169,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
private int mVoteAndReplyUnavailableVoteButtonColor;
|
||||
private int mPostIconAndInfoColor;
|
||||
private int mDividerColor;
|
||||
private int mHideReadPostsIndex = 0;
|
||||
private float mScale;
|
||||
private boolean mDisplaySubredditName;
|
||||
private boolean mVoteButtonsOnTheRight;
|
||||
@ -453,16 +452,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
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;
|
||||
}
|
||||
if (((PostBaseViewHolder) holder).itemViewIsNotCardView) {
|
||||
holder.itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
|
||||
} else {
|
||||
@ -950,14 +939,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
if (post.isRead()) {
|
||||
if ((mHideReadPostsAutomatically && !post.isHiddenManuallyByUser()) || position < mHideReadPostsIndex) {
|
||||
post.hidePostInRecyclerView();
|
||||
holder.itemView.setVisibility(View.GONE);
|
||||
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
|
||||
params.height = 0;
|
||||
holder.itemView.setLayoutParams(params);
|
||||
return;
|
||||
}
|
||||
holder.itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
|
||||
((PostCompactBaseViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor);
|
||||
}
|
||||
@ -1280,16 +1261,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
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);
|
||||
}
|
||||
@ -1700,18 +1671,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
|
||||
}
|
||||
|
||||
public int getHideReadPostsIndex() {
|
||||
return mHideReadPostsIndex;
|
||||
}
|
||||
|
||||
public void setHideReadPostsIndex(int hideReadPostsIndex) {
|
||||
mHideReadPostsIndex = hideReadPostsIndex;
|
||||
}
|
||||
|
||||
public void prepareToHideReadPosts() {
|
||||
mHideReadPostsIndex = getItemCount();
|
||||
}
|
||||
|
||||
public int getNextItemPositionWithoutBeingHidden(int fromPosition) {
|
||||
int temp = fromPosition;
|
||||
while (temp >= 0 && temp < super.getItemCount()) {
|
||||
@ -1813,21 +1772,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostBaseViewHolder) holder).markPostRead(post, false);
|
||||
}
|
||||
}
|
||||
holder.itemView.setVisibility(View.VISIBLE);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
||||
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
if (holder instanceof PostCard2VideoAutoplayViewHolder || holder instanceof PostCard2WithPreviewViewHolder) {
|
||||
int paddingPixel = (int) Utils.convertDpToPixel(16, mActivity);
|
||||
holder.itemView.setPadding(0, paddingPixel, 0, 0);
|
||||
} else if (holder instanceof PostCard2TextTypeViewHolder) {
|
||||
int paddingPixel = (int) Utils.convertDpToPixel(12, mActivity);
|
||||
holder.itemView.setPadding(0, paddingPixel, 0, 0);
|
||||
} else {
|
||||
int marginPixel = (int) Utils.convertDpToPixel(8, mActivity);
|
||||
params.topMargin = marginPixel;
|
||||
params.bottomMargin = marginPixel;
|
||||
}
|
||||
holder.itemView.setLayoutParams(params);
|
||||
if (((PostBaseViewHolder) holder).itemViewIsNotCardView) {
|
||||
holder.itemView.setBackgroundColor(mCardViewBackgroundColor);
|
||||
} else {
|
||||
@ -1902,11 +1846,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostCompactBaseViewHolder) holder).markPostRead(post, false);
|
||||
}
|
||||
}
|
||||
((PostCompactBaseViewHolder) holder).itemView.setVisibility(View.VISIBLE);
|
||||
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
|
||||
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
holder.itemView.setLayoutParams(params);
|
||||
((PostCompactBaseViewHolder) holder).itemView.setBackgroundColor(mCardViewBackgroundColor);
|
||||
holder.itemView.setBackgroundColor(mCardViewBackgroundColor);
|
||||
((PostCompactBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor);
|
||||
mGlide.clear(((PostCompactBaseViewHolder) holder).imageView);
|
||||
mGlide.clear(((PostCompactBaseViewHolder) holder).iconGifImageView);
|
||||
@ -1937,14 +1877,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((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));
|
||||
holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor));
|
||||
|
||||
((PostGalleryViewHolder) holder).titleTextView.setText("");
|
||||
((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.GONE);
|
||||
@ -2636,7 +2569,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
}
|
||||
mFragment.addCurrentlyReadPostId(post.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3249,7 +3181,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
itemView.setOnLongClickListener(view -> {
|
||||
if (mLongPressToHideToolbarInCompactLayout) {
|
||||
if (bottomConstraintLayout.getLayoutParams().height == 0) {
|
||||
ViewGroup.LayoutParams params = (LinearLayout.LayoutParams) bottomConstraintLayout.getLayoutParams();
|
||||
ViewGroup.LayoutParams params = bottomConstraintLayout.getLayoutParams();
|
||||
params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
bottomConstraintLayout.setLayoutParams(params);
|
||||
mCallback.delayTransition();
|
||||
@ -3621,7 +3553,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
}
|
||||
mFragment.addCurrentlyReadPostId(post.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3856,7 +3787,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
}
|
||||
mFragment.addCurrentlyReadPostId(post.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||
private static final String RECYCLER_VIEW_POSITION_STATE = "RVPS";
|
||||
private static final String READ_POST_LIST_STATE = "RPLS";
|
||||
private static final String HIDE_READ_POSTS_INDEX_STATE = "HRPIS";
|
||||
private static final String POST_FILTER_STATE = "PFS";
|
||||
private static final String CONCATENATED_SUBREDDIT_NAMES_STATE = "CSNS";
|
||||
private static final String POST_FRAGMENT_ID_STATE = "PFIS";
|
||||
@ -253,7 +252,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
private float swipeActionThreshold;
|
||||
private ItemTouchHelper touchHelper;
|
||||
private ArrayList<ReadPost> readPosts;
|
||||
private Set<String> currentlyReadPostIds = new HashSet<>();
|
||||
private Unbinder unbinder;
|
||||
private Map<String, String> subredditOrUserIcons = new HashMap<>();
|
||||
|
||||
@ -391,13 +389,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this::refresh);
|
||||
|
||||
int recyclerViewPosition = 0;
|
||||
int hideReadPostsIndex = 0;
|
||||
if (savedInstanceState != null) {
|
||||
recyclerViewPosition = savedInstanceState.getInt(RECYCLER_VIEW_POSITION_STATE);
|
||||
|
||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||
readPosts = savedInstanceState.getParcelableArrayList(READ_POST_LIST_STATE);
|
||||
hideReadPostsIndex = savedInstanceState.getInt(HIDE_READ_POSTS_INDEX_STATE, 0);
|
||||
postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE);
|
||||
concatenatedSubredditNames = savedInstanceState.getString(CONCATENATED_SUBREDDIT_NAMES_STATE);
|
||||
postFragmentId = savedInstanceState.getLong(POST_FRAGMENT_ID_STATE);
|
||||
@ -842,8 +838,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
mPostRecyclerView.scrollToPosition(recyclerViewPosition);
|
||||
}
|
||||
|
||||
mAdapter.setHideReadPostsIndex(hideReadPostsIndex);
|
||||
|
||||
if (activity instanceof ActivityToolbarInterface) {
|
||||
((ActivityToolbarInterface) activity).displaySortType();
|
||||
}
|
||||
@ -872,7 +866,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
|
||||
}
|
||||
this.readPosts = readPostList;
|
||||
currentlyReadPostIds.addAll(Lists.transform(readPosts, ReadPost::getId));
|
||||
initializeAndBindPostViewModel(accessToken);
|
||||
}
|
||||
});
|
||||
@ -1279,9 +1272,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||
outState.putParcelableArrayList(READ_POST_LIST_STATE, readPosts);
|
||||
if (mAdapter != null) {
|
||||
outState.putInt(HIDE_READ_POSTS_INDEX_STATE, mAdapter.getHideReadPostsIndex());
|
||||
}
|
||||
if (mLinearLayoutManager != null) {
|
||||
outState.putInt(RECYCLER_VIEW_POSITION_STATE, mLinearLayoutManager.findFirstVisibleItemPosition());
|
||||
} else if (mStaggeredGridLayoutManager != null) {
|
||||
@ -1332,10 +1322,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
}
|
||||
|
||||
public void addCurrentlyReadPostId(String id) {
|
||||
currentlyReadPostIds.add(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeNSFW(boolean nsfw) {
|
||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && nsfw;
|
||||
@ -1492,10 +1478,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
@Override
|
||||
public void hideReadPosts() {
|
||||
/*if (mAdapter != null) {
|
||||
mAdapter.prepareToHideReadPosts();
|
||||
refreshAdapter();
|
||||
}*/
|
||||
mPostViewModel.hideReadPosts();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user