From 69ba6461ff5743d60911ea57a60983be78685b72 Mon Sep 17 00:00:00 2001 From: Sergei Kozelko Date: Sun, 27 Nov 2022 20:12:29 +0800 Subject: Remove unused Post fields (#1212) * Remove unused isHiddenInRecyclerView Post field Was used only for reads and was always false * Remove unused isHiddenManuallyByUser Post field Was only written to and read for serialization. Never used for any logic --- .../adapters/HistoryPostRecyclerViewAdapter.java | 14 -------------- .../adapters/PostRecyclerViewAdapter.java | 20 +++----------------- .../fragments/HistoryPostFragment.java | 8 ++++---- .../infinityforreddit/fragments/PostFragment.java | 8 ++++---- .../fragments/ViewPostDetailFragment.java | 2 +- .../infinityforreddit/post/ParsePost.java | 2 +- .../infinityforreddit/post/Post.java | 21 +-------------------- 7 files changed, 14 insertions(+), 61 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index 8cb82325..a254bef3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -1699,20 +1699,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter= 0 && temp < super.getItemCount()) { - Post post = getItem(temp); - if (post != null && post.isHiddenInRecyclerView()) { - temp++; - } else { - break; - } - } - - return temp; - } - public void setAutoplay(boolean autoplay) { mAutoplay = autoplay; } 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 443e0842..693a5920 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -1769,20 +1769,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter= 0 && temp < super.getItemCount()) { - Post post = getItem(temp); - if (post != null && post.isHiddenInRecyclerView()) { - temp++; - } else { - break; - } - } - - return temp; - } - public void setAutoplay(boolean autoplay) { mAutoplay = autoplay; } @@ -2718,7 +2704,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter getCurrentPosition()) { incrementCurrentPosition(); - smoothScroller.setTargetPosition(mAdapter.getNextItemPositionWithoutBeingHidden(getCurrentPosition())); + smoothScroller.setTargetPosition(getCurrentPosition()); if (mLinearLayoutManager != null) { mLinearLayoutManager.startSmoothScroll(smoothScroller); } else { @@ -1029,7 +1029,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato post.setFlair(event.post.getFlair()); post.setSaved(event.post.isSaved()); if (event.post.isRead()) { - post.markAsRead(true); + post.markAsRead(); } mAdapter.notifyItemChanged(event.positionInList); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index cb3f1694..763ef3cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -361,16 +361,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator { int nPosts = mAdapter.getItemCount(); if (getCurrentPosition() == -1) { if (mLinearLayoutManager != null) { - setCurrentPosition(mAdapter.getNextItemPositionWithoutBeingHidden(mLinearLayoutManager.findFirstVisibleItemPosition())); + setCurrentPosition(mLinearLayoutManager.findFirstVisibleItemPosition()); } else { int[] into = new int[2]; - setCurrentPosition(mAdapter.getNextItemPositionWithoutBeingHidden(mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[1])); + setCurrentPosition(mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[1]); } } if (getCurrentPosition() != RecyclerView.NO_POSITION && nPosts > getCurrentPosition()) { incrementCurrentPosition(); - smoothScroller.setTargetPosition(mAdapter.getNextItemPositionWithoutBeingHidden(getCurrentPosition())); + smoothScroller.setTargetPosition(getCurrentPosition()); if (mLinearLayoutManager != null) { mLinearLayoutManager.startSmoothScroll(smoothScroller); } else { @@ -1777,7 +1777,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { post.setFlair(event.post.getFlair()); post.setSaved(event.post.isSaved()); if (event.post.isRead()) { - post.markAsRead(true); + post.markAsRead(); } mAdapter.notifyItemChanged(event.positionInList); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 3196d705..03e08059 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -1189,7 +1189,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic private void tryMarkingPostAsRead() { if (mMarkPostsAsRead && mPost != null && !mPost.isRead()) { - mPost.markAsRead(true); + mPost.markAsRead(); InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, mPost.getId()); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index 9374ba75..dddb4d69 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -51,7 +51,7 @@ public class ParsePost { JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); Post post = parseBasicData(data); if (readPostHashSet != null && readPostHashSet.contains(post.getId())) { - post.markAsRead(false); + post.markAsRead(); } if (PostFilter.isPostAllowed(post, postFilter)) { newPosts.add(post); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index 82060f0e..090e7005 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -76,8 +76,6 @@ public class Post implements Parcelable { private boolean saved; private boolean isCrosspost; private boolean isRead; - private boolean isHiddenInRecyclerView = false; - private boolean isHiddenManuallyByUser = false; private String crosspostParentId; private ArrayList previews = new ArrayList<>(); private ArrayList gallery = new ArrayList<>(); @@ -199,8 +197,6 @@ public class Post implements Parcelable { saved = in.readByte() != 0; isCrosspost = in.readByte() != 0; isRead = in.readByte() != 0; - isHiddenInRecyclerView = in.readByte() != 0; - isHiddenManuallyByUser = in.readByte() != 0; crosspostParentId = in.readString(); in.readTypedList(previews, Preview.CREATOR); in.readTypedList(gallery, Gallery.CREATOR); @@ -496,27 +492,14 @@ public class Post implements Parcelable { return isCrosspost; } - public void markAsRead(boolean isHiddenManuallyByUser) { + public void markAsRead() { isRead = true; - this.isHiddenManuallyByUser = isHiddenManuallyByUser; } public boolean isRead() { return isRead; } - public boolean isHiddenInRecyclerView() { - return isHiddenInRecyclerView; - } - - public void hidePostInRecyclerView() { - isHiddenInRecyclerView = true; - } - - public boolean isHiddenManuallyByUser() { - return isHiddenManuallyByUser; - } - public String getCrosspostParentId() { return crosspostParentId; } @@ -586,8 +569,6 @@ public class Post implements Parcelable { parcel.writeByte((byte) (saved ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0)); parcel.writeByte((byte) (isRead ? 1 : 0)); - parcel.writeByte((byte) (isHiddenInRecyclerView ? 1 : 0)); - parcel.writeByte((byte) (isHiddenManuallyByUser ? 1 : 0)); parcel.writeString(crosspostParentId); parcel.writeTypedList(previews); parcel.writeTypedList(gallery); -- cgit v1.2.3