From 52b27971ffff6e57247ce06a7363cbaf37495d82 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 22 Sep 2019 21:28:28 +0800 Subject: Display comments count in the post. Display a comment and a save button in a post. Minor bugs fixed. --- .../infinityforreddit/CommentActivity.java | 4 +- .../CommentAndPostRecyclerViewAdapter.java | 101 ++++++++++++-- .../infinityforreddit/ParsePost.java | 49 +++---- .../ml/docilealligator/infinityforreddit/Post.java | 27 +++- .../infinityforreddit/PostDataSource.java | 19 ++- .../infinityforreddit/PostDataSourceFactory.java | 4 - .../infinityforreddit/PostRecyclerViewAdapter.java | 109 ++++++++++++--- .../PostUpdateEventToDetailActivity.java | 8 +- .../SubredditSelectionActivity.java | 6 +- .../infinityforreddit/ViewPostDetailActivity.java | 14 +- app/src/main/res/drawable/gold.xml | 4 +- app/src/main/res/drawable/ic_archive_outline.xml | 9 ++ .../main/res/drawable/ic_archive_outline_24dp.xml | 9 -- app/src/main/res/drawable/ic_outline_lock.xml | 9 ++ app/src/main/res/drawable/ic_outline_lock_24px.xml | 9 -- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/item_post.xml | 154 ++++++++++++++------- app/src/main/res/layout/item_post_detail.xml | 153 +++++++++++++++++--- 18 files changed, 516 insertions(+), 174 deletions(-) create mode 100644 app/src/main/res/drawable/ic_archive_outline.xml delete mode 100644 app/src/main/res/drawable/ic_archive_outline_24dp.xml create mode 100644 app/src/main/res/drawable/ic_outline_lock.xml delete mode 100644 app/src/main/res/drawable/ic_outline_lock_24px.xml (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java index 5104bef8..46f1c850 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java @@ -150,8 +150,8 @@ public class CommentActivity extends AppCompatActivity { }) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .build(); - markwon.setMarkdown(commentParentMarkwonView, intent.getExtras().getString(EXTRA_COMMENT_PARENT_TEXT_KEY)); - parentFullname = intent.getExtras().getString(EXTRA_PARENT_FULLNAME_KEY); + markwon.setMarkdown(commentParentMarkwonView, intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY)); + parentFullname = intent.getStringExtra(EXTRA_PARENT_FULLNAME_KEY); parentDepth = intent.getExtras().getInt(EXTRA_PARENT_DEPTH_KEY); parentPosition = intent.getExtras().getInt(EXTRA_PARENT_POSITION_KEY); isReplying = intent.getExtras().getBoolean(EXTRA_IS_REPLYING_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index ada28849..efb920e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -33,7 +33,6 @@ import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; -import com.google.android.material.chip.Chip; import com.libRG.CustomTextView; import com.santalu.aspectratioimageview.AspectRatioImageView; @@ -366,7 +365,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + ((PostDetailViewHolder) holder).mNSFWTextView.setOnClickListener(view -> { Intent intent = new Intent(mActivity, FilteredThingActivity.class); intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); @@ -374,15 +373,15 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + ((PostDetailViewHolder) holder).mTypeTextView.setOnClickListener(view -> { Intent intent = new Intent(mActivity, FilteredThingActivity.class); intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); @@ -394,7 +393,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(mActivity, ViewImageActivity.class); @@ -406,7 +405,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -437,7 +436,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -450,7 +449,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + Intent intent = new Intent(mActivity, CommentActivity.class); + intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle()); + intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false); + intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0); + mActivity.startActivity(intent); + }); + + ((PostDetailViewHolder) holder).commentsCountTextView.setText(Integer.toString(mPost.getnComments())); + + if(mPost.isSaved()) { + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + } else { + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + } + + ((PostDetailViewHolder) holder).saveButton.setOnClickListener(view -> { + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + if(mPost.isSaved()) { + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), + new SaveThing.SaveThingListener() { + @Override + public void success() { + mPost.setSaved(false); + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + + @Override + public void failed() { + mPost.setSaved(true); + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + }); + } else { + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), + new SaveThing.SaveThingListener() { + @Override + public void success() { + mPost.setSaved(true); + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px); + Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + + @Override + public void failed() { + mPost.setSaved(false); + ((PostDetailViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px); + Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + }); + } + }); } else if(holder.getItemViewType() == VIEW_TYPE_COMMENT) { CommentData comment; if(mIsSingleCommentThreadMode) { @@ -1100,7 +1170,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter