diff options
Diffstat (limited to 'app/src/main/java/ml')
8 files changed, 106 insertions, 6 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java index d7ee9918..e2e0a5b8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java @@ -139,8 +139,6 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing toolbar.setTitle(R.string.upvoted); } else if(mUserWhere.equals(PostDataSource.USER_WHERE_DOWNVOTED)) { toolbar.setTitle(R.string.downvoted); - } else if(mUserWhere.equals(PostDataSource.USER_WHERE_SAVED)) { - toolbar.setTitle(R.string.saved); } else if(mUserWhere.equals(PostDataSource.USER_WHERE_HIDDEN)) { toolbar.setTitle(R.string.hidden); } else if(mUserWhere.equals(PostDataSource.USER_WHERE_GILDED)){ diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index b68628fb..b3c501c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -747,6 +747,50 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie public void onVoteThingFail(int position1) { } }, mVisibleComments.get(commentPosition).getFullName(), newVoteType, holder.getAdapterPosition()); }); + + if(comment.isSaved()) { + ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + } else { + ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + } + + ((CommentViewHolder) holder).saveButton.setOnClickListener(view -> { + if (comment.isSaved()) { + comment.setSaved(false); + SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { + @Override + public void success() { + comment.setSaved(false); + ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show(); + } + + @Override + public void failed() { + comment.setSaved(true); + ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show(); + } + }); + } else { + comment.setSaved(true); + SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { + @Override + public void success() { + comment.setSaved(true); + ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show(); + } + + @Override + public void failed() { + comment.setSaved(false); + ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show(); + } + }); + } + }); } else if(holder instanceof LoadMoreChildCommentsViewHolder) { CommentData placeholder; placeholder = mIsSingleCommentThreadMode ? mVisibleComments.get(holder.getAdapterPosition() - 2) @@ -1314,6 +1358,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie @BindView(R.id.score_text_view_item_post_comment) TextView scoreTextView; @BindView(R.id.down_vote_button_item_post_comment) ImageView downVoteButton; @BindView(R.id.more_button_item_post_comment) ImageView moreButton; + @BindView(R.id.save_button_item_post_comment) ImageView saveButton; @BindView(R.id.expand_button_item_post_comment) ImageView expandButton; @BindView(R.id.share_button_item_post_comment) ImageView shareButton; @BindView(R.id.reply_button_item_post_comment) ImageView replyButton; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java index bce51afa..b06caa15 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java @@ -27,6 +27,7 @@ class CommentData implements Parcelable { private boolean collapsed; private boolean hasReply; private boolean scoreHidden; + private boolean saved; private boolean isExpanded; private ArrayList<CommentData> children; private ArrayList<String> moreChildrenFullnames; @@ -38,7 +39,7 @@ class CommentData implements Parcelable { CommentData(String id, String fullName, String author, String linkAuthor, String commentTime, String commentContent, String linkId, String subredditName, String parentId, int score, int voteType, boolean isSubmitter, String permalink, - int depth, boolean collapsed, boolean hasReply, boolean scoreHidden) { + int depth, boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) { this.id = id; this.fullName = fullName; this.author = author; @@ -56,6 +57,7 @@ class CommentData implements Parcelable { this.collapsed = collapsed; this.hasReply = hasReply; this.scoreHidden = scoreHidden; + this.saved = saved; this.isExpanded = false; moreChildrenStartingIndex = 0; isPlaceHolder = false; @@ -192,6 +194,14 @@ class CommentData implements Parcelable { return scoreHidden; } + public boolean isSaved() { + return saved; + } + + public void setSaved(boolean saved) { + this.saved = saved; + } + public boolean isExpanded() { return isExpanded; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java index d148f026..0a2ec243 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java @@ -287,6 +287,50 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R public void onVoteThingFail(int position1) { } }, comment.getFullName(), newVoteType, holder.getAdapterPosition()); }); + + if(comment.isSaved()) { + ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + } else { + ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + } + + ((DataViewHolder) holder).saveButton.setOnClickListener(view -> { + if (comment.isSaved()) { + comment.setSaved(false); + SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { + @Override + public void success() { + comment.setSaved(false); + ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + Toast.makeText(mContext, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show(); + } + + @Override + public void failed() { + comment.setSaved(true); + ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + Toast.makeText(mContext, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show(); + } + }); + } else { + comment.setSaved(true); + SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { + @Override + public void success() { + comment.setSaved(true); + ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + Toast.makeText(mContext, R.string.comment_saved_success, Toast.LENGTH_SHORT).show(); + } + + @Override + public void failed() { + comment.setSaved(false); + ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + Toast.makeText(mContext, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show(); + } + }); + } + }); } } } @@ -352,6 +396,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R @BindView(R.id.score_text_view_item_post_comment) TextView scoreTextView; @BindView(R.id.down_vote_button_item_post_comment) ImageView downvoteButton; @BindView(R.id.more_button_item_post_comment) ImageView moreButton; + @BindView(R.id.save_button_item_post_comment) ImageView saveButton; @BindView(R.id.share_button_item_post_comment) ImageView shareButton; @BindView(R.id.reply_button_item_post_comment) ImageView replyButton; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ModifyCommentBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ModifyCommentBottomSheetFragment.java index 5b19cfaf..7c39a8e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ModifyCommentBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ModifyCommentBottomSheetFragment.java @@ -55,7 +55,7 @@ public class ModifyCommentBottomSheetFragment extends RoundedBottomSheetDialogFr String accessToken = bundle.getString(EXTRA_ACCESS_TOKEN); editTextView.setOnClickListener(view -> { - Intent intent = new Intent(getActivity(), EditCommentActivity.class); + Intent intent = new Intent(activity, EditCommentActivity.class); intent.putExtra(EditCommentActivity.EXTRA_ACCESS_TOKEN, accessToken); intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, fullName); intent.putExtra(EditCommentActivity.EXTRA_CONTENT, content); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java index 7f48d8ea..e84b8e24 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java @@ -232,6 +232,7 @@ class ParseComment { } long submitTime = singleCommentData.getLong(JSONUtils.CREATED_UTC_KEY) * 1000; boolean scoreHidden = singleCommentData.getBoolean(JSONUtils.SCORE_HIDDEN_KEY); + boolean saved = singleCommentData.getBoolean(JSONUtils.SAVED_KEY); Calendar submitTimeCalendar = Calendar.getInstance(); submitTimeCalendar.setTimeInMillis(submitTime); @@ -247,7 +248,7 @@ class ParseComment { return new CommentData(id, fullName, author, linkAuthor, formattedSubmitTime, commentContent, linkId, subredditName, parentId, score, voteType, isSubmitter, permalink, depth, collapsed, - hasReply, scoreHidden); + hasReply, scoreHidden, saved); } @Nullable diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index e671bda5..15b5187b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -360,7 +360,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo if(mPostType == PostDataSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) { ((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE); - mGlide.load(R.drawable.thumbtack).into(((DataViewHolder) holder).stickiedPostImageView); + mGlide.load(R.drawable.ic_thumbtack_24dp).into(((DataViewHolder) holder).stickiedPostImageView); } if(isArchived) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index e3103796..e0b6672a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -22,4 +22,5 @@ public class SharedPreferencesUtils { public static final String RATE_KEY = "rate"; public static final String EMAIL_KEY = "email"; public static final String REDDIT_ACCOUNT_KEY = "reddit_account"; + public static final String SUBREDDIT_KEY = "subreddit"; } |