mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-24 18:08:23 +01:00
Replace the RecyclerView for comments to MultiLevelRecyclerView in order to display the comment trees easily. Click the expand more button to expand the comment tree. Click the expand less button to hide the comment tree. Rewrite some code.
This commit is contained in:
parent
6637cefc05
commit
06a692130c
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -59,4 +59,5 @@ dependencies {
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
||||
implementation 'com.squareup.retrofit2:converter-scalars:2.4.0'
|
||||
implementation 'jp.wasabeef:glide-transformations:3.3.0'
|
||||
implementation 'com.muditsen.multilevelrecyclerview:multilevelview:1.0.0'
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit;
|
||||
|
||||
class CommentData {
|
||||
import com.multilevelview.models.RecyclerViewItem;
|
||||
|
||||
class CommentData extends RecyclerViewItem {
|
||||
private String id;
|
||||
private String fullName;
|
||||
private String author;
|
||||
private String commentTime;
|
||||
@ -14,9 +17,11 @@ class CommentData {
|
||||
private boolean hasReply;
|
||||
private boolean scoreHidden;
|
||||
|
||||
CommentData(String fullName, String author, String commentTime, String commentContent, int score,
|
||||
boolean isSubmitter, String permalink, int depth, boolean collapsed, boolean hasReply,
|
||||
boolean scoreHidden) {
|
||||
CommentData(String id, String fullName, String author, String commentTime, String commentContent,
|
||||
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;
|
||||
@ -30,6 +35,9 @@ class CommentData {
|
||||
this.scoreHidden = scoreHidden;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
@ -71,7 +79,7 @@ class CommentData {
|
||||
return collapsed;
|
||||
}
|
||||
|
||||
public boolean isHasReply() {
|
||||
public boolean hasReply() {
|
||||
return hasReply;
|
||||
}
|
||||
|
||||
|
@ -9,36 +9,100 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.multilevelview.MultiLevelAdapter;
|
||||
import com.multilevelview.MultiLevelRecyclerView;
|
||||
import com.multilevelview.models.RecyclerViewItem;
|
||||
|
||||
import org.sufficientlysecure.htmltextview.HtmlTextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
private Context mContext;
|
||||
private ArrayList<CommentData> mCommentData;
|
||||
private MultiLevelRecyclerView mMultiLevelRecyclerView;
|
||||
private String subredditNamePrefixed;
|
||||
private String article;
|
||||
private Locale locale;
|
||||
|
||||
CommentRecyclerViewAdapter(Context context, ArrayList<CommentData> commentData) {
|
||||
CommentMultiLevelRecyclerViewAdapter(Context context, ArrayList<CommentData> commentData,
|
||||
MultiLevelRecyclerView multiLevelRecyclerView,
|
||||
String subredditNamePrefixed, String article, Locale locale) {
|
||||
super(commentData);
|
||||
mContext = context;
|
||||
mCommentData = commentData;
|
||||
mMultiLevelRecyclerView = multiLevelRecyclerView;
|
||||
this.subredditNamePrefixed = subredditNamePrefixed;
|
||||
this.article = article;
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_comment, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
|
||||
((CommentViewHolder) holder).authorTextView.setText(mCommentData.get(position).getAuthor());
|
||||
((CommentViewHolder) holder).commentTimeTextView.setText(mCommentData.get(position).getCommentTime());
|
||||
((CommentViewHolder) holder).commentHtmlTextView.setHtml(mCommentData.get(position).getCommentContent());
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
|
||||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
|
||||
final CommentData commentItem = mCommentData.get(position);
|
||||
|
||||
switch (mCommentData.get(position).getVoteType()) {
|
||||
((CommentViewHolder) holder).authorTextView.setText(commentItem.getAuthor());
|
||||
((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime());
|
||||
((CommentViewHolder) holder).commentHtmlTextView.setHtml(commentItem.getCommentContent());
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
|
||||
((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16;
|
||||
if(commentItem.hasReply()) {
|
||||
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
||||
}
|
||||
|
||||
((CommentViewHolder) holder).expandButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
|
||||
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
||||
mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
|
||||
} else {
|
||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.VISIBLE);
|
||||
FetchComment.fetchComment(subredditNamePrefixed, article, commentItem.getId(),
|
||||
new FetchComment.FetchCommentListener() {
|
||||
@Override
|
||||
public void onFetchCommentSuccess(String response) {
|
||||
ParseComment.parseComment(response, new ArrayList<CommentData>(),
|
||||
locale, false, commentItem.getDepth(), new ParseComment.ParseCommentListener() {
|
||||
@Override
|
||||
public void onParseCommentSuccess(List<?> commentData, int moreCommentCount) {
|
||||
commentItem.addChildren((List<RecyclerViewItem>) commentData);
|
||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar
|
||||
.setVisibility(View.GONE);
|
||||
mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParseCommentFail() {
|
||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar
|
||||
.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchCommentFail() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
switch (commentItem.getVoteType()) {
|
||||
case 1:
|
||||
((CommentViewHolder) holder).upvoteButton
|
||||
.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
@ -59,19 +123,19 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
if (((CommentViewHolder) holder).upvoteButton.getColorFilter() == null) {
|
||||
((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
if(isDownvotedBefore) {
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 2));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 2));
|
||||
} else {
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 1));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
|
||||
}
|
||||
|
||||
VoteThing.voteThing(mContext, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mCommentData.get(position).setVoteType(1);
|
||||
commentItem.setVoteType(1);
|
||||
if(isDownvotedBefore) {
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 2);
|
||||
commentItem.setScore(commentItem.getScore() + 2);
|
||||
} else {
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 1);
|
||||
commentItem.setScore(commentItem.getScore() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,30 +143,30 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
public void onVoteThingFail(int position) {
|
||||
Toast.makeText(mContext, "Cannot upvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).upvoteButton.clearColorFilter();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
((CommentViewHolder) holder).downvoteButton.setColorFilter(minusButtonColorFilter);
|
||||
}
|
||||
}, mCommentData.get(position).getFullName(), RedditUtils.DIR_UPVOTE, ((CommentViewHolder) holder).getAdapterPosition(), 1);
|
||||
}, commentItem.getFullName(), RedditUtils.DIR_UPVOTE, ((CommentViewHolder) holder).getAdapterPosition(), 1);
|
||||
} else {
|
||||
//Upvoted before
|
||||
((CommentViewHolder) holder).upvoteButton.clearColorFilter();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() - 1));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 1));
|
||||
|
||||
VoteThing.voteThing(mContext, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mCommentData.get(position).setVoteType(0);
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 1);
|
||||
commentItem.setVoteType(0);
|
||||
commentItem.setScore(commentItem.getScore() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 1));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
|
||||
((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 1);
|
||||
commentItem.setScore(commentItem.getScore() + 1);
|
||||
}
|
||||
}, mCommentData.get(position).getFullName(), RedditUtils.DIR_UNVOTE, ((CommentViewHolder) holder).getAdapterPosition(), 1);
|
||||
}, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, ((CommentViewHolder) holder).getAdapterPosition(), 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -118,19 +182,19 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
if (((CommentViewHolder) holder).downvoteButton.getColorFilter() == null) {
|
||||
((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
if (isUpvotedBefore) {
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() - 2));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 2));
|
||||
} else {
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() - 1));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() - 1));
|
||||
}
|
||||
|
||||
VoteThing.voteThing(mContext, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mCommentData.get(position).setVoteType(-1);
|
||||
commentItem.setVoteType(-1);
|
||||
if(isUpvotedBefore) {
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 2);
|
||||
commentItem.setScore(commentItem.getScore() - 2);
|
||||
} else {
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 1);
|
||||
commentItem.setScore(commentItem.getScore() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,38 +202,45 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
public void onVoteThingFail(int position) {
|
||||
Toast.makeText(mContext, "Cannot downvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).downvoteButton.clearColorFilter();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
((CommentViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
|
||||
}
|
||||
}, mCommentData.get(position).getFullName(), RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition(), 1);
|
||||
}, commentItem.getFullName(), RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition(), 1);
|
||||
} else {
|
||||
//Down voted before
|
||||
((CommentViewHolder) holder).downvoteButton.clearColorFilter();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 1));
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
|
||||
|
||||
VoteThing.voteThing(mContext, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
mCommentData.get(position).setVoteType(0);
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore());
|
||||
commentItem.setVoteType(0);
|
||||
commentItem.setScore(commentItem.getScore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
|
||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore());
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
commentItem.setScore(commentItem.getScore());
|
||||
}
|
||||
}, mCommentData.get(position).getFullName(), RedditUtils.DIR_UNVOTE, holder.getAdapterPosition(), 1);
|
||||
}, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, holder.getAdapterPosition(), 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mCommentData.size();
|
||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
|
||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void setExpandButton(ImageView expandButton, boolean isExpanded) {
|
||||
// set the icon based on the current state
|
||||
expandButton.setVisibility(View.VISIBLE);
|
||||
expandButton.setImageResource(isExpanded ? R.drawable.ic_expand_less_black_20dp : R.drawable.ic_expand_more_black_20dp);
|
||||
}
|
||||
|
||||
private class CommentViewHolder extends RecyclerView.ViewHolder {
|
||||
@ -179,7 +250,10 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
private ImageView upvoteButton;
|
||||
private ImageView downvoteButton;
|
||||
private TextView scoreTextView;
|
||||
private ImageView expandButton;
|
||||
private ProgressBar loadMoreCommentsProgressBar;
|
||||
private ImageView replyButton;
|
||||
private View verticalBlock;
|
||||
|
||||
public CommentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@ -189,7 +263,10 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
upvoteButton = itemView.findViewById(R.id.plus_button_item_post_comment);
|
||||
downvoteButton = itemView.findViewById(R.id.minus_button_item_post_comment);
|
||||
scoreTextView = itemView.findViewById(R.id.score_text_view_item_post_comment);
|
||||
loadMoreCommentsProgressBar = itemView.findViewById(R.id.load_more_comments_progress_bar);
|
||||
expandButton = itemView.findViewById(R.id.expand_button_item_post_comment);
|
||||
replyButton = itemView.findViewById(R.id.reply_button_item_post_comment);
|
||||
verticalBlock = itemView.findViewById(R.id.vertical_block_item_post_comment);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,8 @@ class FetchComment {
|
||||
void onFetchCommentFail();
|
||||
}
|
||||
|
||||
static void queryComment(String subredditNamePrefixed, String article, final FetchCommentListener fetchCommentListener) {
|
||||
static void fetchComment(String subredditNamePrefixed, String article, String comment,
|
||||
final FetchCommentListener fetchCommentListener) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(RedditUtils.API_BASE_URI)
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
@ -23,7 +24,7 @@ class FetchComment {
|
||||
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
|
||||
Call<String> comments = api.getComments(subredditNamePrefixed, article);
|
||||
Call<String> comments = api.getComments(subredditNamePrefixed, article, comment);
|
||||
comments.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
|
@ -10,16 +10,18 @@ import org.json.JSONObject;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
class ParseComment {
|
||||
interface ParseCommentListener {
|
||||
void onParseCommentSuccess(ArrayList<CommentData> commentData, int moreCommentCount);
|
||||
void onParseCommentSuccess(List<?> commentData, int moreCommentCount);
|
||||
void onParseCommentFail();
|
||||
}
|
||||
|
||||
static void parseComment(String response, ArrayList<CommentData> commentData, Locale locale, ParseCommentListener parseCommentListener) {
|
||||
new ParseCommentAsyncTask(response, commentData, locale, parseCommentListener).execute();
|
||||
static void parseComment(String response, ArrayList<CommentData> commentData, Locale locale,
|
||||
boolean isPost, int parentDepth, ParseCommentListener parseCommentListener) {
|
||||
new ParseCommentAsyncTask(response, commentData, locale, isPost, parentDepth, parseCommentListener).execute();
|
||||
}
|
||||
|
||||
private static class ParseCommentAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
@ -27,16 +29,21 @@ class ParseComment {
|
||||
private ArrayList<CommentData> commentData;
|
||||
private ArrayList<CommentData> newcommentData;
|
||||
private Locale locale;
|
||||
private boolean isPost;
|
||||
private int parentDepth;
|
||||
private ParseCommentListener parseCommentListener;
|
||||
private boolean parseFailed;
|
||||
private int moreCommentCount;
|
||||
|
||||
ParseCommentAsyncTask(String response, ArrayList<CommentData> commentData, Locale locale, ParseCommentListener parseCommentListener){
|
||||
ParseCommentAsyncTask(String response, ArrayList<CommentData> commentData, Locale locale,
|
||||
boolean isPost, int parentDepth, ParseCommentListener parseCommentListener){
|
||||
try {
|
||||
jsonResponse = new JSONArray(response);
|
||||
this.commentData = commentData;
|
||||
newcommentData = new ArrayList<>();
|
||||
this.locale = locale;
|
||||
this.isPost = isPost;
|
||||
this.parentDepth = parentDepth;
|
||||
this.parseCommentListener = parseCommentListener;
|
||||
parseFailed = false;
|
||||
} catch (JSONException e) {
|
||||
@ -50,8 +57,15 @@ class ParseComment {
|
||||
try {
|
||||
moreCommentCount = 0;
|
||||
int actualCommentLength;
|
||||
JSONArray allComments;
|
||||
|
||||
JSONArray allComments = jsonResponse.getJSONObject(1).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||
if(isPost) {
|
||||
allComments = jsonResponse.getJSONObject(1).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||
} else {
|
||||
allComments = jsonResponse.getJSONObject(1).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY)
|
||||
.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONObject(JSONUtils.REPLIES_KEY)
|
||||
.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||
}
|
||||
if(allComments.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
@ -68,6 +82,7 @@ class ParseComment {
|
||||
|
||||
for (int i = 0; i < actualCommentLength; i++) {
|
||||
JSONObject data = allComments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||
String id = data.getString(JSONUtils.ID_KEY);
|
||||
String fullName = data.getString(JSONUtils.LINK_ID_KEY);
|
||||
String author = data.getString(JSONUtils.AUTHOR_KEY);
|
||||
boolean isSubmitter = data.getBoolean(JSONUtils.IS_SUBMITTER_KEY);
|
||||
@ -85,11 +100,11 @@ class ParseComment {
|
||||
String formattedSubmitTime = new SimpleDateFormat("MMM d, YYYY, HH:mm",
|
||||
locale).format(submitTimeCalendar.getTime());
|
||||
|
||||
int depth = data.getInt(JSONUtils.DEPTH_KEY);
|
||||
int depth = data.getInt(JSONUtils.DEPTH_KEY) + parentDepth;
|
||||
boolean collapsed = data.getBoolean(JSONUtils.COLLAPSED_KEY);
|
||||
boolean hasReply = !(data.get(JSONUtils.REPLIES_KEY) instanceof String);
|
||||
|
||||
newcommentData.add(new CommentData(fullName, author, formattedSubmitTime, commentContent, score, isSubmitter, permalink, depth, collapsed, hasReply, scoreHidden));
|
||||
newcommentData.add(new CommentData(id, fullName, author, formattedSubmitTime, commentContent, score, isSubmitter, permalink, depth, collapsed, hasReply, scoreHidden));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
parseFailed = true;
|
||||
|
@ -17,7 +17,8 @@ public interface RedditAPI {
|
||||
Call<String> getAccessToken(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
|
||||
|
||||
@GET("{subredditNamePrefixed}/comments/{article}.json?raw_json=1")
|
||||
Call<String> getComments(@Path("subredditNamePrefixed") String subredditNamePrefixed, @Path("article") String article);
|
||||
Call<String> getComments(@Path("subredditNamePrefixed") String subredditNamePrefixed,
|
||||
@Path("article") String article, @Query("comment") String comment);
|
||||
|
||||
@GET("r/{subredditName}/about.json?raw_json=1")
|
||||
Call<String> getSubredditData(@Path("subredditName") String subredditName);
|
||||
|
@ -14,7 +14,6 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@ -31,10 +30,12 @@ import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.multilevelview.MultiLevelRecyclerView;
|
||||
|
||||
import org.sufficientlysecure.htmltextview.HtmlTextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
@ -53,7 +54,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
private CoordinatorLayout mCoordinatorLayout;
|
||||
private ProgressBar mCommentProgressbar;
|
||||
private CardView mCommentCardView;
|
||||
private RecyclerView mRecyclerView;
|
||||
private MultiLevelRecyclerView mRecyclerView;
|
||||
|
||||
private LinearLayout mNoCommentWrapperLinearLayout;
|
||||
private ImageView mNoCommentImageView;
|
||||
@ -454,19 +455,25 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
private void queryComment() {
|
||||
mCommentProgressbar.setVisibility(View.VISIBLE);
|
||||
mNoCommentWrapperLinearLayout.setVisibility(View.GONE);
|
||||
FetchComment.queryComment(mPostData.getSubredditNamePrefixed(), mPostData.getId(),
|
||||
new FetchComment.FetchCommentListener() {
|
||||
FetchComment.fetchComment(mPostData.getSubredditNamePrefixed(), mPostData.getId(),
|
||||
null, new FetchComment.FetchCommentListener() {
|
||||
@Override
|
||||
public void onFetchCommentSuccess(String response) {
|
||||
ParseComment.parseComment(response, new ArrayList<CommentData>(),
|
||||
getResources().getConfiguration().locale, new ParseComment.ParseCommentListener() {
|
||||
getResources().getConfiguration().locale, true, 0,
|
||||
new ParseComment.ParseCommentListener() {
|
||||
@Override
|
||||
public void onParseCommentSuccess(ArrayList<CommentData> commentData, int moreCommentCount) {
|
||||
public void onParseCommentSuccess(List<?> commentData, int moreCommentCount) {
|
||||
mCommentProgressbar.setVisibility(View.GONE);
|
||||
mMoreCommentCount = moreCommentCount;
|
||||
if (commentData.size() > 0) {
|
||||
CommentRecyclerViewAdapter adapter = new CommentRecyclerViewAdapter(
|
||||
ViewPostDetailActivity.this, commentData);
|
||||
CommentMultiLevelRecyclerViewAdapter adapter = new CommentMultiLevelRecyclerViewAdapter(
|
||||
ViewPostDetailActivity.this, (ArrayList<CommentData>) commentData,
|
||||
mRecyclerView, mPostData.getSubredditNamePrefixed(),
|
||||
mPostData.getId(), getResources().getConfiguration().locale);
|
||||
mRecyclerView.removeItemClickListeners();
|
||||
mRecyclerView.setToggleItemOnClick(false);
|
||||
mRecyclerView.setAccordion(false);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mCommentCardView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
<vector android:height="12dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="12dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<vector android:height="20dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#010101" android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"/>
|
||||
</vector>
|
@ -1,4 +1,4 @@
|
||||
<vector android:height="12dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="12dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<vector android:height="20dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8 -8,8z"/>
|
||||
</vector>
|
4
app/src/main/res/drawable/ic_expand_less_black_20dp.xml
Normal file
4
app/src/main/res/drawable/ic_expand_less_black_20dp.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<vector android:height="20dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M12,8l-6,6 1.41,1.41L12,10.83l4.59,4.58L18,14z"/>
|
||||
</vector>
|
4
app/src/main/res/drawable/ic_expand_more_black_20dp.xml
Normal file
4
app/src/main/res/drawable/ic_expand_more_black_20dp.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<vector android:height="20dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z"/>
|
||||
</vector>
|
@ -1,4 +1,4 @@
|
||||
<vector android:height="12dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="12dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<vector android:height="20dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M10,9V5l-7,7 7,7v-4.1c5,0 8.5,1.6 11,5.1 -1,-5 -4,-10 -11,-11z"/>
|
||||
</vector>
|
@ -258,7 +258,12 @@
|
||||
android:textColor="#000000"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
<!--<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_view_post_detail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />-->
|
||||
|
||||
<com.multilevelview.MultiLevelRecyclerView
|
||||
android:id="@+id/recycler_view_view_post_detail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
@ -2,104 +2,128 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/linear_layout_item_post_comment"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="8dp">
|
||||
android:id="@+id/linear_layout_item_post_comment">
|
||||
|
||||
<View
|
||||
android:id="@+id/vertical_block_item_post_comment"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/colorPrimary"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/author_text_view_item_post_comment"
|
||||
android:layout_width="0dp"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textColor="@color/colorPrimary"/>
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/comment_time_text_view_item_post_comment"
|
||||
android:layout_width="0dp"
|
||||
<TextView
|
||||
android:id="@+id/author_text_view_item_post_comment"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textColor="@color/colorPrimary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/comment_time_text_view_item_post_comment"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<org.sufficientlysecure.htmltextview.HtmlTextView
|
||||
android:id="@+id/comment_html_text_view_item_post_comment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end"
|
||||
android:layout_marginEnd="16dp" />
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAppearance="@android:style/TextAppearance.Small"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relative_layout_item_post_comment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/plus_button_item_post_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:src="@drawable/ic_arrow_upward_black_20dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:tint="@android:color/tab_indicator_text"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/score_text_view_item_post_comment"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/plus_button_item_post_comment"
|
||||
android:gravity="center"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/minus_button_item_post_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/score_text_view_item_post_comment"
|
||||
android:src="@drawable/ic_arrow_downward_black_20dp"
|
||||
android:tint="@android:color/tab_indicator_text"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/load_more_comments_progress_bar"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_toStartOf="@id/expand_button_item_post_comment"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/expand_button_item_post_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toStartOf="@id/reply_button_item_post_comment"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:tint="@android:color/tab_indicator_text"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/reply_button_item_post_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:src="@drawable/ic_reply_black_20dp"
|
||||
android:tint="@android:color/tab_indicator_text"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<org.sufficientlysecure.htmltextview.HtmlTextView
|
||||
android:id="@+id/comment_html_text_view_item_post_comment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginLeft="32dp"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginRight="32dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:textAppearance="@android:style/TextAppearance.Small"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relative_layout_item_post_comment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginEnd="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/plus_button_item_post_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_arrow_upward_black_12dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:tint="@android:color/tab_indicator_text"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/score_text_view_item_post_comment"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/plus_button_item_post_comment"
|
||||
android:gravity="center"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/minus_button_item_post_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/score_text_view_item_post_comment"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_arrow_downward_black_12dp"
|
||||
android:tint="@android:color/tab_indicator_text"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/reply_button_item_post_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:src="@drawable/ic_reply_black_12dp"
|
||||
android:tint="@android:color/tab_indicator_text"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user