mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-12 11:17:11 +01:00
Fixed refreshing comments and sending comments.
This commit is contained in:
parent
25f2a35d22
commit
70f4a7fc4c
@ -59,7 +59,8 @@ class CommentData implements Parcelable {
|
|||||||
hasReply = in.readByte() != 0;
|
hasReply = in.readByte() != 0;
|
||||||
scoreHidden = in.readByte() != 0;
|
scoreHidden = in.readByte() != 0;
|
||||||
isExpanded = 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>() {
|
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) (hasReply ? 1 : 0));
|
||||||
parcel.writeByte((byte) (scoreHidden ? 1 : 0));
|
parcel.writeByte((byte) (scoreHidden ? 1 : 0));
|
||||||
parcel.writeByte((byte) (isExpanded ? 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);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
@ -56,6 +56,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mVisibleComments = new ArrayList<>();
|
mVisibleComments = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
new Handler().post(() -> {
|
new Handler().post(() -> {
|
||||||
makeChildrenVisible(commentData, mVisibleComments);
|
makeChildrenVisible(commentData, mVisibleComments);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
@ -80,7 +81,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
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();
|
String authorPrefixed = "u/" + commentItem.getAuthor();
|
||||||
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
|
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
|
||||||
@ -327,9 +328,9 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||||||
notifyItemRangeInserted(sizeBefore, comments.size());
|
notifyItemRangeInserted(sizeBefore, comments.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Need proper implementation
|
|
||||||
void addComment(CommentData comment) {
|
void addComment(CommentData comment) {
|
||||||
mCommentData.add(0, comment);
|
mCommentData.add(0, comment);
|
||||||
|
mVisibleComments.add(0, comment);
|
||||||
notifyItemInserted(0);
|
notifyItemInserted(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,6 +346,12 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||||||
notifyItemChanged(parentPosition);
|
notifyItemChanged(parentPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearData() {
|
||||||
|
mCommentData.clear();
|
||||||
|
mVisibleComments.clear();
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
if (holder instanceof CommentViewHolder) {
|
if (holder instanceof CommentViewHolder) {
|
||||||
|
@ -84,7 +84,6 @@ class FetchComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
||||||
//final int finalStartingIndex = startingIndex + 100;
|
|
||||||
|
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
Call<String> moreChildrenBasicInfo = api.getMoreChildren(mParentId, stringBuilder.toString());
|
Call<String> moreChildrenBasicInfo = api.getMoreChildren(mParentId, stringBuilder.toString());
|
||||||
|
@ -85,7 +85,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private boolean isLoadingMoreChildren = false;
|
private boolean isLoadingMoreChildren = false;
|
||||||
private boolean isRefreshing = false;
|
private boolean isRefreshing = false;
|
||||||
private ArrayList<CommentData> mCommentsData;
|
|
||||||
private ArrayList<String> children;
|
private ArrayList<String> children;
|
||||||
private int mChildrenStartingIndex = 0;
|
private int mChildrenStartingIndex = 0;
|
||||||
|
|
||||||
@ -167,8 +166,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
postListPosition = getIntent().getExtras().getInt(EXTRA_POST_LIST_POSITION);
|
postListPosition = getIntent().getExtras().getInt(EXTRA_POST_LIST_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
mCommentsData = new ArrayList<>();
|
|
||||||
|
|
||||||
mRecyclerView.setNestedScrollingEnabled(false);
|
mRecyclerView.setNestedScrollingEnabled(false);
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
||||||
@ -507,15 +504,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
String parentId, ArrayList<String> children) {
|
String parentId, ArrayList<String> children) {
|
||||||
ViewPostDetailActivity.this.children = children;
|
ViewPostDetailActivity.this.children = children;
|
||||||
mCommentProgressbar.setVisibility(View.GONE);
|
mCommentProgressbar.setVisibility(View.GONE);
|
||||||
mCommentsData.addAll(commentsData);
|
|
||||||
|
|
||||||
if (mCommentsData.size() > 0) {
|
if (commentsData.size() > 0) {
|
||||||
if(mAdapter == null) {
|
if(mAdapter == null) {
|
||||||
mAdapter = new CommentRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
|
||||||
mOauthRetrofit, mSharedPreferences, commentsData, mRecyclerView,
|
|
||||||
mPost.getSubredditNamePrefixed(), mPost.getId(), mLocale);
|
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
|
||||||
|
|
||||||
mNestedScrollView.getViewTreeObserver().addOnScrollChangedListener(() -> {
|
mNestedScrollView.getViewTreeObserver().addOnScrollChangedListener(() -> {
|
||||||
if(!isLoadingMoreChildren) {
|
if(!isLoadingMoreChildren) {
|
||||||
View view = mNestedScrollView.getChildAt(mNestedScrollView.getChildCount() - 1);
|
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);
|
mCommentCardView.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
mNoCommentWrapperLinearLayout.setVisibility(View.VISIBLE);
|
mNoCommentWrapperLinearLayout.setVisibility(View.VISIBLE);
|
||||||
@ -627,11 +621,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
private void refresh() {
|
private void refresh() {
|
||||||
if(!isRefreshing) {
|
if(!isRefreshing) {
|
||||||
isRefreshing = true;
|
isRefreshing = true;
|
||||||
|
mChildrenStartingIndex = 0;
|
||||||
|
|
||||||
if(mAdapter != null && mCommentsData != null) {
|
if(mAdapter != null) {
|
||||||
int size = mCommentsData.size();
|
mAdapter.clearData();
|
||||||
mCommentsData.clear();
|
|
||||||
mAdapter.notifyItemRangeRemoved(0, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchComment();
|
fetchComment();
|
||||||
|
Loading…
Reference in New Issue
Block a user