aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/BestPostRecyclerViewAdapter.java52
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java109
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java150
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java5
7 files changed, 229 insertions, 102 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BestPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BestPostRecyclerViewAdapter.java
index 38838a00..5978b407 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/BestPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BestPostRecyclerViewAdapter.java
@@ -132,11 +132,11 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
switch (voteType) {
case 1:
//Upvote
- ((DataViewHolder) holder).plusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
break;
case -1:
//Downvote
- ((DataViewHolder) holder).minusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
break;
}
@@ -295,14 +295,14 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
((DataViewHolder) holder).typeTextView.setText("TEXT");
}
- ((DataViewHolder) holder).plusButton.setOnClickListener(new View.OnClickListener() {
+ ((DataViewHolder) holder).upvoteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- final boolean isDownvotedBefore = ((DataViewHolder) holder).minusButton.getColorFilter() != null;
- ((DataViewHolder) holder).minusButton.clearColorFilter();
+ final boolean isDownvotedBefore = ((DataViewHolder) holder).downvoteButton.getColorFilter() != null;
+ ((DataViewHolder) holder).downvoteButton.clearColorFilter();
- if (((DataViewHolder) holder).plusButton.getColorFilter() == null) {
- ((DataViewHolder) holder).plusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ if (((DataViewHolder) holder).upvoteButton.getColorFilter() == null) {
+ ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
if(isDownvotedBefore) {
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() + 2));
} else {
@@ -323,14 +323,14 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
@Override
public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot upvote this post", Toast.LENGTH_SHORT).show();
- ((DataViewHolder) holder).plusButton.clearColorFilter();
+ ((DataViewHolder) holder).upvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore()));
- ((DataViewHolder) holder).minusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
}
}, id, RedditUtils.DIR_UPVOTE, ((DataViewHolder) holder).getAdapterPosition(), 1);
} else {
//Upvoted before
- ((DataViewHolder) holder).plusButton.clearColorFilter();
+ ((DataViewHolder) holder).upvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() - 1));
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@@ -344,7 +344,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() + 1));
- ((DataViewHolder) holder).plusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore() + 1);
}
}, id, RedditUtils.DIR_UNVOTE, ((DataViewHolder) holder).getAdapterPosition(), 1);
@@ -352,14 +352,14 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
}
});
- ((DataViewHolder) holder).minusButton.setOnClickListener(new View.OnClickListener() {
+ ((DataViewHolder) holder).downvoteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- final boolean isUpvotedBefore = ((DataViewHolder) holder).plusButton.getColorFilter() != null;
+ final boolean isUpvotedBefore = ((DataViewHolder) holder).upvoteButton.getColorFilter() != null;
- ((DataViewHolder) holder).plusButton.clearColorFilter();
- if (((DataViewHolder) holder).minusButton.getColorFilter() == null) {
- ((DataViewHolder) holder).minusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((DataViewHolder) holder).upvoteButton.clearColorFilter();
+ if (((DataViewHolder) holder).downvoteButton.getColorFilter() == null) {
+ ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
if (isUpvotedBefore) {
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() - 2));
} else {
@@ -380,14 +380,14 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
@Override
public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot downvote this post", Toast.LENGTH_SHORT).show();
- ((DataViewHolder) holder).minusButton.clearColorFilter();
+ ((DataViewHolder) holder).downvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore()));
- ((DataViewHolder) holder).plusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
}
}, id, RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition(), 1);
} else {
//Down voted before
- ((DataViewHolder) holder).minusButton.clearColorFilter();
+ ((DataViewHolder) holder).downvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore() + 1));
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@@ -400,7 +400,7 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
@Override
public void onVoteThingFail(int position) {
Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show();
- ((DataViewHolder) holder).minusButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mBestPostData.get(position).getScore()));
mBestPostData.get(position).setScore(mBestPostData.get(position).getScore());
}
@@ -475,9 +475,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
private ProgressBar progressBar;
private ImageView imageView;
private ImageView noPreviewLinkImageView;
- private ImageView plusButton;
+ private ImageView upvoteButton;
private TextView scoreTextView;
- private ImageView minusButton;
+ private ImageView downvoteButton;
private ImageView shareButton;
DataViewHolder(CardView itemView) {
@@ -494,9 +494,9 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
imageView = itemView.findViewById(R.id.image_view_best_post_item);
noPreviewLinkImageView = itemView.findViewById(R.id.image_view_no_preview_link_best_post_item);
- plusButton = itemView.findViewById(R.id.plus_button_item_best_post);
+ upvoteButton = itemView.findViewById(R.id.plus_button_item_best_post);
scoreTextView = itemView.findViewById(R.id.score_text_view_item_best_post);
- minusButton = itemView.findViewById(R.id.minus_button_item_best_post);
+ downvoteButton = itemView.findViewById(R.id.minus_button_item_best_post);
shareButton = itemView.findViewById(R.id.share_button_item_best_post);
}
}
@@ -523,8 +523,8 @@ class BestPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.View
((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
((DataViewHolder) holder).imageView.setVisibility(View.GONE);
((DataViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE);
- ((DataViewHolder) holder).plusButton.clearColorFilter();
- ((DataViewHolder) holder).minusButton.clearColorFilter();
+ ((DataViewHolder) holder).upvoteButton.clearColorFilter();
+ ((DataViewHolder) holder).downvoteButton.clearColorFilter();
} else if(holder instanceof LoadingViewHolder) {
if(isLoadingMorePostSuccess) {
((LoadingViewHolder) holder).relativeLayout.setVisibility(View.GONE);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
index fbc0c830..5da40e9a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
@@ -1,7 +1,7 @@
package ml.docilealligator.infinityforreddit;
class CommentData {
- private String id;
+ private String fullName;
private String author;
private String commentTime;
private String commentContent;
@@ -13,10 +13,10 @@ class CommentData {
private boolean hasReply;
private boolean scoreHidden;
- CommentData(String id, String author, String commentTime, String commentContent, int score,
+ CommentData(String fullName, String author, String commentTime, String commentContent, int score,
boolean isSubmitter, String permalink, int depth, boolean collapsed, boolean hasReply,
boolean scoreHidden) {
- this.id = id;
+ this.fullName = fullName;
this.author = author;
this.commentTime = commentTime;
this.commentContent = commentContent;
@@ -30,8 +30,8 @@ class CommentData {
}
- public String getId() {
- return id;
+ public String getFullName() {
+ return fullName;
}
public String getAuthor() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
index e8bdd764..7de223bb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
@@ -1,13 +1,16 @@
package ml.docilealligator.infinityforreddit;
import android.content.Context;
+import android.graphics.ColorFilter;
import android.support.annotation.NonNull;
+import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
+import android.widget.Toast;
import com.android.volley.RequestQueue;
@@ -17,12 +20,14 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
private Context mContext;
private ArrayList<CommentData> mCommentData;
private RequestQueue mVoteThingRequestQueue;
+ private RequestQueue mAcquireAccessTokenRequestQueue;
CommentRecyclerViewAdapter(Context context, ArrayList<CommentData> commentData,
- RequestQueue voteThingRequestQueue) {
+ RequestQueue voteThingRequestQueue, RequestQueue acquireAccessTokenRequestQueue) {
mContext = context;
mCommentData = commentData;
mVoteThingRequestQueue = voteThingRequestQueue;
+ mAcquireAccessTokenRequestQueue = acquireAccessTokenRequestQueue;
}
@NonNull
@@ -32,7 +37,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
@Override
- public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
((CommentViewHolder) holder).authorTextView.setText(mCommentData.get(position).getAuthor());
((CommentViewHolder) holder).commentTimeTextView.setText(mCommentData.get(position).getCommentTime());
((CommentViewHolder) holder).commentTextView.setText(mCommentData.get(position).getCommentContent());
@@ -40,13 +45,113 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
((CommentViewHolder) holder).upvoteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
+ final boolean isDownvotedBefore = ((CommentViewHolder) holder).downvoteButton.getColorFilter() != null;
+ final ColorFilter minusButtonColorFilter = ((CommentViewHolder) holder).downvoteButton.getColorFilter();
+ ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
+ if (((CommentViewHolder) holder).upvoteButton.getColorFilter() == null) {
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ if(isDownvotedBefore) {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 2));
+ } else {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 1));
+ }
+
+ new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position) {
+ if(isDownvotedBefore) {
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 2);
+ } else {
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 1);
+ }
+ }
+
+ @Override
+ public void onVoteThingFail(int position) {
+ Toast.makeText(mContext, "Cannot upvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(minusButtonColorFilter);
+ }
+ }, mCommentData.get(position).getFullName(), RedditUtils.DIR_UPVOTE, ((CommentViewHolder) holder).getAdapterPosition(), 1);
+ } else {
+ //Upvoted before
+ ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() - 1));
+
+ new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position) {
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 1);
+ }
+
+ @Override
+ public void onVoteThingFail(int position) {
+ Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 1));
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 1);
+ }
+ }, mCommentData.get(position).getFullName(), RedditUtils.DIR_UNVOTE, ((CommentViewHolder) holder).getAdapterPosition(), 1);
+ }
}
});
+
((CommentViewHolder) holder).downvoteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
+ final boolean isUpvotedBefore = ((CommentViewHolder) holder).upvoteButton.getColorFilter() != null;
+
+ final ColorFilter upvoteButtonColorFilter = ((CommentViewHolder) holder).upvoteButton.getColorFilter();
+ ((CommentViewHolder) holder).upvoteButton.clearColorFilter();
+
+ if (((CommentViewHolder) holder).downvoteButton.getColorFilter() == null) {
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ if (isUpvotedBefore) {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() - 2));
+ } else {
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() - 1));
+ }
+
+ new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position) {
+ if(isUpvotedBefore) {
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 2);
+ } else {
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 1);
+ }
+ }
+
+ @Override
+ public void onVoteThingFail(int position) {
+ Toast.makeText(mContext, "Cannot downvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
+ }
+ }, mCommentData.get(position).getFullName(), RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition(), 1);
+ } else {
+ //Down voted before
+ ((CommentViewHolder) holder).downvoteButton.clearColorFilter();
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore() + 1));
+
+ new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position) {
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore());
+ }
+ @Override
+ public void onVoteThingFail(int position) {
+ Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
+ mCommentData.get(position).setScore(mCommentData.get(position).getScore());
+ }
+ }, mCommentData.get(position).getFullName(), RedditUtils.DIR_UNVOTE, holder.getAdapterPosition(), 1);
+ }
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
index 90518d74..60ea1c98 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
@@ -63,4 +63,5 @@ class JSONUtils {
static final String PUBLIC_DESCRIPTION = "public_description";
static final String ACTIVE_USER_COUNT = "active_user_count";
static final String DISPLAY_NAME_PREFIXED = "display_name_prefixed";
+ static final String LINK_ID = "link_id";
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index 87de57a7..8ca3fbc8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -1,7 +1,5 @@
package ml.docilealligator.infinityforreddit;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
@@ -10,6 +8,8 @@ import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
@@ -37,6 +37,8 @@ public class MainActivity extends AppCompatActivity {
private String profileImageUrlState = "PIUS";
private String bannerImageUrlState = "BIUS";
private String karmaState = "KS";
+ private String fetchUserInfoState = "FUIS";
+ private String insertSubscribedSubredditState = "ISSS";
private TextView mNameTextView;
private TextView mKarmaTextView;
@@ -52,12 +54,13 @@ public class MainActivity extends AppCompatActivity {
private String mKarma;
private boolean mFetchUserInfoSuccess;
private boolean mIsInserting;
+ private boolean mInsertSuccess;
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
private SubscribedUserViewModel mSubscribedUserViewModel;
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
@@ -95,11 +98,15 @@ public class MainActivity extends AppCompatActivity {
new AcquireAccessToken(this).refreshAccessToken(Volley.newRequestQueue(this),
new AcquireAccessToken.AcquireAccessTokenListener() {
@Override
- public void onAcquireAccessTokenSuccess() {}
+ public void onAcquireAccessTokenSuccess() {
+ loadUserData(savedInstanceState);
+ }
@Override
public void onAcquireAccessTokenFail() {}
});
+ } else {
+ loadUserData(savedInstanceState);
}
View header = findViewById(R.id.nav_header_main_activity);
@@ -133,7 +140,46 @@ public class MainActivity extends AppCompatActivity {
glide.load(mBannerImageUrl).into(mBannerImageView);
}
- if(savedInstanceState == null && !mFetchUserInfoSuccess) {
+ final SubscribedSubredditRecyclerViewAdapter subredditadapter = new SubscribedSubredditRecyclerViewAdapter(this);
+ subscribedSubredditRecyclerView.setAdapter(subredditadapter);
+ mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
+ mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, new Observer<List<SubscribedSubredditData>>() {
+ @Override
+ public void onChanged(@Nullable final List<SubscribedSubredditData> subscribedSubredditData) {
+ if(!mIsInserting) {
+ if(subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
+ subscriptionsLabelTextView.setVisibility(View.GONE);
+ } else {
+ subscriptionsLabelTextView.setVisibility(View.VISIBLE);
+ }
+
+ subredditadapter.setSubscribedSubreddits(subscribedSubredditData);
+ }
+ }
+ });
+
+ final SubscribedUserRecyclerViewAdapter userAdapter = new SubscribedUserRecyclerViewAdapter(this);
+ subscribedUserRecyclerView.setAdapter(userAdapter);
+ mSubscribedUserViewModel = ViewModelProviders.of(this).get(SubscribedUserViewModel.class);
+ mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, new Observer<List<SubscribedUserData>>() {
+ @Override
+ public void onChanged(@Nullable final List<SubscribedUserData> subscribedUserData) {
+ if(!mIsInserting) {
+ if(subscribedUserData == null || subscribedUserData.size() == 0) {
+ followingLabelTextView.setVisibility(View.GONE);
+ } else {
+ followingLabelTextView.setVisibility(View.VISIBLE);
+ }
+ userAdapter.setSubscribedUsers(subscribedUserData);
+ }
+ }
+ });
+ }
+ }
+
+ private void loadUserData(Bundle savedInstanceState) {
+ if(savedInstanceState == null) {
+ if(!mFetchUserInfoSuccess) {
new FetchUserInfo(this, Volley.newRequestQueue(this)).queryUserInfo(new FetchUserInfo.FetchUserInfoListener() {
@Override
public void onFetchUserInfoSuccess(String response) {
@@ -178,69 +224,37 @@ public class MainActivity extends AppCompatActivity {
}, 1);
}
- final SubscribedSubredditRecyclerViewAdapter subredditadapter = new SubscribedSubredditRecyclerViewAdapter(this);
- subscribedSubredditRecyclerView.setAdapter(subredditadapter);
- mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
- mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, new Observer<List<SubscribedSubredditData>>() {
- @Override
- public void onChanged(@Nullable final List<SubscribedSubredditData> subscribedSubredditData) {
- if(!mIsInserting) {
- if(subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
- subscriptionsLabelTextView.setVisibility(View.GONE);
- } else {
- subscriptionsLabelTextView.setVisibility(View.VISIBLE);
- }
-
- subredditadapter.setSubscribedSubreddits(subscribedSubredditData);
- }
- }
- });
-
- final SubscribedUserRecyclerViewAdapter userAdapter = new SubscribedUserRecyclerViewAdapter(this);
- subscribedUserRecyclerView.setAdapter(userAdapter);
- mSubscribedUserViewModel = ViewModelProviders.of(this).get(SubscribedUserViewModel.class);
- mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, new Observer<List<SubscribedUserData>>() {
- @Override
- public void onChanged(@Nullable final List<SubscribedUserData> subscribedUserData) {
- if(!mIsInserting) {
- if(subscribedUserData == null || subscribedUserData.size() == 0) {
- followingLabelTextView.setVisibility(View.GONE);
- } else {
- followingLabelTextView.setVisibility(View.VISIBLE);
- }
- userAdapter.setSubscribedUsers(subscribedUserData);
- }
- }
- });
-
- new FetchSubscribedThing(this, Volley.newRequestQueue(this), new ArrayList<SubscribedSubredditData>(),
- new ArrayList<SubscribedUserData>(), new ArrayList<SubredditData>())
- .fetchSubscribedSubreddits(new FetchSubscribedThing.FetchSubscribedSubredditsListener() {
- @Override
- public void onFetchSubscribedSubredditsSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
- ArrayList<SubscribedUserData> subscribedUserData,
- ArrayList<SubredditData> subredditData) {
- mIsInserting = true;
- new InsertSubscribedThingsAsyncTask(
- SubscribedSubredditRoomDatabase.getDatabase(MainActivity.this),
- SubscribedUserRoomDatabase.getDatabase(MainActivity.this),
- SubredditRoomDatabase.getDatabase(MainActivity.this),
- subscribedSubredditData,
- subscribedUserData,
- subredditData,
- new InsertSubscribedThingsAsyncTask.InsertSubscribedThingListener() {
- @Override
- public void insertSuccess() {
- mIsInserting = false;
- }
- }).execute();
- }
+ if(mInsertSuccess) {
+ new FetchSubscribedThing(this, Volley.newRequestQueue(this), new ArrayList<SubscribedSubredditData>(),
+ new ArrayList<SubscribedUserData>(), new ArrayList<SubredditData>())
+ .fetchSubscribedSubreddits(new FetchSubscribedThing.FetchSubscribedSubredditsListener() {
+ @Override
+ public void onFetchSubscribedSubredditsSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
+ ArrayList<SubscribedUserData> subscribedUserData,
+ ArrayList<SubredditData> subredditData) {
+ mIsInserting = true;
+ new InsertSubscribedThingsAsyncTask(
+ SubscribedSubredditRoomDatabase.getDatabase(MainActivity.this),
+ SubscribedUserRoomDatabase.getDatabase(MainActivity.this),
+ SubredditRoomDatabase.getDatabase(MainActivity.this),
+ subscribedSubredditData,
+ subscribedUserData,
+ subredditData,
+ new InsertSubscribedThingsAsyncTask.InsertSubscribedThingListener() {
+ @Override
+ public void insertSuccess() {
+ mIsInserting = false;
+ mInsertSuccess = true;
+ }
+ }).execute();
+ }
- @Override
- public void onFetchSubscribedSubredditsFail() {
+ @Override
+ public void onFetchSubscribedSubredditsFail() {
- }
- }, 1);
+ }
+ }, 1);
+ }
}
}
@@ -264,6 +278,8 @@ public class MainActivity extends AppCompatActivity {
outState.putString(profileImageUrlState, mProfileImageUrl);
outState.putString(bannerImageUrlState, mBannerImageUrl);
outState.putString(karmaState, mKarma);
+ outState.putBoolean(fetchUserInfoState, mFetchUserInfoSuccess);
+ outState.putBoolean(insertSubscribedSubredditState, mInsertSuccess);
}
@Override
@@ -273,6 +289,8 @@ public class MainActivity extends AppCompatActivity {
mProfileImageUrl = savedInstanceState.getString(profileImageUrlState);
mBannerImageUrl = savedInstanceState.getString(bannerImageUrlState);
mKarma = savedInstanceState.getString(karmaState);
+ mFetchUserInfoSuccess = savedInstanceState.getBoolean(fetchUserInfoState);
+ mInsertSuccess = savedInstanceState.getBoolean(insertSubscribedSubredditState);
mNameTextView.setText(mName);
mKarmaTextView.setText(mKarma);
if(!mProfileImageUrl.equals("")) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
index 58b435f1..686a4874 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
@@ -69,7 +69,7 @@ class ParseComment {
for (int i = 0; i < actualCommentLength; i++) {
JSONObject data = allComments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
- String id = data.getString(JSONUtils.ID_KEY);
+ String fullName = data.getString(JSONUtils.LINK_ID);
String author = data.getString(JSONUtils.AUTHOR_KEY);
boolean isSubmitter = data.getBoolean(JSONUtils.IS_SUBMITTER_KEY);
String commentContent = data.getString(JSONUtils.BODY_KEY);
@@ -87,7 +87,7 @@ class ParseComment {
boolean collapsed = data.getBoolean(JSONUtils.COLLAPSED_KEY);
boolean hasReply = !(data.get(JSONUtils.REPLIES_KEY) instanceof String);
- newcommentData.add(new CommentData(id, author, formattedSubmitTime, commentContent, score, isSubmitter, permalink, depth, collapsed, hasReply, scoreHidden));
+ newcommentData.add(new CommentData(fullName, author, formattedSubmitTime, commentContent, score, isSubmitter, permalink, depth, collapsed, hasReply, scoreHidden));
}
} catch (JSONException e) {
parseFailed = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 36bed4e1..47a0ef7f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -53,6 +53,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private ImageView mNoCommentImageView;
private RequestQueue mVoteThingQueue;
+ private RequestQueue mAcquireAccessTokenRequestQueue;
private RequestQueue mCommentQueue;
@Override
@@ -107,6 +108,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
mVoteThingQueue = Volley.newRequestQueue(this);
+ mAcquireAccessTokenRequestQueue = Volley.newRequestQueue(this);
mCommentQueue = Volley.newRequestQueue(this);
subredditTextView.setText(mPostData.getSubredditName());
@@ -296,7 +298,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mCommentProgressbar.setVisibility(View.GONE);
mMoreCommentCount = moreCommentCount;
if(commentData.size() > 0) {
- CommentRecyclerViewAdapter adapter = new CommentRecyclerViewAdapter(ViewPostDetailActivity.this, commentData, mVoteThingQueue);
+ CommentRecyclerViewAdapter adapter = new CommentRecyclerViewAdapter(
+ ViewPostDetailActivity.this, commentData, mVoteThingQueue, mAcquireAccessTokenRequestQueue);
mRecyclerView.setAdapter(adapter);
mCommentCardView.setVisibility(View.VISIBLE);
} else {