mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 10:28:22 +01:00
Temporarily use the old way to load comments instead of Paging library. Load more parent-level comments once. Loading comments of comments is now working.
This commit is contained in:
parent
0d6296c1a4
commit
c00aaf04b9
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
@ -21,7 +21,6 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.multilevelview.models.RecyclerViewItem;
|
import com.multilevelview.models.RecyclerViewItem;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -77,7 +76,7 @@ public class CommentAdapter extends PagedListAdapter<CommentData, RecyclerView.V
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
|
||||||
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_comment, parent, false));
|
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -122,16 +121,22 @@ public class CommentAdapter extends PagedListAdapter<CommentData, RecyclerView.V
|
|||||||
|
|
||||||
((CommentViewHolder) viewHolder).expandButton.setOnClickListener(view -> {
|
((CommentViewHolder) viewHolder).expandButton.setOnClickListener(view -> {
|
||||||
if(commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
|
if(commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
|
||||||
//mRecyclerView.toggleItemsGroup(viewHolder.getAdapterPosition());
|
|
||||||
setExpandButton(((CommentViewHolder) viewHolder).expandButton, commentItem.isExpanded());
|
setExpandButton(((CommentViewHolder) viewHolder).expandButton, commentItem.isExpanded());
|
||||||
} else {
|
} else {
|
||||||
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar.setVisibility(View.VISIBLE);
|
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar.setVisibility(View.VISIBLE);
|
||||||
FetchComment.fetchComment(mRetrofit, subredditNamePrefixed, article, commentItem.getId(),
|
FetchComment.fetchComment(mRetrofit, subredditNamePrefixed, article, commentItem.getId(),
|
||||||
new FetchComment.FetchCommentListener() {
|
locale, false, commentItem.getDepth(), new FetchComment.FetchCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentSuccess(String response) {
|
public void onFetchCommentSuccess(List<?> commentData,
|
||||||
ParseComment.parseComment(response, new ArrayList<CommentData>(),
|
String parentId, String commaSeparatedChildren) {
|
||||||
locale, false, commentItem.getDepth(), 1,
|
commentItem.addChildren((List<RecyclerViewItem>) commentData);
|
||||||
|
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar
|
||||||
|
.setVisibility(View.GONE);
|
||||||
|
((CommentViewHolder) viewHolder).expandButton
|
||||||
|
.setImageResource(R.drawable.ic_expand_less_black_20dp);
|
||||||
|
|
||||||
|
/*ParseComment.parseComment(response, new ArrayList<>(),
|
||||||
|
locale, false, commentItem.getDepth(),
|
||||||
new ParseComment.ParseCommentListener() {
|
new ParseComment.ParseCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParseCommentSuccess(List<?> commentData,
|
public void onParseCommentSuccess(List<?> commentData,
|
||||||
@ -139,7 +144,6 @@ public class CommentAdapter extends PagedListAdapter<CommentData, RecyclerView.V
|
|||||||
commentItem.addChildren((List<RecyclerViewItem>) commentData);
|
commentItem.addChildren((List<RecyclerViewItem>) commentData);
|
||||||
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar
|
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar
|
||||||
.setVisibility(View.GONE);
|
.setVisibility(View.GONE);
|
||||||
//mRecyclerView.toggleItemsGroup(viewHolder.getAdapterPosition());
|
|
||||||
((CommentViewHolder) viewHolder).expandButton
|
((CommentViewHolder) viewHolder).expandButton
|
||||||
.setImageResource(R.drawable.ic_expand_less_black_20dp);
|
.setImageResource(R.drawable.ic_expand_less_black_20dp);
|
||||||
}
|
}
|
||||||
@ -149,12 +153,13 @@ public class CommentAdapter extends PagedListAdapter<CommentData, RecyclerView.V
|
|||||||
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar
|
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar
|
||||||
.setVisibility(View.GONE);
|
.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentFail() {
|
public void onFetchCommentFailed() {
|
||||||
|
((CommentViewHolder) viewHolder).loadMoreCommentsProgressBar
|
||||||
|
.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParseComment.parseComment(response.body(), new ArrayList<>(), locale, isPost,
|
ParseComment.parseComment(response.body(), new ArrayList<>(), locale, isPost,
|
||||||
0, 1, new ParseComment.ParseCommentListener() {
|
0, new ParseComment.ParseCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParseCommentSuccess(List<?> commentData, String parentId,
|
public void onParseCommentSuccess(List<?> commentData, String parentId,
|
||||||
String commaSeparatedChildren) {
|
String commaSeparatedChildren) {
|
||||||
@ -138,8 +138,8 @@ public class CommentDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<String> call, Response<String> response) {
|
public void onResponse(Call<String> call, Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParseComment.parseMoreComment(response.body(), new ArrayList<>(), locale, isPost,
|
ParseComment.parseMoreComment(response.body(), new ArrayList<>(), locale,
|
||||||
0, 0, new ParseComment.ParseCommentListener() {
|
0, new ParseComment.ParseCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParseCommentSuccess(List<?> commentData, String parentId,
|
public void onParseCommentSuccess(List<?> commentData, String parentId,
|
||||||
String commaSeparatedChildren) {
|
String commaSeparatedChildren) {
|
||||||
|
@ -9,6 +9,7 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.customtabs.CustomTabsIntent;
|
import android.support.customtabs.CustomTabsIntent;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -61,7 +62,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(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));
|
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,11 +79,11 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
|
|
||||||
((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime());
|
((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime());
|
||||||
SpannableConfiguration spannableConfiguration = SpannableConfiguration.builder(mContext).linkResolver((view, link) -> {
|
SpannableConfiguration spannableConfiguration = SpannableConfiguration.builder(mContext).linkResolver((view, link) -> {
|
||||||
if(link.startsWith("/u/")) {
|
if (link.startsWith("/u/")) {
|
||||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3));
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3));
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
} else if(link.startsWith("/r/")) {
|
} else if (link.startsWith("/r/")) {
|
||||||
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
||||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3));
|
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3));
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
@ -100,45 +101,36 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||||
|
|
||||||
((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16;
|
((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16;
|
||||||
if(commentItem.hasReply()) {
|
if (commentItem.hasReply()) {
|
||||||
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
||||||
}
|
}
|
||||||
|
|
||||||
((CommentViewHolder) holder).expandButton.setOnClickListener(view -> {
|
((CommentViewHolder) holder).expandButton.setOnClickListener(view -> {
|
||||||
if(commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
|
if (commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
|
||||||
mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
|
mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
|
||||||
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
||||||
} else {
|
} else {
|
||||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.VISIBLE);
|
((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.VISIBLE);
|
||||||
FetchComment.fetchComment(mRetrofit, subredditNamePrefixed, article, commentItem.getId(),
|
FetchComment.fetchComment(mRetrofit, subredditNamePrefixed, article, commentItem.getId(),
|
||||||
new FetchComment.FetchCommentListener() {
|
locale, false, commentItem.getDepth(), new FetchComment.FetchCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentSuccess(String response) {
|
public void onFetchCommentSuccess(List<?> commentData,
|
||||||
ParseComment.parseComment(response, new ArrayList<CommentData>(),
|
String parentId, String commaSeparatedChildren) {
|
||||||
locale, false, commentItem.getDepth(), 1,
|
commentItem.addChildren((List<RecyclerViewItem>) commentData);
|
||||||
new ParseComment.ParseCommentListener() {
|
for (RecyclerViewItem r : (List<RecyclerViewItem>) commentData) {
|
||||||
@Override
|
Log.i("asdfasdfasd", Integer.toString(r.getLevel()));
|
||||||
public void onParseCommentSuccess(List<?> commentData,
|
}
|
||||||
String parentId, String commaSeparatedChildren) {
|
((CommentViewHolder) holder).loadMoreCommentsProgressBar
|
||||||
commentItem.addChildren((List<RecyclerViewItem>) commentData);
|
.setVisibility(View.GONE);
|
||||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar
|
mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
|
||||||
.setVisibility(View.GONE);
|
((CommentViewHolder) holder).expandButton
|
||||||
mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
|
.setImageResource(R.drawable.ic_expand_less_black_20dp);
|
||||||
((CommentViewHolder) holder).expandButton
|
|
||||||
.setImageResource(R.drawable.ic_expand_less_black_20dp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onParseCommentFailed() {
|
|
||||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar
|
|
||||||
.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentFail() {
|
public void onFetchCommentFailed() {
|
||||||
|
((CommentViewHolder) holder).loadMoreCommentsProgressBar
|
||||||
|
.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -162,17 +154,17 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
|
|
||||||
if (((CommentViewHolder) holder).upvoteButton.getColorFilter() == null) {
|
if (((CommentViewHolder) holder).upvoteButton.getColorFilter() == null) {
|
||||||
((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
if(isDownvotedBefore) {
|
if (isDownvotedBefore) {
|
||||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 2));
|
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 2));
|
||||||
} else {
|
} else {
|
||||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
|
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit,mSharedPreferences, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
commentItem.setVoteType(1);
|
commentItem.setVoteType(1);
|
||||||
if(isDownvotedBefore) {
|
if (isDownvotedBefore) {
|
||||||
commentItem.setScore(commentItem.getScore() + 2);
|
commentItem.setScore(commentItem.getScore() + 2);
|
||||||
} else {
|
} else {
|
||||||
commentItem.setScore(commentItem.getScore() + 1);
|
commentItem.setScore(commentItem.getScore() + 1);
|
||||||
@ -228,7 +220,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position12) {
|
public void onVoteThingSuccess(int position12) {
|
||||||
commentItem.setVoteType(-1);
|
commentItem.setVoteType(-1);
|
||||||
if(isUpvotedBefore) {
|
if (isUpvotedBefore) {
|
||||||
commentItem.setScore(commentItem.getScore() - 2);
|
commentItem.setScore(commentItem.getScore() - 2);
|
||||||
} else {
|
} else {
|
||||||
commentItem.setScore(commentItem.getScore() - 1);
|
commentItem.setScore(commentItem.getScore() - 1);
|
||||||
@ -269,8 +261,16 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
|
if (holder instanceof CommentViewHolder) {
|
||||||
((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.GONE);
|
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
|
||||||
|
((CommentViewHolder) holder).loadMoreCommentsProgressBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addComments(ArrayList<CommentData> comments) {
|
||||||
|
int sizeBefore = mCommentData.size();
|
||||||
|
mCommentData.addAll(comments);
|
||||||
|
notifyItemRangeInserted(sizeBefore, mCommentData.size() - sizeBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setExpandButton(ImageView expandButton, boolean isExpanded) {
|
private void setExpandButton(ImageView expandButton, boolean isExpanded) {
|
||||||
@ -280,16 +280,26 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CommentViewHolder extends RecyclerView.ViewHolder {
|
class CommentViewHolder extends RecyclerView.ViewHolder {
|
||||||
@BindView(R.id.author_text_view_item_post_comment) TextView authorTextView;
|
@BindView(R.id.author_text_view_item_post_comment)
|
||||||
@BindView(R.id.comment_time_text_view_item_post_comment) TextView commentTimeTextView;
|
TextView authorTextView;
|
||||||
@BindView(R.id.comment_markdown_view_item_post_comment) MarkwonView commentMarkdownView;
|
@BindView(R.id.comment_time_text_view_item_post_comment)
|
||||||
@BindView(R.id.plus_button_item_post_comment) ImageView upvoteButton;
|
TextView commentTimeTextView;
|
||||||
@BindView(R.id.score_text_view_item_post_comment) TextView scoreTextView;
|
@BindView(R.id.comment_markdown_view_item_post_comment)
|
||||||
@BindView(R.id.minus_button_item_post_comment) ImageView downvoteButton;
|
MarkwonView commentMarkdownView;
|
||||||
@BindView(R.id.expand_button_item_post_comment) ImageView expandButton;
|
@BindView(R.id.plus_button_item_post_comment)
|
||||||
@BindView(R.id.load_more_comments_progress_bar) ProgressBar loadMoreCommentsProgressBar;
|
ImageView upvoteButton;
|
||||||
@BindView(R.id.reply_button_item_post_comment) ImageView replyButton;
|
@BindView(R.id.score_text_view_item_post_comment)
|
||||||
@BindView(R.id.vertical_block_item_post_comment) View verticalBlock;
|
TextView scoreTextView;
|
||||||
|
@BindView(R.id.minus_button_item_post_comment)
|
||||||
|
ImageView downvoteButton;
|
||||||
|
@BindView(R.id.expand_button_item_post_comment)
|
||||||
|
ImageView expandButton;
|
||||||
|
@BindView(R.id.load_more_comments_progress_bar)
|
||||||
|
ProgressBar loadMoreCommentsProgressBar;
|
||||||
|
@BindView(R.id.reply_button_item_post_comment)
|
||||||
|
ImageView replyButton;
|
||||||
|
@BindView(R.id.vertical_block_item_post_comment)
|
||||||
|
View verticalBlock;
|
||||||
|
|
||||||
CommentViewHolder(View itemView) {
|
CommentViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
@ -3,6 +3,10 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@ -10,30 +14,115 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
class FetchComment {
|
class FetchComment {
|
||||||
interface FetchCommentListener {
|
interface FetchCommentListener {
|
||||||
void onFetchCommentSuccess(String response);
|
void onFetchCommentSuccess(List<?> commentData,
|
||||||
void onFetchCommentFail();
|
String parentId, String commaSeparatedChildren);
|
||||||
|
void onFetchCommentFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fetchComment(Retrofit retrofit, String subredditNamePrefixed, String article, String comment,
|
interface FetchMoreCommentListener {
|
||||||
|
void onFetchMoreCommentSuccess(List<?> commentData);
|
||||||
|
void onFetchMoreCommentFailed();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fetchComment(Retrofit retrofit, String subredditNamePrefixed, String article,
|
||||||
|
String comment, Locale locale, boolean isPost, int parentDepth,
|
||||||
final FetchCommentListener fetchCommentListener) {
|
final FetchCommentListener fetchCommentListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
Call<String> comments = api.getComments(subredditNamePrefixed, article, comment);
|
Call<String> comments = api.getComments(subredditNamePrefixed, article, comment);
|
||||||
comments.enqueue(new Callback<String>() {
|
comments.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
fetchCommentListener.onFetchCommentSuccess(response.body());
|
ParseComment.parseComment(response.body(), new ArrayList<>(),
|
||||||
|
locale, isPost, parentDepth,
|
||||||
|
new ParseComment.ParseCommentListener() {
|
||||||
|
@Override
|
||||||
|
public void onParseCommentSuccess(List<?> commentData,
|
||||||
|
String parentId, String commaSeparatedChildren) {
|
||||||
|
fetchCommentListener.onFetchCommentSuccess(commentData, parentId,
|
||||||
|
commaSeparatedChildren);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onParseCommentFailed() {
|
||||||
|
Log.i("parse failed", "parse failed");
|
||||||
|
fetchCommentListener.onFetchCommentFailed();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
Log.i("call failed", response.message());
|
Log.i("call failed", response.message());
|
||||||
fetchCommentListener.onFetchCommentFail();
|
fetchCommentListener.onFetchCommentFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
Log.i("call failed", t.getMessage());
|
Log.i("call failed", t.getMessage());
|
||||||
fetchCommentListener.onFetchCommentFail();
|
fetchCommentListener.onFetchCommentFailed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fetchMoreComment(Retrofit retrofit, String subredditNamePrefixed, String mParentId,
|
||||||
|
String children, Locale locale, FetchMoreCommentListener fetchMoreCommentListener) {
|
||||||
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
Call<String> moreChildrenBasicInfo = api.getMoreChildren(mParentId, children);
|
||||||
|
moreChildrenBasicInfo.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<String> call, Response<String> response) {
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
ParseComment.parseMoreCommentBasicInfo(response.body(), new ParseComment.ParseMoreCommentBasicInfoListener() {
|
||||||
|
@Override
|
||||||
|
public void onParseMoreCommentBasicInfoSuccess(String commaSeparatedChildrenId) {
|
||||||
|
Call<String> moreComments = api.getInfo(subredditNamePrefixed, commaSeparatedChildrenId);
|
||||||
|
moreComments.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<String> call, Response<String> response) {
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
ParseComment.parseMoreComment(response.body(), new ArrayList<>(), locale,
|
||||||
|
0, new ParseComment.ParseCommentListener() {
|
||||||
|
@Override
|
||||||
|
public void onParseCommentSuccess(List<?> commentData, String parentId,
|
||||||
|
String commaSeparatedChildren) {
|
||||||
|
fetchMoreCommentListener.onFetchMoreCommentSuccess(commentData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onParseCommentFailed() {
|
||||||
|
fetchMoreCommentListener.onFetchMoreCommentFailed();
|
||||||
|
Log.i("comment parse failed", "comment parse failed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Log.i("more comment failed", response.message());
|
||||||
|
fetchMoreCommentListener.onFetchMoreCommentFailed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<String> call, Throwable t) {
|
||||||
|
Log.i("more comment failed", t.getMessage());
|
||||||
|
fetchMoreCommentListener.onFetchMoreCommentFailed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onParseMoreCommentBasicInfoFailed() {
|
||||||
|
Log.i("comment parse failed", "comment parse failed");
|
||||||
|
fetchMoreCommentListener.onFetchMoreCommentFailed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Log.i("basic info failed", response.message());
|
||||||
|
fetchMoreCommentListener.onFetchMoreCommentFailed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<String> call, Throwable t) {
|
||||||
|
Log.i("basic info failed", t.getMessage());
|
||||||
|
fetchMoreCommentListener.onFetchMoreCommentFailed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -25,18 +25,18 @@ class ParseComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void parseComment(String response, ArrayList<CommentData> commentData, Locale locale,
|
static void parseComment(String response, ArrayList<CommentData> commentData, Locale locale,
|
||||||
boolean isPost, int parentDepth, int childrenStartIndex, ParseCommentListener parseCommentListener) {
|
boolean isPost, int parentDepth, ParseCommentListener parseCommentListener) {
|
||||||
try {
|
try {
|
||||||
JSONArray childrenArray = new JSONArray(response);
|
JSONArray childrenArray = new JSONArray(response);
|
||||||
|
|
||||||
if(isPost) {
|
if(isPost) {
|
||||||
childrenArray = childrenArray.getJSONObject(childrenStartIndex).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
childrenArray = childrenArray.getJSONObject(1).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||||
} else {
|
} else {
|
||||||
childrenArray = childrenArray.getJSONObject(childrenStartIndex).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY)
|
childrenArray = childrenArray.getJSONObject(1).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY)
|
||||||
.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONObject(JSONUtils.REPLIES_KEY)
|
.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONObject(JSONUtils.REPLIES_KEY)
|
||||||
.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||||
}
|
}
|
||||||
new ParseCommentAsyncTask(childrenArray, commentData, locale, isPost, parentDepth, childrenStartIndex, parseCommentListener).execute();
|
new ParseCommentAsyncTask(childrenArray, commentData, locale, parentDepth, parseCommentListener).execute();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.i("comment json error", e.getMessage());
|
Log.i("comment json error", e.getMessage());
|
||||||
@ -49,10 +49,10 @@ class ParseComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void parseMoreComment(String response, ArrayList<CommentData> commentData, Locale locale,
|
static void parseMoreComment(String response, ArrayList<CommentData> commentData, Locale locale,
|
||||||
boolean isPost, int parentDepth, int childrenStartIndex, ParseCommentListener parseCommentListener) {
|
int parentDepth, ParseCommentListener parseCommentListener) {
|
||||||
try {
|
try {
|
||||||
JSONArray childrenArray = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
JSONArray childrenArray = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||||
new ParseCommentAsyncTask(childrenArray, commentData, locale, isPost, parentDepth, childrenStartIndex, parseCommentListener).execute();
|
new ParseCommentAsyncTask(childrenArray, commentData, locale, parentDepth, parseCommentListener).execute();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.i("comment json error", e.getMessage());
|
Log.i("comment json error", e.getMessage());
|
||||||
@ -66,23 +66,19 @@ class ParseComment {
|
|||||||
private ArrayList<CommentData> newcommentData;
|
private ArrayList<CommentData> newcommentData;
|
||||||
private StringBuilder commaSeparatedChildren;
|
private StringBuilder commaSeparatedChildren;
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
private boolean isPost;
|
|
||||||
private int parentDepth;
|
private int parentDepth;
|
||||||
private int childrenStartIndex;
|
|
||||||
private ParseCommentListener parseCommentListener;
|
private ParseCommentListener parseCommentListener;
|
||||||
private boolean parseFailed;
|
private boolean parseFailed;
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
ParseCommentAsyncTask(JSONArray comments, ArrayList<CommentData> commentData, Locale locale,
|
ParseCommentAsyncTask(JSONArray comments, ArrayList<CommentData> commentData, Locale locale,
|
||||||
boolean isPost, int parentDepth, int childrenStartIndex, ParseCommentListener parseCommentListener){
|
int parentDepth, ParseCommentListener parseCommentListener){
|
||||||
this.comments = comments;
|
this.comments = comments;
|
||||||
this.commentData = commentData;
|
this.commentData = commentData;
|
||||||
newcommentData = new ArrayList<>();
|
newcommentData = new ArrayList<>();
|
||||||
commaSeparatedChildren = new StringBuilder();
|
commaSeparatedChildren = new StringBuilder();
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.isPost = isPost;
|
|
||||||
this.parentDepth = parentDepth;
|
this.parentDepth = parentDepth;
|
||||||
this.childrenStartIndex = childrenStartIndex;
|
|
||||||
parseFailed = false;
|
parseFailed = false;
|
||||||
this.parseCommentListener = parseCommentListener;
|
this.parseCommentListener = parseCommentListener;
|
||||||
}
|
}
|
||||||
@ -93,13 +89,6 @@ class ParseComment {
|
|||||||
int actualCommentLength;
|
int actualCommentLength;
|
||||||
ArrayList<String> children = new ArrayList<>();
|
ArrayList<String> children = new ArrayList<>();
|
||||||
|
|
||||||
/*if(isPost) {
|
|
||||||
allComments = comments.getJSONObject(childrenStartIndex).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
|
||||||
} else {
|
|
||||||
allComments = comments.getJSONObject(childrenStartIndex).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(comments.length() == 0) {
|
if(comments.length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.arch.lifecycle.ViewModelProviders;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
@ -19,7 +18,6 @@ import android.support.v7.app.AppCompatActivity;
|
|||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.support.v7.widget.DividerItemDecoration;
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@ -38,8 +36,12 @@ import com.bumptech.glide.request.RequestListener;
|
|||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
||||||
|
import com.multilevelview.MultiLevelRecyclerView;
|
||||||
import com.santalu.aspectratioimageview.AspectRatioImageView;
|
import com.santalu.aspectratioimageview.AspectRatioImageView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
@ -65,6 +67,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private Post mPost;
|
private Post mPost;
|
||||||
|
|
||||||
|
private String mCommaSeparatedChildren;
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_view_post_detail) CoordinatorLayout mCoordinatorLayout;
|
@BindView(R.id.coordinator_layout_view_post_detail) CoordinatorLayout mCoordinatorLayout;
|
||||||
@BindView(R.id.subreddit_icon_name_linear_layout_view_post_detail) LinearLayout mSubredditIconNameLinearLayout;
|
@BindView(R.id.subreddit_icon_name_linear_layout_view_post_detail) LinearLayout mSubredditIconNameLinearLayout;
|
||||||
@BindView(R.id.subreddit_icon_circle_image_view_view_post_detail) AspectRatioGifImageView mSubredditIconGifImageView;
|
@BindView(R.id.subreddit_icon_circle_image_view_view_post_detail) AspectRatioGifImageView mSubredditIconGifImageView;
|
||||||
@ -91,11 +95,13 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@BindView(R.id.comment_progress_bar_view_post_detail) CircleProgressBar mCommentProgressbar;
|
@BindView(R.id.comment_progress_bar_view_post_detail) CircleProgressBar mCommentProgressbar;
|
||||||
@BindView(R.id.comment_card_view_view_post_detail) CardView mCommentCardView;
|
@BindView(R.id.comment_card_view_view_post_detail) CardView mCommentCardView;
|
||||||
@BindView(R.id.recycler_view_view_post_detail) RecyclerView mRecyclerView;
|
@BindView(R.id.recycler_view_view_post_detail) MultiLevelRecyclerView mRecyclerView;
|
||||||
|
|
||||||
@BindView(R.id.no_comment_wrapper_linear_layout_view_post_detail) LinearLayout mNoCommentWrapperLinearLayout;
|
@BindView(R.id.no_comment_wrapper_linear_layout_view_post_detail) LinearLayout mNoCommentWrapperLinearLayout;
|
||||||
@BindView(R.id.no_comment_image_view_view_post_detail) ImageView mNoCommentImageView;
|
@BindView(R.id.no_comment_image_view_view_post_detail) ImageView mNoCommentImageView;
|
||||||
|
|
||||||
|
private CommentMultiLevelRecyclerViewAdapter mAdapter;
|
||||||
|
private LinearLayoutManager mLayoutManager;
|
||||||
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
|
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
|
||||||
|
|
||||||
@Inject @Named("no_oauth")
|
@Inject @Named("no_oauth")
|
||||||
@ -208,8 +214,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
mCrosspostImageView.setVisibility(View.VISIBLE);
|
mCrosspostImageView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mLayoutManager = new LinearLayoutManager(this);
|
||||||
mRecyclerView.setNestedScrollingEnabled(false);
|
mRecyclerView.setNestedScrollingEnabled(false);
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||||
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
||||||
|
|
||||||
mSubredditTextView.setText(mPost.getSubredditNamePrefixed());
|
mSubredditTextView.setText(mPost.getSubredditNamePrefixed());
|
||||||
@ -327,9 +334,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//queryComment();
|
|
||||||
|
|
||||||
CommentAdapter adapter = new CommentAdapter(this, mRetrofit, mOauthRetrofit, mSharedPreferences,
|
fetchComment();
|
||||||
|
|
||||||
|
/*CommentAdapter mAdapter = new CommentAdapter(this, mRetrofit, mOauthRetrofit, mSharedPreferences,
|
||||||
mRecyclerView, mPost.getSubredditNamePrefixed(), mPost.getId(), getResources().getConfiguration().locale);
|
mRecyclerView, mPost.getSubredditNamePrefixed(), mPost.getId(), getResources().getConfiguration().locale);
|
||||||
|
|
||||||
CommentViewModel.Factory factory = new CommentViewModel.Factory(mRetrofit, getResources().getConfiguration().locale,
|
CommentViewModel.Factory factory = new CommentViewModel.Factory(mRetrofit, getResources().getConfiguration().locale,
|
||||||
@ -337,10 +345,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void hasComment() {
|
public void hasComment() {
|
||||||
mCommentProgressbar.setVisibility(View.GONE);
|
mCommentProgressbar.setVisibility(View.GONE);
|
||||||
/*mRecyclerView.removeItemClickListeners();
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
mRecyclerView.setToggleItemOnClick(false);
|
|
||||||
mRecyclerView.setAccordion(false);*/
|
|
||||||
mRecyclerView.setAdapter(adapter);
|
|
||||||
mCommentCardView.setVisibility(View.VISIBLE);
|
mCommentCardView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +356,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CommentViewModel commentViewModel = ViewModelProviders.of(this, factory).get(CommentViewModel.class);
|
CommentViewModel commentViewModel = ViewModelProviders.of(this, factory).get(CommentViewModel.class);
|
||||||
commentViewModel.getComments().observe(this, posts -> adapter.submitList(posts));
|
commentViewModel.getComments().observe(this, posts -> mAdapter.submitList(posts));*/
|
||||||
|
|
||||||
|
|
||||||
mUpvoteButton.setOnClickListener(view -> {
|
mUpvoteButton.setOnClickListener(view -> {
|
||||||
@ -467,52 +472,59 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private void queryComment() {
|
private void fetchComment() {
|
||||||
mCommentProgressbar.setVisibility(View.VISIBLE);
|
mCommentProgressbar.setVisibility(View.VISIBLE);
|
||||||
mNoCommentWrapperLinearLayout.setVisibility(View.GONE);
|
mNoCommentWrapperLinearLayout.setVisibility(View.GONE);
|
||||||
FetchComment.fetchComment(mRetrofit, mPost.getSubredditNamePrefixed(), mPost.getId(),
|
FetchComment.fetchComment(mRetrofit, mPost.getSubredditNamePrefixed(), mPost.getId(),
|
||||||
null, new FetchComment.FetchCommentListener() {
|
null, getResources().getConfiguration().locale, true, 0, new FetchComment.FetchCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentSuccess(String response) {
|
public void onFetchCommentSuccess(List<?> commentData,
|
||||||
ParseComment.parseComment(response, new ArrayList<CommentData>(),
|
String parentId, String commaSeparatedChildren) {
|
||||||
getResources().getConfiguration().locale, true, 0, 1,
|
mCommaSeparatedChildren = commaSeparatedChildren;
|
||||||
new ParseComment.ParseCommentListener() {
|
mCommentProgressbar.setVisibility(View.GONE);
|
||||||
@Override
|
if (commentData.size() > 0) {
|
||||||
public void onParseCommentSuccess(List<?> commentData,
|
mAdapter = new CommentMultiLevelRecyclerViewAdapter(
|
||||||
String parentId, String commaSeparatedChildren) {
|
ViewPostDetailActivity.this, mRetrofit, mOauthRetrofit,
|
||||||
mCommentProgressbar.setVisibility(View.GONE);
|
mSharedPreferences, (ArrayList<CommentData>) commentData,
|
||||||
if (commentData.size() > 0) {
|
mRecyclerView, mPost.getSubredditNamePrefixed(),
|
||||||
CommentMultiLevelRecyclerViewAdapter adapter = new CommentMultiLevelRecyclerViewAdapter(
|
mPost.getId(), getResources().getConfiguration().locale);
|
||||||
ViewPostDetailActivity.this, mRetrofit, mOauthRetrofit,
|
mRecyclerView.removeItemClickListeners();
|
||||||
mSharedPreferences, (ArrayList<CommentData>) commentData,
|
mRecyclerView.setToggleItemOnClick(false);
|
||||||
mRecyclerView, mPost.getSubredditNamePrefixed(),
|
mRecyclerView.setAccordion(false);
|
||||||
mPost.getId(), getResources().getConfiguration().locale);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
mRecyclerView.removeItemClickListeners();
|
mCommentCardView.setVisibility(View.VISIBLE);
|
||||||
mRecyclerView.setToggleItemOnClick(false);
|
|
||||||
mRecyclerView.setAccordion(false);
|
|
||||||
mRecyclerView.setAdapter(adapter);
|
|
||||||
mCommentCardView.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
mNoCommentWrapperLinearLayout.setVisibility(View.VISIBLE);
|
|
||||||
glide.load(R.drawable.no_comment_indicator).into(mNoCommentImageView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
fetchMoreComment();
|
||||||
public void onParseCommentFailed() {
|
} else {
|
||||||
mCommentProgressbar.setVisibility(View.GONE);
|
mNoCommentWrapperLinearLayout.setVisibility(View.VISIBLE);
|
||||||
showRetrySnackbar();
|
glide.load(R.drawable.no_comment_indicator).into(mNoCommentImageView);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentFail() {
|
public void onFetchCommentFailed() {
|
||||||
mCommentProgressbar.setVisibility(View.GONE);
|
mCommentProgressbar.setVisibility(View.GONE);
|
||||||
showRetrySnackbar();
|
showRetrySnackbar();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
private void fetchMoreComment() {
|
||||||
|
FetchComment.fetchMoreComment(mRetrofit, mPost.getSubredditNamePrefixed(), mPost.getFullName(),
|
||||||
|
mCommaSeparatedChildren, getResources().getConfiguration().locale, new FetchComment.FetchMoreCommentListener() {
|
||||||
|
@Override
|
||||||
|
public void onFetchMoreCommentSuccess(List<?> commentData) {
|
||||||
|
mAdapter.addComments((ArrayList<CommentData>) commentData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFetchMoreCommentFailed() {
|
||||||
|
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, R.string.load_more_comment_failed, Snackbar.LENGTH_INDEFINITE);
|
||||||
|
snackbar.setAction(R.string.retry, view -> fetchMoreComment());
|
||||||
|
snackbar.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void loadImage() {
|
private void loadImage() {
|
||||||
RequestBuilder imageRequestBuilder = glide.load(mPost.getPreviewUrl())
|
RequestBuilder imageRequestBuilder = glide.load(mPost.getPreviewUrl())
|
||||||
@ -568,12 +580,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void showRetrySnackbar() {
|
private void showRetrySnackbar() {
|
||||||
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, R.string.load_comment_failed, Snackbar.LENGTH_INDEFINITE);
|
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, R.string.load_comment_failed, Snackbar.LENGTH_INDEFINITE);
|
||||||
snackbar.setAction(R.string.retry, new View.OnClickListener() {
|
snackbar.setAction(R.string.retry, view -> fetchComment());
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
//queryComment();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@
|
|||||||
android:textColor="#000000"
|
android:textColor="#000000"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<com.multilevelview.MultiLevelRecyclerView
|
||||||
android:id="@+id/recycler_view_view_post_detail"
|
android:id="@+id/recycler_view_view_post_detail"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
<string name="load_data_failed">Cannot load posts</string>
|
<string name="load_data_failed">Cannot load posts</string>
|
||||||
<string name="load_comment_failed">Error loading comments</string>
|
<string name="load_comment_failed">Error loading comments</string>
|
||||||
|
<string name="load_more_comment_failed">Error loading more comments</string>
|
||||||
<string name="retry">Retry</string>
|
<string name="retry">Retry</string>
|
||||||
<string name="comments">Comments</string>
|
<string name="comments">Comments</string>
|
||||||
<string name="no_comments_yet">No comments yet. Write a comment?</string>
|
<string name="no_comments_yet">No comments yet. Write a comment?</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user