From 50da29ad8c507898b337b0ebcb84b34ef1680978 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 18 Sep 2019 16:01:08 +0800 Subject: Saving and unsaving comments are now available. Use xml thumbtack to avoid crashes on low resolution devices. Add a subreddit link in Settings -> About. --- .../infinityforreddit/AccountPostsActivity.java | 2 - .../CommentAndPostRecyclerViewAdapter.java | 45 ++++++++++++++++++++++ .../infinityforreddit/CommentData.java | 12 +++++- .../CommentsListingRecyclerViewAdapter.java | 45 ++++++++++++++++++++++ .../ModifyCommentBottomSheetFragment.java | 2 +- .../infinityforreddit/ParseComment.java | 3 +- .../infinityforreddit/PostRecyclerViewAdapter.java | 2 +- .../infinityforreddit/SharedPreferencesUtils.java | 1 + 8 files changed, 106 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/ml') 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 { + 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 children; private ArrayList 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 { + 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 { - 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