aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-09-08 16:14:52 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-09-08 16:14:52 +0000
commit313eb77ddc97bdd2f96a2a221d397819308f1851 (patch)
tree9cba282a102e954a2c8d686a06ff665062b04b0b
parent38ed89fc304731eaac2a2130995988f379d5eeba (diff)
downloadinfinity-for-reddit-313eb77ddc97bdd2f96a2a221d397819308f1851.tar
infinity-for-reddit-313eb77ddc97bdd2f96a2a221d397819308f1851.tar.gz
infinity-for-reddit-313eb77ddc97bdd2f96a2a221d397819308f1851.tar.bz2
infinity-for-reddit-313eb77ddc97bdd2f96a2a221d397819308f1851.tar.lz
infinity-for-reddit-313eb77ddc97bdd2f96a2a221d397819308f1851.tar.xz
infinity-for-reddit-313eb77ddc97bdd2f96a2a221d397819308f1851.tar.zst
infinity-for-reddit-313eb77ddc97bdd2f96a2a221d397819308f1851.zip
Vote status is now correctly shown when viewing post details. Fixed following user failed.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java28
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/UserFollowing.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java7
7 files changed, 47 insertions, 20 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
index 6ad3638f..273b52ce 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
@@ -1296,7 +1296,8 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
mVisibleComments.get(commentPosition).setLoadMoreChildrenFailed(false);
placeholderTextView.setText(R.string.loading);
- FetchComment.fetchMoreComment(mRetrofit, parentComment.getMoreChildrenFullnames(),
+ Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
+ FetchComment.fetchMoreComment(retrofit, mAccessToken, parentComment.getMoreChildrenFullnames(),
parentComment.getMoreChildrenStartingIndex(), parentComment.getDepth() + 1, mLocale,
new FetchComment.FetchMoreCommentListener() {
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
index d24f297b..bce51afa 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
@@ -37,7 +37,7 @@ class CommentData implements Parcelable {
private boolean loadMoreChildrenFailed;
CommentData(String id, String fullName, String author, String linkAuthor, String commentTime, String commentContent,
- String linkId, String subredditName, String parentId, int score, boolean isSubmitter, String permalink,
+ String linkId, String subredditName, String parentId, int score, int voteType, boolean isSubmitter, String permalink,
int depth, boolean collapsed, boolean hasReply, boolean scoreHidden) {
this.id = id;
this.fullName = fullName;
@@ -49,6 +49,7 @@ class CommentData implements Parcelable {
this.subredditName = subredditName;
this.parentId = parentId;
this.score = score;
+ this.voteType = voteType;
this.isSubmitter = isSubmitter;
this.permalink = RedditUtils.API_BASE_URI + permalink;
this.depth = depth;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
index fd53414b..f3ac4944 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchComment.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Locale;
@@ -21,15 +22,24 @@ class FetchComment {
void onFetchMoreCommentFailed();
}
- static void fetchComments(Retrofit retrofit, String article, String commentId,
+ static void fetchComments(Retrofit retrofit, @Nullable String accessToken, String article, String commentId,
Locale locale, FetchCommentListener fetchCommentListener) {
RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> comments;
- if(commentId == null) {
- comments = api.getPostAndCommentsById(article);
+ if(accessToken == null) {
+ if(commentId == null) {
+ comments = api.getPostAndCommentsById(article);
+ } else {
+ comments = api.getPostAndCommentsSingleThreadById(article, commentId);
+ }
} else {
- comments = api.getPostAndCommentsSingleThreadById(article, commentId);
+ if(commentId == null) {
+ comments = api.getPostAndCommentsByIdOauth(article, RedditUtils.getOAuthHeader(accessToken));
+ } else {
+ comments = api.getPostAndCommentsSingleThreadByIdOauth(article, commentId, RedditUtils.getOAuthHeader(accessToken));
+ }
}
+
comments.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
@@ -60,7 +70,8 @@ class FetchComment {
});
}
- static void fetchMoreComment(Retrofit retrofit, ArrayList<String> allChildren, int startingIndex,
+ static void fetchMoreComment(Retrofit retrofit, @Nullable String accessToken,
+ ArrayList<String> allChildren, int startingIndex,
int depth, Locale locale, FetchMoreCommentListener fetchMoreCommentListener) {
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < 100; i++) {
@@ -77,8 +88,13 @@ class FetchComment {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
RedditAPI api = retrofit.create(RedditAPI.class);
+ Call<String> moreComments;
+ if(accessToken == null) {
+ moreComments = api.getInfo(stringBuilder.toString());
+ } else {
+ moreComments = api.getInfoOauth(stringBuilder.toString(), RedditUtils.getOAuthHeader(accessToken));
+ }
- Call<String> moreComments = api.getInfo(stringBuilder.toString());
moreComments.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
index f9770867..4bcaa29a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
@@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
import android.text.Html;
-import android.util.Log;
import androidx.annotation.Nullable;
@@ -15,6 +14,10 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
+import static ml.docilealligator.infinityforreddit.CommentData.VOTE_TYPE_DOWNVOTE;
+import static ml.docilealligator.infinityforreddit.CommentData.VOTE_TYPE_NO_VOTE;
+import static ml.docilealligator.infinityforreddit.CommentData.VOTE_TYPE_UPVOTE;
+
class ParseComment {
interface ParseCommentListener {
void onParseCommentSuccess(ArrayList<CommentData> expandedComments, String parentId,
@@ -49,9 +52,6 @@ class ParseComment {
new ParseCommentAsyncTask(childrenArray, commentData, locale, null, depth, parseCommentListener).execute();
} catch (JSONException e) {
e.printStackTrace();
- if(e.getMessage() != null) {
- Log.i("comment json error", e.getMessage());
- }
parseCommentListener.onParseCommentFailed();
}
}
@@ -94,9 +94,6 @@ class ParseComment {
expandChildren(newComments, expandedNewComments);
} catch (JSONException e) {
parseFailed = true;
- if(e.getMessage() != null) {
- Log.i("parse comment error", e.getMessage());
- }
}
return null;
}
@@ -226,6 +223,13 @@ class ParseComment {
}
String permalink = Html.fromHtml(singleCommentData.getString(JSONUtils.PERMALINK_KEY)).toString();
int score = singleCommentData.getInt(JSONUtils.SCORE_KEY);
+ int voteType;
+ if(singleCommentData.isNull(JSONUtils.LIKES_KEY)) {
+ voteType = VOTE_TYPE_NO_VOTE;
+ } else {
+ voteType = singleCommentData.getBoolean(JSONUtils.LIKES_KEY) ? VOTE_TYPE_UPVOTE : VOTE_TYPE_DOWNVOTE;
+ score -= voteType;
+ }
long submitTime = singleCommentData.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
boolean scoreHidden = singleCommentData.getBoolean(JSONUtils.SCORE_HIDDEN_KEY);
@@ -242,7 +246,7 @@ class ParseComment {
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
return new CommentData(id, fullName, author, linkAuthor, formattedSubmitTime, commentContent,
- linkId, subredditName, parentId, score, isSubmitter, permalink, depth, collapsed,
+ linkId, subredditName, parentId, score, voteType, isSubmitter, permalink, depth, collapsed,
hasReply, scoreHidden);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
index 55904d2b..8a9b8a9e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
@@ -73,6 +73,9 @@ public interface RedditAPI {
@GET("/api/info.json?raw_json=1")
Call<String> getInfo(@Query("id") String id);
+ @GET("/api/info.json?raw_json=1")
+ Call<String> getInfoOauth(@Query("id") String id, @HeaderMap Map<String, String> headers);
+
@GET("subreddits/search.json?raw_json=1")
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after,
@Query("sort") String sort);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserFollowing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserFollowing.java
index 99337362..1b25c415 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserFollowing.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserFollowing.java
@@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit;
import android.os.AsyncTask;
-import android.util.Log;
import androidx.annotation.NonNull;
@@ -99,7 +98,7 @@ class UserFollowing {
String accountName, boolean isSubscribing) {
this.subscribedUserDao = subscribedUserDao;
this.subscribedUserData = new SubscribedUserData(userData.getName(), userData.getIconUrl(),
- userData.getName());
+ accountName);
this.accountName = accountName;
this.isSubscribing = isSubscribing;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 42a63247..27b31083 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -548,7 +548,8 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
commentId = mSingleCommentId;
}
- FetchComment.fetchComments(mRetrofit, mPost.getId(), commentId, mLocale, new FetchComment.FetchCommentListener() {
+ Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
+ FetchComment.fetchComments(retrofit, mAccessToken, mPost.getId(), commentId, mLocale, new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<CommentData> expandedComments,
String parentId, ArrayList<String> children) {
@@ -597,7 +598,9 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
isLoadingMoreChildren = true;
- FetchComment.fetchMoreComment(mRetrofit, children, mChildrenStartingIndex,
+
+ Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
+ FetchComment.fetchMoreComment(retrofit, mAccessToken, children, mChildrenStartingIndex,
0, mLocale, new FetchComment.FetchMoreCommentListener() {
@Override
public void onFetchMoreCommentSuccess(ArrayList<CommentData> expandedComments, int childrenStartingIndex) {