mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-11 18:57:11 +01:00
Display single comment thread when clicking a comment from ViewUserDetailActivity instead of showing all the comments.
This commit is contained in:
parent
62dc889867
commit
478b85e67b
@ -56,6 +56,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 5;
|
private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 5;
|
||||||
private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 6;
|
private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 6;
|
||||||
private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 7;
|
private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 7;
|
||||||
|
private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 8;
|
||||||
|
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private Retrofit mRetrofit;
|
private Retrofit mRetrofit;
|
||||||
@ -68,6 +69,8 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
private ArrayList<CommentData> mVisibleComments;
|
private ArrayList<CommentData> mVisibleComments;
|
||||||
private String mSubredditNamePrefixed;
|
private String mSubredditNamePrefixed;
|
||||||
private Locale mLocale;
|
private Locale mLocale;
|
||||||
|
private String mSingleCommentId;
|
||||||
|
private boolean mIsSingleCommentThreadMode;
|
||||||
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
|
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
|
||||||
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
|
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
|
||||||
private boolean isInitiallyLoading;
|
private boolean isInitiallyLoading;
|
||||||
@ -82,8 +85,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
CommentAndPostRecyclerViewAdapter(Activity activity, Retrofit retrofit, Retrofit oauthRetrofit,
|
CommentAndPostRecyclerViewAdapter(Activity activity, Retrofit retrofit, Retrofit oauthRetrofit,
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
|
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
|
||||||
String accessToken, String accountName, Post post, String subredditNamePrefixed,
|
String accessToken, String accountName, Post post, Locale locale,
|
||||||
Locale locale, LoadSubredditIconAsyncTask loadSubredditIconAsyncTask,
|
String singleCommentId, boolean isSingleCommentThreadMode,
|
||||||
|
LoadSubredditIconAsyncTask loadSubredditIconAsyncTask,
|
||||||
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
|
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mRetrofit = retrofit;
|
mRetrofit = retrofit;
|
||||||
@ -94,8 +98,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
mAccountName = accountName;
|
mAccountName = accountName;
|
||||||
mPost = post;
|
mPost = post;
|
||||||
mVisibleComments = new ArrayList<>();
|
mVisibleComments = new ArrayList<>();
|
||||||
mSubredditNamePrefixed = subredditNamePrefixed;
|
mSubredditNamePrefixed = post.getSubredditNamePrefixed();
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
|
mSingleCommentId = singleCommentId;
|
||||||
|
mIsSingleCommentThreadMode = isSingleCommentThreadMode;
|
||||||
mLoadSubredditIconAsyncTask = loadSubredditIconAsyncTask;
|
mLoadSubredditIconAsyncTask = loadSubredditIconAsyncTask;
|
||||||
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
|
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
|
||||||
isInitiallyLoading = true;
|
isInitiallyLoading = true;
|
||||||
@ -122,19 +128,40 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(position == mVisibleComments.size() + 1) {
|
if(mIsSingleCommentThreadMode) {
|
||||||
if(mHasMoreComments) {
|
if(position == 1) {
|
||||||
return VIEW_TYPE_IS_LOADING_MORE_COMMENTS;
|
return VIEW_TYPE_VIEW_ALL_COMMENTS;
|
||||||
} else {
|
|
||||||
return VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CommentData comment = mVisibleComments.get(position - 1);
|
if(position == mVisibleComments.size() + 2) {
|
||||||
if(!comment.isPlaceHolder()) {
|
if(mHasMoreComments) {
|
||||||
return VIEW_TYPE_COMMENT;
|
return VIEW_TYPE_IS_LOADING_MORE_COMMENTS;
|
||||||
|
} else {
|
||||||
|
return VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CommentData comment = mVisibleComments.get(position - 2);
|
||||||
|
if(!comment.isPlaceHolder()) {
|
||||||
|
return VIEW_TYPE_COMMENT;
|
||||||
|
} else {
|
||||||
|
return VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS;
|
if(position == mVisibleComments.size() + 1) {
|
||||||
|
if(mHasMoreComments) {
|
||||||
|
return VIEW_TYPE_IS_LOADING_MORE_COMMENTS;
|
||||||
|
} else {
|
||||||
|
return VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CommentData comment = mVisibleComments.get(position - 1);
|
||||||
|
if(!comment.isPlaceHolder()) {
|
||||||
|
return VIEW_TYPE_COMMENT;
|
||||||
|
} else {
|
||||||
|
return VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,8 +183,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
return new LoadMoreChildCommentsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_load_more_comments_placeholder, parent, false));
|
return new LoadMoreChildCommentsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_load_more_comments_placeholder, parent, false));
|
||||||
case VIEW_TYPE_IS_LOADING_MORE_COMMENTS:
|
case VIEW_TYPE_IS_LOADING_MORE_COMMENTS:
|
||||||
return new IsLoadingMoreCommentsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_footer_loading, parent, false));
|
return new IsLoadingMoreCommentsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_footer_loading, parent, false));
|
||||||
default:
|
case VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED:
|
||||||
return new LoadMoreCommentsFailedViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_footer_error, parent, false));
|
return new LoadMoreCommentsFailedViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_footer_error, parent, false));
|
||||||
|
default:
|
||||||
|
return new ViewAllCommentsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view_all_comments, parent, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +444,12 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if(holder.getItemViewType() == VIEW_TYPE_COMMENT) {
|
} else if(holder.getItemViewType() == VIEW_TYPE_COMMENT) {
|
||||||
CommentData comment = mVisibleComments.get(holder.getAdapterPosition() - 1);
|
CommentData comment;
|
||||||
|
if(mIsSingleCommentThreadMode) {
|
||||||
|
comment = mVisibleComments.get(holder.getAdapterPosition() - 2);
|
||||||
|
} else {
|
||||||
|
comment = mVisibleComments.get(holder.getAdapterPosition() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
String authorPrefixed = "u/" + comment.getAuthor();
|
String authorPrefixed = "u/" + comment.getAuthor();
|
||||||
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
|
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
|
||||||
@ -619,6 +653,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSingleComment(String singleCommentId, boolean isSingleCommentThreadMode) {
|
||||||
|
mSingleCommentId = singleCommentId;
|
||||||
|
mIsSingleCommentThreadMode = isSingleCommentThreadMode;
|
||||||
|
}
|
||||||
|
|
||||||
void initiallyLoading() {
|
void initiallyLoading() {
|
||||||
if(mLoadSubredditIconAsyncTask != null) {
|
if(mLoadSubredditIconAsyncTask != null) {
|
||||||
mLoadSubredditIconAsyncTask.cancel(true);
|
mLoadSubredditIconAsyncTask.cancel(true);
|
||||||
@ -627,7 +666,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
if(mVisibleComments.size() != 0) {
|
if(mVisibleComments.size() != 0) {
|
||||||
int previousSize = mVisibleComments.size();
|
int previousSize = mVisibleComments.size();
|
||||||
mVisibleComments.clear();
|
mVisibleComments.clear();
|
||||||
notifyItemRangeRemoved(1, previousSize);
|
if(mIsSingleCommentThreadMode) {
|
||||||
|
notifyItemRangeRemoved(1, previousSize + 1);
|
||||||
|
} else {
|
||||||
|
notifyItemRangeRemoved(1, previousSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) {
|
if(isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) {
|
||||||
@ -689,10 +732,18 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(mHasMoreComments || loadMoreCommentsFailed) {
|
if(mHasMoreComments || loadMoreCommentsFailed) {
|
||||||
return mVisibleComments.size() + 2;
|
if(mIsSingleCommentThreadMode) {
|
||||||
|
return mVisibleComments.size() + 3;
|
||||||
|
} else {
|
||||||
|
return mVisibleComments.size() + 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mVisibleComments.size() + 1;
|
if(mIsSingleCommentThreadMode) {
|
||||||
|
return mVisibleComments.size() + 2;
|
||||||
|
} else {
|
||||||
|
return mVisibleComments.size() + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PostDetailViewHolder extends RecyclerView.ViewHolder {
|
class PostDetailViewHolder extends RecyclerView.ViewHolder {
|
||||||
@ -1050,7 +1101,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
mVisibleComments.get(getAdapterPosition() - 1).setLoadMoreChildrenFailed(false);
|
mVisibleComments.get(getAdapterPosition() - 1).setLoadMoreChildrenFailed(false);
|
||||||
placeholderTextView.setText(R.string.loading);
|
placeholderTextView.setText(R.string.loading);
|
||||||
|
|
||||||
FetchComment.fetchMoreComment(mRetrofit, mSubredditNamePrefixed, parentComment.getMoreChildrenFullnames(),
|
FetchComment.fetchMoreComment(mRetrofit, parentComment.getMoreChildrenFullnames(),
|
||||||
parentComment.getMoreChildrenStartingIndex(), parentComment.getDepth() + 1, mLocale,
|
parentComment.getMoreChildrenStartingIndex(), parentComment.getDepth() + 1, mLocale,
|
||||||
new FetchComment.FetchMoreCommentListener() {
|
new FetchComment.FetchMoreCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -1238,4 +1289,17 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
retryButton.setOnClickListener(view -> mCommentRecyclerViewAdapterCallback.retryFetchingMoreComments());
|
retryButton.setOnClickListener(view -> mCommentRecyclerViewAdapterCallback.retryFetchingMoreComments());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ViewAllCommentsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
ViewAllCommentsViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(view -> {
|
||||||
|
if(mActivity != null && mActivity instanceof ViewPostDetailActivity) {
|
||||||
|
((ViewPostDetailActivity) mActivity).changeToSingleThreadMode();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,6 +196,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
|
|||||||
linearLayout.setOnClickListener(view -> {
|
linearLayout.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
|
||||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, getItem(getAdapterPosition()).getLinkId());
|
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, getItem(getAdapterPosition()).getLinkId());
|
||||||
|
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, getItem(getAdapterPosition()).getId());
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,10 +23,15 @@ class FetchComment {
|
|||||||
void onFetchMoreCommentFailed();
|
void onFetchMoreCommentFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fetchComments(Retrofit retrofit, String subredditNamePrefixed, String article,
|
static void fetchComments(Retrofit retrofit, String article, String commentId,
|
||||||
Locale locale, FetchCommentListener fetchCommentListener) {
|
Locale locale, FetchCommentListener fetchCommentListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
Call<String> comments = api.getComments(subredditNamePrefixed, article);
|
Call<String> comments;
|
||||||
|
if(commentId == null) {
|
||||||
|
comments = api.getPostAndCommentsById(article);
|
||||||
|
} else {
|
||||||
|
comments = api.getPostAndCommentsSingleThreadById(article, commentId);
|
||||||
|
}
|
||||||
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) {
|
||||||
@ -60,9 +65,8 @@ class FetchComment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fetchMoreComment(Retrofit retrofit, String subredditNamePrefixed,
|
static void fetchMoreComment(Retrofit retrofit, ArrayList<String> allChildren, int startingIndex,
|
||||||
ArrayList<String> allChildren, int startingIndex, int depth,
|
int depth, Locale locale, FetchMoreCommentListener fetchMoreCommentListener) {
|
||||||
Locale locale, FetchMoreCommentListener fetchMoreCommentListener) {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for(int i = 0; i < 100; i++) {
|
for(int i = 0; i < 100; i++) {
|
||||||
if(allChildren.size() <= startingIndex + i) {
|
if(allChildren.size() <= startingIndex + i) {
|
||||||
@ -79,10 +83,10 @@ class FetchComment {
|
|||||||
|
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
Call<String> moreComments = api.getInfo(subredditNamePrefixed, stringBuilder.toString());
|
Call<String> moreComments = api.getInfo(stringBuilder.toString());
|
||||||
moreComments.enqueue(new Callback<String>() {
|
moreComments.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<String> call, Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParseComment.parseMoreComment(response.body(), new ArrayList<>(), locale,
|
ParseComment.parseMoreComment(response.body(), new ArrayList<>(), locale,
|
||||||
depth, new ParseComment.ParseCommentListener() {
|
depth, new ParseComment.ParseCommentListener() {
|
||||||
|
@ -21,10 +21,6 @@ public interface RedditAPI {
|
|||||||
@POST("api/v1/access_token")
|
@POST("api/v1/access_token")
|
||||||
Call<String> getAccessToken(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
|
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);
|
|
||||||
|
|
||||||
@GET("r/{subredditName}/about.json?raw_json=1")
|
@GET("r/{subredditName}/about.json?raw_json=1")
|
||||||
Call<String> getSubredditData(@Path("subredditName") String subredditName);
|
Call<String> getSubredditData(@Path("subredditName") String subredditName);
|
||||||
|
|
||||||
@ -74,8 +70,8 @@ public interface RedditAPI {
|
|||||||
@POST("api/subscribe")
|
@POST("api/subscribe")
|
||||||
Call<String> subredditSubscription(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
|
Call<String> subredditSubscription(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
|
||||||
|
|
||||||
@GET("{subredditNamePrefixed}/api/info.json?raw_json=1")
|
@GET("/api/info.json?raw_json=1")
|
||||||
Call<String> getInfo(@Path("subredditNamePrefixed") String subredditNamePrefixed, @Query("id") String id);
|
Call<String> getInfo(@Query("id") String id);
|
||||||
|
|
||||||
@GET("subreddits/search.json?raw_json=1&include_over_18=on")
|
@GET("subreddits/search.json?raw_json=1&include_over_18=on")
|
||||||
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after, @Query("sort") String sort);
|
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after, @Query("sort") String sort);
|
||||||
@ -120,9 +116,16 @@ public interface RedditAPI {
|
|||||||
@GET("/r/{subredditName}/about/rules.json?raw_json=1")
|
@GET("/r/{subredditName}/about/rules.json?raw_json=1")
|
||||||
Call<String> getRules(@Path("subredditName") String subredditName);
|
Call<String> getRules(@Path("subredditName") String subredditName);
|
||||||
|
|
||||||
|
@GET("/comments/{id}/placeholder/{singleCommentId}.json?context=8&raw_json=1")
|
||||||
|
Call<String> getPostAndCommentsSingleThreadByIdOauth(@Path("id") String id, @Path("singleCommentId") String singleCommentId,
|
||||||
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("/comments/{id}.json?raw_json=1")
|
@GET("/comments/{id}.json?raw_json=1")
|
||||||
Call<String> getPostAndCommentsByIdOauth(@Path("id") String id, @HeaderMap Map<String, String> headers);
|
Call<String> getPostAndCommentsByIdOauth(@Path("id") String id, @HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
|
@GET("/comments/{id}/placeholder/{singleCommentId}.json?context=8&raw_json=1")
|
||||||
|
Call<String> getPostAndCommentsSingleThreadById(@Path("id") String id, @Path("singleCommentId") String singleCommentId);
|
||||||
|
|
||||||
@GET("/comments/{id}.json?raw_json=1")
|
@GET("/comments/{id}.json?raw_json=1")
|
||||||
Call<String> getPostAndCommentsById(@Path("id") String id);
|
Call<String> getPostAndCommentsById(@Path("id") String id);
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
static final String EXTRA_POST_DATA = "EPD";
|
static final String EXTRA_POST_DATA = "EPD";
|
||||||
static final String EXTRA_POST_LIST_POSITION = "EPLI";
|
static final String EXTRA_POST_LIST_POSITION = "EPLI";
|
||||||
static final String EXTRA_POST_ID = "EPI";
|
static final String EXTRA_POST_ID = "EPI";
|
||||||
|
static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
|
||||||
|
|
||||||
private static final int EDIT_POST_REQUEST_CODE = 2;
|
private static final int EDIT_POST_REQUEST_CODE = 2;
|
||||||
static final int EDIT_COMMENT_REQUEST_CODE = 3;
|
static final int EDIT_COMMENT_REQUEST_CODE = 3;
|
||||||
@ -69,6 +70,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
|
|
||||||
private int orientation;
|
private int orientation;
|
||||||
private int postListPosition = -1;
|
private int postListPosition = -1;
|
||||||
|
private String mSingleCommentId;
|
||||||
|
|
||||||
@State
|
@State
|
||||||
boolean mNullAccessToken = false;
|
boolean mNullAccessToken = false;
|
||||||
@ -83,6 +85,8 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
@State
|
@State
|
||||||
boolean isRefreshing = false;
|
boolean isRefreshing = false;
|
||||||
@State
|
@State
|
||||||
|
boolean isSingleCommentThreadMode = false;
|
||||||
|
@State
|
||||||
ArrayList<CommentData> comments;
|
ArrayList<CommentData> comments;
|
||||||
@State
|
@State
|
||||||
ArrayList<String> children;
|
ArrayList<String> children;
|
||||||
@ -186,6 +190,11 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
mLinearLayoutManager = new LinearLayoutManager(this);
|
mLinearLayoutManager = new LinearLayoutManager(this);
|
||||||
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
|
|
||||||
|
mSingleCommentId = getIntent().hasExtra(EXTRA_SINGLE_COMMENT_ID) ? getIntent().getExtras().getString(EXTRA_SINGLE_COMMENT_ID) : null;
|
||||||
|
if(savedInstanceState == null && mSingleCommentId != null) {
|
||||||
|
isSingleCommentThreadMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
orientation = getResources().getConfiguration().orientation;
|
orientation = getResources().getConfiguration().orientation;
|
||||||
|
|
||||||
if(!mNullAccessToken && mAccessToken == null) {
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
@ -246,7 +255,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
}
|
}
|
||||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
||||||
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
|
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
|
||||||
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
mLocale, mSingleCommentId, isSingleCommentThreadMode, mLoadSubredditIconAsyncTask,
|
||||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void updatePost(Post post) {
|
public void updatePost(Post post) {
|
||||||
@ -264,11 +273,11 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
if(comments == null) {
|
if(comments == null) {
|
||||||
fetchComments();
|
fetchComments(false);
|
||||||
} else {
|
} else {
|
||||||
if(isRefreshing) {
|
if(isRefreshing) {
|
||||||
isRefreshing = false;
|
isRefreshing = false;
|
||||||
refresh(false);
|
refresh(true, true);
|
||||||
} else {
|
} else {
|
||||||
mAdapter.addComments(comments, hasMoreChildren);
|
mAdapter.addComments(comments, hasMoreChildren);
|
||||||
if(isLoadingMoreChildren) {
|
if(isLoadingMoreChildren) {
|
||||||
@ -288,9 +297,19 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
|
|
||||||
Call<String> postAndComments;
|
Call<String> postAndComments;
|
||||||
if(mAccessToken == null) {
|
if(mAccessToken == null) {
|
||||||
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId);
|
if(isSingleCommentThreadMode && mSingleCommentId != null) {
|
||||||
|
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadById(subredditId, mSingleCommentId);
|
||||||
|
} else {
|
||||||
|
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId, RedditUtils.getOAuthHeader(mAccessToken));
|
if(isSingleCommentThreadMode && mSingleCommentId != null) {
|
||||||
|
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadByIdOauth(subredditId,
|
||||||
|
mSingleCommentId, RedditUtils.getOAuthHeader(mAccessToken));
|
||||||
|
} else {
|
||||||
|
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId,
|
||||||
|
RedditUtils.getOAuthHeader(mAccessToken));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
postAndComments.enqueue(new Callback<String>() {
|
postAndComments.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
@ -312,7 +331,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
|
|
||||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
||||||
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
|
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
|
||||||
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
mLocale, mSingleCommentId, isSingleCommentThreadMode, mLoadSubredditIconAsyncTask,
|
||||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void updatePost(Post post) {
|
public void updatePost(Post post) {
|
||||||
@ -382,11 +401,15 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchComments() {
|
private void fetchComments(boolean changeRefreshState) {
|
||||||
|
mAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode);
|
||||||
mAdapter.initiallyLoading();
|
mAdapter.initiallyLoading();
|
||||||
|
String commentId = null;
|
||||||
|
if(isSingleCommentThreadMode) {
|
||||||
|
commentId = mSingleCommentId;
|
||||||
|
}
|
||||||
|
|
||||||
FetchComment.fetchComments(mRetrofit, mPost.getSubredditNamePrefixed(), mPost.getId(),
|
FetchComment.fetchComments(mRetrofit, mPost.getId(), commentId, mLocale, new FetchComment.FetchCommentListener() {
|
||||||
mLocale, new FetchComment.FetchCommentListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentSuccess(ArrayList<CommentData> expandedComments,
|
public void onFetchCommentSuccess(ArrayList<CommentData> expandedComments,
|
||||||
String parentId, ArrayList<String> children) {
|
String parentId, ArrayList<String> children) {
|
||||||
@ -414,11 +437,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if(changeRefreshState) {
|
||||||
|
isRefreshing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentFailed() {
|
public void onFetchCommentFailed() {
|
||||||
mAdapter.initiallyLoadCommentsFailed();
|
mAdapter.initiallyLoadCommentsFailed();
|
||||||
|
if(changeRefreshState) {
|
||||||
|
isRefreshing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -429,7 +458,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
}
|
}
|
||||||
|
|
||||||
isLoadingMoreChildren = true;
|
isLoadingMoreChildren = true;
|
||||||
FetchComment.fetchMoreComment(mRetrofit, mPost.getSubredditNamePrefixed(), children, mChildrenStartingIndex,
|
FetchComment.fetchMoreComment(mRetrofit, children, mChildrenStartingIndex,
|
||||||
0, mLocale, new FetchComment.FetchMoreCommentListener() {
|
0, mLocale, new FetchComment.FetchMoreCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchMoreCommentSuccess(ArrayList<CommentData> expandedComments, int childrenStartingIndex) {
|
public void onFetchMoreCommentSuccess(ArrayList<CommentData> expandedComments, int childrenStartingIndex) {
|
||||||
@ -449,7 +478,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean onlyRefreshPost) {
|
private void refresh(boolean fetchPost, boolean fetchComments) {
|
||||||
if(!isRefreshing) {
|
if(!isRefreshing) {
|
||||||
isRefreshing = true;
|
isRefreshing = true;
|
||||||
mChildrenStartingIndex = 0;
|
mChildrenStartingIndex = 0;
|
||||||
@ -457,32 +486,38 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
mGlide.clear(mFetchPostInfoImageView);
|
mGlide.clear(mFetchPostInfoImageView);
|
||||||
|
|
||||||
if(!onlyRefreshPost) {
|
if(fetchComments) {
|
||||||
fetchComments();
|
if(!fetchPost) {
|
||||||
|
fetchComments(true);
|
||||||
|
} else {
|
||||||
|
fetchComments(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Retrofit retrofit;
|
if(fetchPost) {
|
||||||
if(mAccessToken == null) {
|
Retrofit retrofit;
|
||||||
retrofit = mRetrofit;
|
if(mAccessToken == null) {
|
||||||
} else {
|
retrofit = mRetrofit;
|
||||||
retrofit = mOauthRetrofit;
|
} else {
|
||||||
}
|
retrofit = mOauthRetrofit;
|
||||||
FetchPost.fetchPost(retrofit, mPost.getId(), mAccessToken, mLocale,
|
}
|
||||||
new FetchPost.FetchPostListener() {
|
FetchPost.fetchPost(retrofit, mPost.getId(), mAccessToken, mLocale,
|
||||||
@Override
|
new FetchPost.FetchPostListener() {
|
||||||
public void fetchPostSuccess(Post post) {
|
@Override
|
||||||
mPost = post;
|
public void fetchPostSuccess(Post post) {
|
||||||
mAdapter.updatePost(mPost);
|
mPost = post;
|
||||||
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
mAdapter.updatePost(mPost);
|
||||||
isRefreshing = false;
|
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
||||||
}
|
isRefreshing = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostFailed() {
|
public void fetchPostFailed() {
|
||||||
showMessage(R.string.refresh_post_failed);
|
showMessage(R.string.refresh_post_failed);
|
||||||
isRefreshing = false;
|
isRefreshing = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,7 +545,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
@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()) {
|
||||||
refresh(true);
|
refresh(true, false);
|
||||||
showMessage(R.string.mark_nsfw_success);
|
showMessage(R.string.mark_nsfw_success);
|
||||||
} else {
|
} else {
|
||||||
showMessage(R.string.mark_nsfw_failed);
|
showMessage(R.string.mark_nsfw_failed);
|
||||||
@ -532,7 +567,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
@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()) {
|
||||||
refresh(true);
|
refresh(true, false);
|
||||||
showMessage(R.string.unmark_nsfw_success);
|
showMessage(R.string.unmark_nsfw_success);
|
||||||
} else {
|
} else {
|
||||||
showMessage(R.string.unmark_nsfw_failed);
|
showMessage(R.string.unmark_nsfw_failed);
|
||||||
@ -554,7 +589,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
@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()) {
|
||||||
refresh(true);
|
refresh(true, false);
|
||||||
showMessage(R.string.mark_spoiler_success);
|
showMessage(R.string.mark_spoiler_success);
|
||||||
} else {
|
} else {
|
||||||
showMessage(R.string.mark_spoiler_failed);
|
showMessage(R.string.mark_spoiler_failed);
|
||||||
@ -576,7 +611,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
@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()) {
|
||||||
refresh(true);
|
refresh(true, false);
|
||||||
showMessage(R.string.unmark_spoiler_success);
|
showMessage(R.string.unmark_spoiler_success);
|
||||||
} else {
|
} else {
|
||||||
showMessage(R.string.unmark_spoiler_failed);
|
showMessage(R.string.unmark_spoiler_failed);
|
||||||
@ -611,6 +646,12 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void changeToSingleThreadMode() {
|
||||||
|
isSingleCommentThreadMode = false;
|
||||||
|
mSingleCommentId = null;
|
||||||
|
refresh(false, true);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) {
|
public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) {
|
||||||
if(mPost.getId().equals(event.postId)) {
|
if(mPost.getId().equals(event.postId)) {
|
||||||
@ -654,7 +695,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_refresh_view_post_detail_activity:
|
case R.id.action_refresh_view_post_detail_activity:
|
||||||
refresh(false);
|
refresh(true, true);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_comment_view_post_detail_activity:
|
case R.id.action_comment_view_post_detail_activity:
|
||||||
if(mAccessToken == null) {
|
if(mAccessToken == null) {
|
||||||
@ -746,7 +787,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
}
|
}
|
||||||
} else if(requestCode == EDIT_POST_REQUEST_CODE) {
|
} else if(requestCode == EDIT_POST_REQUEST_CODE) {
|
||||||
if(resultCode == RESULT_OK) {
|
if(resultCode == RESULT_OK) {
|
||||||
refresh(true);
|
refresh(true, false);
|
||||||
}
|
}
|
||||||
} else if(requestCode == EDIT_COMMENT_REQUEST_CODE) {
|
} else if(requestCode == EDIT_COMMENT_REQUEST_CODE) {
|
||||||
if(resultCode == RESULT_OK) {
|
if(resultCode == RESULT_OK) {
|
||||||
@ -794,7 +835,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
@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()) {
|
||||||
refresh(true);
|
refresh(true, false);
|
||||||
showMessage(R.string.update_flair_success);
|
showMessage(R.string.update_flair_success);
|
||||||
} else {
|
} else {
|
||||||
showMessage(R.string.update_flair_failed);
|
showMessage(R.string.update_flair_failed);
|
||||||
|
17
app/src/main/res/layout/item_view_all_comments.xml
Normal file
17
app/src/main/res/layout/item_view_all_comments.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/view_all_comments"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@color/colorAccent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -217,6 +217,5 @@
|
|||||||
<string name="edit_flair">Edit Flair</string>
|
<string name="edit_flair">Edit Flair</string>
|
||||||
<string name="only_allow_64_chars">Only allow less than 64 characters</string>
|
<string name="only_allow_64_chars">Only allow less than 64 characters</string>
|
||||||
|
|
||||||
<!-- TODO: Remove or change this placeholder text -->
|
<string name="view_all_comments">Click here to browse all comments</string>
|
||||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user