aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-15 05:35:25 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-15 05:35:25 +0000
commit478b85e67b1798ab6b0bdc4392785c40fe1c1307 (patch)
treef5f9154e7910caa4d32de4d2ae17e4d6785d1197 /app/src/main/java/ml/docilealligator/infinityforreddit
parent62dc889867678be046a4d298782cd14305fe5c39 (diff)
downloadinfinity-for-reddit-478b85e67b1798ab6b0bdc4392785c40fe1c1307.tar
infinity-for-reddit-478b85e67b1798ab6b0bdc4392785c40fe1c1307.tar.gz
infinity-for-reddit-478b85e67b1798ab6b0bdc4392785c40fe1c1307.tar.bz2
infinity-for-reddit-478b85e67b1798ab6b0bdc4392785c40fe1c1307.tar.lz
infinity-for-reddit-478b85e67b1798ab6b0bdc4392785c40fe1c1307.tar.xz
infinity-for-reddit-478b85e67b1798ab6b0bdc4392785c40fe1c1307.tar.zst
infinity-for-reddit-478b85e67b1798ab6b0bdc4392785c40fe1c1307.zip
Display single comment thread when clicking a comment from ViewUserDetailActivity instead of showing all the comments.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java102
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java123
5 files changed, 186 insertions, 73 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
index b5ca248b..5ecc81df 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
@@ -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_IS_LOADING_MORE_COMMENTS = 6;
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 Retrofit mRetrofit;
@@ -68,6 +69,8 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
private ArrayList<CommentData> mVisibleComments;
private String mSubredditNamePrefixed;
private Locale mLocale;
+ private String mSingleCommentId;
+ private boolean mIsSingleCommentThreadMode;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
private boolean isInitiallyLoading;
@@ -82,8 +85,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
CommentAndPostRecyclerViewAdapter(Activity activity, Retrofit retrofit, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
- String accessToken, String accountName, Post post, String subredditNamePrefixed,
- Locale locale, LoadSubredditIconAsyncTask loadSubredditIconAsyncTask,
+ String accessToken, String accountName, Post post, Locale locale,
+ String singleCommentId, boolean isSingleCommentThreadMode,
+ LoadSubredditIconAsyncTask loadSubredditIconAsyncTask,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity;
mRetrofit = retrofit;
@@ -94,8 +98,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
mAccountName = accountName;
mPost = post;
mVisibleComments = new ArrayList<>();
- mSubredditNamePrefixed = subredditNamePrefixed;
+ mSubredditNamePrefixed = post.getSubredditNamePrefixed();
mLocale = locale;
+ mSingleCommentId = singleCommentId;
+ mIsSingleCommentThreadMode = isSingleCommentThreadMode;
mLoadSubredditIconAsyncTask = loadSubredditIconAsyncTask;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true;
@@ -122,19 +128,40 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
}
}
- if(position == mVisibleComments.size() + 1) {
- if(mHasMoreComments) {
- return VIEW_TYPE_IS_LOADING_MORE_COMMENTS;
- } else {
- return VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED;
+ if(mIsSingleCommentThreadMode) {
+ if(position == 1) {
+ return VIEW_TYPE_VIEW_ALL_COMMENTS;
+ }
+
+ if(position == mVisibleComments.size() + 2) {
+ 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;
+ CommentData comment = mVisibleComments.get(position - 2);
+ if(!comment.isPlaceHolder()) {
+ return VIEW_TYPE_COMMENT;
+ } else {
+ return VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS;
+ }
} 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));
case VIEW_TYPE_IS_LOADING_MORE_COMMENTS:
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));
+ 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;
}
} 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();
((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() {
if(mLoadSubredditIconAsyncTask != null) {
mLoadSubredditIconAsyncTask.cancel(true);
@@ -627,7 +666,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
if(mVisibleComments.size() != 0) {
int previousSize = mVisibleComments.size();
mVisibleComments.clear();
- notifyItemRangeRemoved(1, previousSize);
+ if(mIsSingleCommentThreadMode) {
+ notifyItemRangeRemoved(1, previousSize + 1);
+ } else {
+ notifyItemRangeRemoved(1, previousSize);
+ }
}
if(isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) {
@@ -689,10 +732,18 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
}
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 {
@@ -1050,7 +1101,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
mVisibleComments.get(getAdapterPosition() - 1).setLoadMoreChildrenFailed(false);
placeholderTextView.setText(R.string.loading);
- FetchComment.fetchMoreComment(mRetrofit, mSubredditNamePrefixed, parentComment.getMoreChildrenFullnames(),
+ FetchComment.fetchMoreComment(mRetrofit, parentComment.getMoreChildrenFullnames(),
parentComment.getMoreChildrenStartingIndex(), parentComment.getDepth() + 1, mLocale,
new FetchComment.FetchMoreCommentListener() {
@Override
@@ -1238,4 +1289,17 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
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();
+ }
+ });
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
index ffcf707b..c20920a9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
@@ -196,6 +196,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
linearLayout.setOnClickListener(view -> {
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, getItem(getAdapterPosition()).getLinkId());
+ intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, getItem(getAdapterPosition()).getId());
mContext.startActivity(intent);
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
index cec412fc..5558a104 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
@@ -23,10 +23,15 @@ class FetchComment {
void onFetchMoreCommentFailed();
}
- static void fetchComments(Retrofit retrofit, String subredditNamePrefixed, String article,
+ static void fetchComments(Retrofit retrofit, String article, String commentId,
Locale locale, FetchCommentListener fetchCommentListener) {
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>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
@@ -60,9 +65,8 @@ class FetchComment {
});
}
- static void fetchMoreComment(Retrofit retrofit, String subredditNamePrefixed,
- ArrayList<String> allChildren, int startingIndex, int depth,
- Locale locale, FetchMoreCommentListener fetchMoreCommentListener) {
+ static void fetchMoreComment(Retrofit retrofit, ArrayList<String> allChildren, int startingIndex,
+ int depth, Locale locale, FetchMoreCommentListener fetchMoreCommentListener) {
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < 100; i++) {
if(allChildren.size() <= startingIndex + i) {
@@ -79,10 +83,10 @@ class FetchComment {
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>() {
@Override
- public void onResponse(Call<String> call, Response<String> response) {
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
ParseComment.parseMoreComment(response.body(), new ArrayList<>(), locale,
depth, new ParseComment.ParseCommentListener() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
index ce351359..a9caccd6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
@@ -21,10 +21,6 @@ public interface RedditAPI {
@POST("api/v1/access_token")
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")
Call<String> getSubredditData(@Path("subredditName") String subredditName);
@@ -74,8 +70,8 @@ public interface RedditAPI {
@POST("api/subscribe")
Call<String> subredditSubscription(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
- @GET("{subredditNamePrefixed}/api/info.json?raw_json=1")
- Call<String> getInfo(@Path("subredditNamePrefixed") String subredditNamePrefixed, @Query("id") String id);
+ @GET("/api/info.json?raw_json=1")
+ Call<String> getInfo(@Query("id") String id);
@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);
@@ -120,9 +116,16 @@ public interface RedditAPI {
@GET("/r/{subredditName}/about/rules.json?raw_json=1")
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")
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")
Call<String> getPostAndCommentsById(@Path("id") String id);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 0ec34c57..1039fc96 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -59,6 +59,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
static final String EXTRA_POST_DATA = "EPD";
static final String EXTRA_POST_LIST_POSITION = "EPLI";
static final String EXTRA_POST_ID = "EPI";
+ static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
private static final int EDIT_POST_REQUEST_CODE = 2;
static final int EDIT_COMMENT_REQUEST_CODE = 3;
@@ -69,6 +70,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
private int orientation;
private int postListPosition = -1;
+ private String mSingleCommentId;
@State
boolean mNullAccessToken = false;
@@ -83,6 +85,8 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@State
boolean isRefreshing = false;
@State
+ boolean isSingleCommentThreadMode = false;
+ @State
ArrayList<CommentData> comments;
@State
ArrayList<String> children;
@@ -186,6 +190,11 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mLinearLayoutManager = new LinearLayoutManager(this);
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;
if(!mNullAccessToken && mAccessToken == null) {
@@ -246,7 +255,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
- mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
+ mLocale, mSingleCommentId, isSingleCommentThreadMode, mLoadSubredditIconAsyncTask,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
public void updatePost(Post post) {
@@ -264,11 +273,11 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mRecyclerView.setAdapter(mAdapter);
if(comments == null) {
- fetchComments();
+ fetchComments(false);
} else {
if(isRefreshing) {
isRefreshing = false;
- refresh(false);
+ refresh(true, true);
} else {
mAdapter.addComments(comments, hasMoreChildren);
if(isLoadingMoreChildren) {
@@ -288,9 +297,19 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
Call<String> postAndComments;
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 {
- 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>() {
@Override
@@ -312,7 +331,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
- mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
+ mLocale, mSingleCommentId, isSingleCommentThreadMode, mLoadSubredditIconAsyncTask,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
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();
+ String commentId = null;
+ if(isSingleCommentThreadMode) {
+ commentId = mSingleCommentId;
+ }
- FetchComment.fetchComments(mRetrofit, mPost.getSubredditNamePrefixed(), mPost.getId(),
- mLocale, new FetchComment.FetchCommentListener() {
+ FetchComment.fetchComments(mRetrofit, mPost.getId(), commentId, mLocale, new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<CommentData> expandedComments,
String parentId, ArrayList<String> children) {
@@ -414,11 +437,17 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
});
}
+ if(changeRefreshState) {
+ isRefreshing = false;
+ }
}
@Override
public void onFetchCommentFailed() {
mAdapter.initiallyLoadCommentsFailed();
+ if(changeRefreshState) {
+ isRefreshing = false;
+ }
}
});
}
@@ -429,7 +458,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
isLoadingMoreChildren = true;
- FetchComment.fetchMoreComment(mRetrofit, mPost.getSubredditNamePrefixed(), children, mChildrenStartingIndex,
+ FetchComment.fetchMoreComment(mRetrofit, children, mChildrenStartingIndex,
0, mLocale, new FetchComment.FetchMoreCommentListener() {
@Override
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) {
isRefreshing = true;
mChildrenStartingIndex = 0;
@@ -457,32 +486,38 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
mGlide.clear(mFetchPostInfoImageView);
- if(!onlyRefreshPost) {
- fetchComments();
+ if(fetchComments) {
+ if(!fetchPost) {
+ fetchComments(true);
+ } else {
+ fetchComments(false);
+ }
}
- Retrofit retrofit;
- if(mAccessToken == null) {
- retrofit = mRetrofit;
- } else {
- retrofit = mOauthRetrofit;
- }
- FetchPost.fetchPost(retrofit, mPost.getId(), mAccessToken, mLocale,
- new FetchPost.FetchPostListener() {
- @Override
- public void fetchPostSuccess(Post post) {
- mPost = post;
- mAdapter.updatePost(mPost);
- EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
- isRefreshing = false;
- }
+ if(fetchPost) {
+ Retrofit retrofit;
+ if(mAccessToken == null) {
+ retrofit = mRetrofit;
+ } else {
+ retrofit = mOauthRetrofit;
+ }
+ FetchPost.fetchPost(retrofit, mPost.getId(), mAccessToken, mLocale,
+ new FetchPost.FetchPostListener() {
+ @Override
+ public void fetchPostSuccess(Post post) {
+ mPost = post;
+ mAdapter.updatePost(mPost);
+ EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
+ isRefreshing = false;
+ }
- @Override
- public void fetchPostFailed() {
- showMessage(R.string.refresh_post_failed);
- isRefreshing = false;
- }
- });
+ @Override
+ public void fetchPostFailed() {
+ showMessage(R.string.refresh_post_failed);
+ isRefreshing = false;
+ }
+ });
+ }
}
}
@@ -510,7 +545,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
- refresh(true);
+ refresh(true, false);
showMessage(R.string.mark_nsfw_success);
} else {
showMessage(R.string.mark_nsfw_failed);
@@ -532,7 +567,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
- refresh(true);
+ refresh(true, false);
showMessage(R.string.unmark_nsfw_success);
} else {
showMessage(R.string.unmark_nsfw_failed);
@@ -554,7 +589,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
- refresh(true);
+ refresh(true, false);
showMessage(R.string.mark_spoiler_success);
} else {
showMessage(R.string.mark_spoiler_failed);
@@ -576,7 +611,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
- refresh(true);
+ refresh(true, false);
showMessage(R.string.unmark_spoiler_success);
} else {
showMessage(R.string.unmark_spoiler_failed);
@@ -611,6 +646,12 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
.show();
}
+ void changeToSingleThreadMode() {
+ isSingleCommentThreadMode = false;
+ mSingleCommentId = null;
+ refresh(false, true);
+ }
+
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) {
if(mPost.getId().equals(event.postId)) {
@@ -654,7 +695,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh_view_post_detail_activity:
- refresh(false);
+ refresh(true, true);
return true;
case R.id.action_comment_view_post_detail_activity:
if(mAccessToken == null) {
@@ -746,7 +787,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
} else if(requestCode == EDIT_POST_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
- refresh(true);
+ refresh(true, false);
}
} else if(requestCode == EDIT_COMMENT_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
@@ -794,7 +835,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if(response.isSuccessful()) {
- refresh(true);
+ refresh(true, false);
showMessage(R.string.update_flair_success);
} else {
showMessage(R.string.update_flair_failed);