diff options
Diffstat (limited to 'app')
4 files changed, 22 insertions, 194 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java index 043c0071..6ade3dd8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java @@ -59,7 +59,8 @@ class CommentData implements Parcelable { hasReply = in.readByte() != 0; scoreHidden = in.readByte() != 0; isExpanded = in.readByte() != 0; - in.readStringList(moreChildrenIds); + children = in.readArrayList(null); + moreChildrenIds = in.readArrayList(null); } public static final Creator<CommentData> CREATOR = new Creator<CommentData>() { @@ -200,179 +201,7 @@ class CommentData implements Parcelable { parcel.writeByte((byte) (hasReply ? 1 : 0)); parcel.writeByte((byte) (scoreHidden ? 1 : 0)); parcel.writeByte((byte) (isExpanded ? 1 : 0)); - parcel.writeStringList(moreChildrenIds); + parcel.writeList(children); + parcel.writeList(moreChildrenIds); } } - -/*class CommentData extends RecyclerViewItem implements Parcelable { - private String id; - private String fullName; - private String author; - private String commentTime; - private String commentContent; - private String parentId; - private int score; - private int voteType; - private boolean isSubmitter; - private String permalink; - private int depth; - private boolean collapsed; - private boolean hasReply; - private boolean scoreHidden; - private ArrayList<String> moreChildrenIds; - - CommentData(String id, String fullName, String author, String commentTime, String commentContent, - String parentId, int score, boolean isSubmitter, String permalink, int depth, - boolean collapsed, boolean hasReply, boolean scoreHidden) { - super(depth); - this.id = id; - this.fullName = fullName; - this.author = author; - this.commentTime = commentTime; - this.commentContent = commentContent; - this.parentId = parentId; - this.score = score; - this.isSubmitter = isSubmitter; - this.permalink = RedditUtils.API_BASE_URI + permalink; - this.depth = depth; - this.collapsed = collapsed; - this.hasReply = hasReply; - this.scoreHidden = scoreHidden; - } - - protected CommentData(Parcel in) { - super(0); - id = in.readString(); - fullName = in.readString(); - author = in.readString(); - commentTime = in.readString(); - commentContent = in.readString(); - parentId = in.readString(); - score = in.readInt(); - voteType = in.readInt(); - isSubmitter = in.readByte() != 0; - permalink = in.readString(); - depth = in.readInt(); - collapsed = in.readByte() != 0; - hasReply = in.readByte() != 0; - scoreHidden = in.readByte() != 0; - in.readStringList(moreChildrenIds); - super.setLevel(depth); - } - - public static final Creator<CommentData> CREATOR = new Creator<CommentData>() { - @Override - public CommentData createFromParcel(Parcel in) { - return new CommentData(in); - } - - @Override - public CommentData[] newArray(int size) { - return new CommentData[size]; - } - }; - - public String getId() { - return id; - } - - public String getFullName() { - return fullName; - } - - public String getAuthor() { - return author; - } - - public String getCommentTime() { - return commentTime; - } - - public String getCommentContent() { - return commentContent; - } - - public String getParentId() { - return parentId; - } - - public void setParentId(String parentId) { - this.parentId = parentId; - } - - public int getScore() { - return score; - } - - public void setScore(int score) { - this.score = score; - } - - public boolean isSubmitter() { - return isSubmitter; - } - - public String getPermalink() { - return permalink; - } - - public int getDepth() { - return depth; - } - - public boolean isCollapsed() { - return collapsed; - } - - public boolean hasReply() { - return hasReply; - } - - public void setHasReply(boolean hasReply) { - this.hasReply = hasReply; - } - - public boolean isScoreHidden() { - return scoreHidden; - } - - public int getVoteType() { - return voteType; - } - - public void setVoteType(int voteType) { - this.voteType = voteType; - } - - public ArrayList<String> getMoreChildrenIds() { - return moreChildrenIds; - } - - public void setMoreChildrenIds(ArrayList<String> moreChildrenIds) { - this.moreChildrenIds = moreChildrenIds; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(id); - parcel.writeString(fullName); - parcel.writeString(author); - parcel.writeString(commentTime); - parcel.writeString(commentContent); - parcel.writeString(parentId); - parcel.writeInt(score); - parcel.writeInt(voteType); - parcel.writeByte((byte) (isSubmitter ? 1 : 0)); - parcel.writeString(permalink); - parcel.writeInt(depth); - parcel.writeByte((byte) (collapsed ? 1 : 0)); - parcel.writeByte((byte) (hasReply ? 1 : 0)); - parcel.writeByte((byte) (scoreHidden ? 1 : 0)); - parcel.writeStringList(moreChildrenIds); - } -}*/ diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java index e9da8bde..260bb5bf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java @@ -56,6 +56,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH mLocale = locale; mVisibleComments = new ArrayList<>(); + new Handler().post(() -> { makeChildrenVisible(commentData, mVisibleComments); notifyDataSetChanged(); @@ -80,7 +81,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - final CommentData commentItem = mVisibleComments.get(position); + CommentData commentItem = mVisibleComments.get(holder.getAdapterPosition()); String authorPrefixed = "u/" + commentItem.getAuthor(); ((CommentViewHolder) holder).authorTextView.setText(authorPrefixed); @@ -327,9 +328,9 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH notifyItemRangeInserted(sizeBefore, comments.size()); } - //Need proper implementation void addComment(CommentData comment) { mCommentData.add(0, comment); + mVisibleComments.add(0, comment); notifyItemInserted(0); } @@ -345,6 +346,12 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH notifyItemChanged(parentPosition); } + void clearData() { + mCommentData.clear(); + mVisibleComments.clear(); + notifyDataSetChanged(); + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof CommentViewHolder) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java index 7f582214..e2a5569f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java @@ -84,7 +84,6 @@ class FetchComment { } stringBuilder.deleteCharAt(stringBuilder.length() - 1); - //final int finalStartingIndex = startingIndex + 100; RedditAPI api = retrofit.create(RedditAPI.class); Call<String> moreChildrenBasicInfo = api.getMoreChildren(mParentId, stringBuilder.toString()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 3c3db7b5..95a9ba0e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -85,7 +85,6 @@ public class ViewPostDetailActivity extends AppCompatActivity { private boolean isLoadingMoreChildren = false; private boolean isRefreshing = false; - private ArrayList<CommentData> mCommentsData; private ArrayList<String> children; private int mChildrenStartingIndex = 0; @@ -167,8 +166,6 @@ public class ViewPostDetailActivity extends AppCompatActivity { postListPosition = getIntent().getExtras().getInt(EXTRA_POST_LIST_POSITION); } - mCommentsData = new ArrayList<>(); - mRecyclerView.setNestedScrollingEnabled(false); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); @@ -507,15 +504,9 @@ public class ViewPostDetailActivity extends AppCompatActivity { String parentId, ArrayList<String> children) { ViewPostDetailActivity.this.children = children; mCommentProgressbar.setVisibility(View.GONE); - mCommentsData.addAll(commentsData); - if (mCommentsData.size() > 0) { + if (commentsData.size() > 0) { if(mAdapter == null) { - mAdapter = new CommentRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, - mOauthRetrofit, mSharedPreferences, commentsData, mRecyclerView, - mPost.getSubredditNamePrefixed(), mPost.getId(), mLocale); - mRecyclerView.setAdapter(mAdapter); - mNestedScrollView.getViewTreeObserver().addOnScrollChangedListener(() -> { if(!isLoadingMoreChildren) { View view = mNestedScrollView.getChildAt(mNestedScrollView.getChildCount() - 1); @@ -526,10 +517,13 @@ public class ViewPostDetailActivity extends AppCompatActivity { } } }); - } else { - mAdapter.notifyDataSetChanged(); } + mAdapter = new CommentRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, + mOauthRetrofit, mSharedPreferences, commentsData, mRecyclerView, + mPost.getSubredditNamePrefixed(), mPost.getId(), mLocale); + mRecyclerView.setAdapter(mAdapter); + mCommentCardView.setVisibility(View.VISIBLE); } else { mNoCommentWrapperLinearLayout.setVisibility(View.VISIBLE); @@ -627,11 +621,10 @@ public class ViewPostDetailActivity extends AppCompatActivity { private void refresh() { if(!isRefreshing) { isRefreshing = true; + mChildrenStartingIndex = 0; - if(mAdapter != null && mCommentsData != null) { - int size = mCommentsData.size(); - mCommentsData.clear(); - mAdapter.notifyItemRangeRemoved(0, size); + if(mAdapter != null) { + mAdapter.clearData(); } fetchComment(); |