diff options
Diffstat (limited to 'app/src/main/java')
7 files changed, 202 insertions, 172 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index b15d9416..9fd8ffc6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.Adapter; -import android.content.ActivityNotFoundException; import android.content.Intent; import android.graphics.ColorFilter; import android.graphics.PorterDuff; @@ -74,8 +73,8 @@ import ml.docilealligator.infinityforreddit.CommentData; import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.CustomView.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.FetchComment; +import ml.docilealligator.infinityforreddit.Fragment.CommentMoreBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.CopyTextBottomSheetFragment; -import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.Post.Post; import ml.docilealligator.infinityforreddit.Post.PostDataSource; @@ -721,7 +720,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy ((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime()); } - mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentContent()); + mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown()); ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((CommentViewHolder) holder).itemView.setPadding(comment.getDepth() * 8, 0, 0, 0); @@ -761,24 +760,21 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy ((CommentViewHolder) holder).verticalBlock.setLayoutParams(params); } - if (!mPost.isArchived() && !mPost.isLocked() && comment.getAuthor().equals(mAccountName)) { - ((CommentViewHolder) holder).moreButton.setVisibility(View.VISIBLE); - - ((CommentViewHolder) holder).moreButton.setOnClickListener(view -> { - ModifyCommentBottomSheetFragment modifyCommentBottomSheetFragment = new ModifyCommentBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); - bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_CONTENT, comment.getCommentContent()); - bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_FULLNAME, comment.getFullName()); - if (mIsSingleCommentThreadMode) { - bundle.putInt(ModifyCommentBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 2); - } else { - bundle.putInt(ModifyCommentBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 1); - } - modifyCommentBottomSheetFragment.setArguments(bundle); - modifyCommentBottomSheetFragment.show(((AppCompatActivity) mActivity).getSupportFragmentManager(), modifyCommentBottomSheetFragment.getTag()); - }); - } + ((CommentViewHolder) holder).moreButton.setOnClickListener(view -> { + Bundle bundle = new Bundle(); + if (!mPost.isArchived() && !mPost.isLocked() && comment.getAuthor().equals(mAccountName)) { + bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + } + bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment); + if (mIsSingleCommentThreadMode) { + bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 2); + } else { + bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 1); + } + CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment(); + commentMoreBottomSheetFragment.setArguments(bundle); + commentMoreBottomSheetFragment.show(mActivity.getSupportFragmentManager(), commentMoreBottomSheetFragment.getTag()); + }); if (comment.hasReply()) { if (comment.isExpanded()) { @@ -838,7 +834,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy Intent intent = new Intent(mActivity, CommentActivity.class); intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, comment.getDepth() + 1); - intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentContent()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentMarkdown()); intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName()); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true); @@ -1007,7 +1003,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mActivity.startActivity(intent); }); - ((CommentViewHolder) holder).shareButton.setOnClickListener(view -> { + /*((CommentViewHolder) holder).shareButton.setOnClickListener(view -> { try { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); @@ -1016,7 +1012,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } catch (ActivityNotFoundException e) { Toast.makeText(mActivity, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); } - }); + });*/ ((CommentViewHolder) holder).expandButton.setOnClickListener(view -> { if (((CommentViewHolder) holder).expandButton.getVisibility() == View.VISIBLE) { @@ -1500,7 +1496,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } public void editComment(String commentContent, int position) { - mVisibleComments.get(position).setCommentContent(commentContent); + mVisibleComments.get(position).setCommentMarkdown(commentContent); if (mIsSingleCommentThreadMode) { notifyItemChanged(position + 2); } else { @@ -1512,7 +1508,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy if (mVisibleComments != null && position >= 0 && position < mVisibleComments.size()) { if (mVisibleComments.get(position).hasReply()) { mVisibleComments.get(position).setAuthor("[deleted]"); - mVisibleComments.get(position).setCommentContent("[deleted]"); + mVisibleComments.get(position).setCommentMarkdown("[deleted]"); if (mIsSingleCommentThreadMode) { notifyItemChanged(position + 2); } else { @@ -1583,7 +1579,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mGlide.clear(((CommentViewHolder) holder).authorTypeImageView); ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE); ((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.GONE); - ((CommentViewHolder) holder).moreButton.setVisibility(View.GONE); + //((CommentViewHolder) holder).moreButton.setVisibility(View.GONE); ((CommentViewHolder) holder).expandButton.setVisibility(View.GONE); ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); @@ -1932,8 +1928,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy 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; @BindView(R.id.vertical_block_item_post_comment) @@ -1952,16 +1946,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy constraintSet.clear(expandButton.getId(), ConstraintSet.END); constraintSet.clear(saveButton.getId(), ConstraintSet.END); constraintSet.clear(replyButton.getId(), ConstraintSet.END); - constraintSet.clear(shareButton.getId(), ConstraintSet.END); constraintSet.connect(upVoteButton.getId(), ConstraintSet.END, scoreTextView.getId(), ConstraintSet.START); constraintSet.connect(scoreTextView.getId(), ConstraintSet.END, downVoteButton.getId(), ConstraintSet.START); constraintSet.connect(downVoteButton.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); constraintSet.connect(moreButton.getId(), ConstraintSet.START, expandButton.getId(), ConstraintSet.END); - constraintSet.connect(moreButton.getId(), ConstraintSet.END, upVoteButton.getId(), ConstraintSet.END); constraintSet.connect(expandButton.getId(), ConstraintSet.START, saveButton.getId(), ConstraintSet.END); constraintSet.connect(saveButton.getId(), ConstraintSet.START, replyButton.getId(), ConstraintSet.END); - constraintSet.connect(replyButton.getId(), ConstraintSet.START, shareButton.getId(), ConstraintSet.END); - constraintSet.connect(shareButton.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); + constraintSet.connect(replyButton.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); constraintSet.setHorizontalBias(moreButton.getId(), 0); constraintSet.applyTo(bottomConstraintLayout); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java index 0ba6e917..a9ee3f9e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.Adapter; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -38,7 +37,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.CommentData; -import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment; +import ml.docilealligator.infinityforreddit.Fragment.CommentMoreBottomSheetFragment; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; @@ -59,7 +58,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment @Override public boolean areContentsTheSame(@NonNull CommentData commentData, @NonNull CommentData t1) { - return commentData.getCommentContent().equals(t1.getCommentContent()); + return commentData.getCommentMarkdown().equals(t1.getCommentMarkdown()); } }; private Context mContext; @@ -157,7 +156,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment ((DataViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime()); } - mMarkwon.setMarkdown(((DataViewHolder) holder).commentMarkdownView, comment.getCommentContent()); + mMarkwon.setMarkdown(((DataViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown()); ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); @@ -174,19 +173,17 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment break; } - if (comment.getAuthor().equals(mAccountName)) { - ((DataViewHolder) holder).moreButton.setVisibility(View.VISIBLE); - ((DataViewHolder) holder).moreButton.setOnClickListener(view -> { - ModifyCommentBottomSheetFragment modifyCommentBottomSheetFragment = new ModifyCommentBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); - bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_CONTENT, comment.getCommentContent()); - bundle.putString(ModifyCommentBottomSheetFragment.EXTRA_COMMENT_FULLNAME, comment.getFullName()); - bundle.putInt(ModifyCommentBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 1); - modifyCommentBottomSheetFragment.setArguments(bundle); - modifyCommentBottomSheetFragment.show(((AppCompatActivity) mContext).getSupportFragmentManager(), modifyCommentBottomSheetFragment.getTag()); - }); - } + ((DataViewHolder) holder).moreButton.setOnClickListener(view -> { + Bundle bundle = new Bundle(); + if (comment.getAuthor().equals(mAccountName)) { + bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + } + bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment); + bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, holder.getAdapterPosition() - 1); + CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment(); + commentMoreBottomSheetFragment.setArguments(bundle); + commentMoreBottomSheetFragment.show(((AppCompatActivity) mContext).getSupportFragmentManager(), commentMoreBottomSheetFragment.getTag()); + }); ((DataViewHolder) holder).linearLayout.setOnClickListener(view -> { Intent intent = new Intent(mContext, ViewPostDetailActivity.class); @@ -200,17 +197,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment ((DataViewHolder) holder).commentMarkdownView.setOnClickListener(view -> ((DataViewHolder) holder).linearLayout.callOnClick()); - ((DataViewHolder) holder).shareButton.setOnClickListener(view -> { - try { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, comment.getPermalink()); - mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.share))); - } catch (ActivityNotFoundException e) { - Toast.makeText(mContext, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); - } - }); - ((DataViewHolder) holder).replyButton.setVisibility(View.GONE); ((DataViewHolder) holder).upvoteButton.setOnClickListener(view -> { @@ -441,8 +427,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<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; @@ -457,18 +441,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment constraintSet.clear(scoreTextView.getId(), ConstraintSet.START); constraintSet.clear(downvoteButton.getId(), ConstraintSet.START); constraintSet.clear(expandButton.getId(), ConstraintSet.END); - constraintSet.clear(saveButton.getId(), ConstraintSet.END); constraintSet.clear(replyButton.getId(), ConstraintSet.END); - constraintSet.clear(shareButton.getId(), ConstraintSet.END); constraintSet.connect(upvoteButton.getId(), ConstraintSet.END, scoreTextView.getId(), ConstraintSet.START); constraintSet.connect(scoreTextView.getId(), ConstraintSet.END, downvoteButton.getId(), ConstraintSet.START); constraintSet.connect(downvoteButton.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); constraintSet.connect(moreButton.getId(), ConstraintSet.START, expandButton.getId(), ConstraintSet.END); constraintSet.connect(moreButton.getId(), ConstraintSet.END, upvoteButton.getId(), ConstraintSet.END); - constraintSet.connect(expandButton.getId(), ConstraintSet.START, saveButton.getId(), ConstraintSet.END); - constraintSet.connect(saveButton.getId(), ConstraintSet.START, replyButton.getId(), ConstraintSet.END); - constraintSet.connect(replyButton.getId(), ConstraintSet.START, shareButton.getId(), ConstraintSet.END); - constraintSet.connect(shareButton.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); + constraintSet.connect(expandButton.getId(), ConstraintSet.START, replyButton.getId(), ConstraintSet.END); + constraintSet.connect(replyButton.getId(), ConstraintSet.START, replyButton.getId(), ConstraintSet.END); constraintSet.setHorizontalBias(moreButton.getId(), 0); constraintSet.applyTo(bottomConstraintLayout); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java index 9d169147..2396aa9b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java @@ -29,7 +29,8 @@ public class CommentData implements Parcelable { private String linkAuthor; private String commentTime; private long commentTimeMillis; - private String commentContent; + private String commentMarkdown; + private String commentRawText; private String linkId; private String subredditName; private String parentId; @@ -51,9 +52,10 @@ public class CommentData implements Parcelable { private boolean isLoadingMoreChildren; private boolean loadMoreChildrenFailed; - public CommentData(String id, String fullName, String author, String authorFlair, String linkAuthor, String commentTime, - long commentTimeMillis, String commentContent, String linkId, String subredditName, String parentId, int score, - int voteType, boolean isSubmitter, String distinguished, String permalink, + public CommentData(String id, String fullName, String author, String authorFlair, String linkAuthor, + String commentTime, long commentTimeMillis, String commentMarkdown, + String commentRawText, String linkId, String subredditName, String parentId, + int score, int voteType, boolean isSubmitter, String distinguished, String permalink, int depth, boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) { this.id = id; this.fullName = fullName; @@ -62,7 +64,8 @@ public class CommentData implements Parcelable { this.linkAuthor = linkAuthor; this.commentTime = commentTime; this.commentTimeMillis = commentTimeMillis; - this.commentContent = commentContent; + this.commentMarkdown = commentMarkdown; + this.commentRawText = commentRawText; this.linkId = linkId; this.subredditName = subredditName; this.parentId = parentId; @@ -97,7 +100,8 @@ public class CommentData implements Parcelable { linkAuthor = in.readString(); commentTime = in.readString(); commentTimeMillis = in.readLong(); - commentContent = in.readString(); + commentMarkdown = in.readString(); + commentRawText = in.readString(); linkId = in.readString(); subredditName = in.readString(); parentId = in.readString(); @@ -151,12 +155,20 @@ public class CommentData implements Parcelable { return commentTimeMillis; } - public String getCommentContent() { - return commentContent; + public String getCommentMarkdown() { + return commentMarkdown; } - public void setCommentContent(String commentContent) { - this.commentContent = commentContent; + public void setCommentMarkdown(String commentMarkdown) { + this.commentMarkdown = commentMarkdown; + } + + public String getCommentRawText() { + return commentRawText; + } + + public void setCommentRawText(String commentRawText) { + this.commentRawText = commentRawText; } public String getLinkId() { @@ -328,7 +340,8 @@ public class CommentData implements Parcelable { parcel.writeString(linkAuthor); parcel.writeString(commentTime); parcel.writeLong(commentTimeMillis); - parcel.writeString(commentContent); + parcel.writeString(commentMarkdown); + parcel.writeString(commentRawText); parcel.writeString(linkId); parcel.writeString(subredditName); parcel.writeString(parentId); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentMoreBottomSheetFragment.java new file mode 100644 index 00000000..d339b5f6 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentMoreBottomSheetFragment.java @@ -0,0 +1,130 @@ +package ml.docilealligator.infinityforreddit.Fragment; + + +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.Intent; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; + +import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.EditCommentActivity; +import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity; +import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; +import ml.docilealligator.infinityforreddit.CommentData; +import ml.docilealligator.infinityforreddit.R; + + +/** + * A simple {@link Fragment} subclass. + */ +public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFragment { + + public static final String EXTRA_COMMENT = "ECF"; + public static final String EXTRA_ACCESS_TOKEN = "EAT"; + public static final String EXTRA_POSITION = "EP"; + @BindView(R.id.edit_text_view_comment_more_bottom_sheet_fragment) + TextView editTextView; + @BindView(R.id.delete_text_view_comment_more_bottom_sheet_fragment) + TextView deleteTextView; + @BindView(R.id.save_text_view_comment_more_bottom_sheet_fragment) + TextView shareTextView; + @BindView(R.id.copy_text_view_comment_more_bottom_sheet_fragment) + TextView copyTextView; + private AppCompatActivity activity; + public CommentMoreBottomSheetFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_comment_more_bottom_sheet, container, false); + ButterKnife.bind(this, rootView); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + + Bundle bundle = getArguments(); + CommentData commentData = bundle.getParcelable(EXTRA_COMMENT); + if (commentData == null) { + dismiss(); + return rootView; + } + String accessToken = bundle.getString(EXTRA_ACCESS_TOKEN); + + if (accessToken != null && !accessToken.equals("")) { + editTextView.setVisibility(View.VISIBLE); + deleteTextView.setVisibility(View.VISIBLE); + + editTextView.setOnClickListener(view -> { + Intent intent = new Intent(activity, EditCommentActivity.class); + intent.putExtra(EditCommentActivity.EXTRA_ACCESS_TOKEN, accessToken); + intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, commentData.getFullName()); + intent.putExtra(EditCommentActivity.EXTRA_CONTENT, commentData.getCommentMarkdown()); + intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION)); + if (activity instanceof ViewPostDetailActivity) { + activity.startActivityForResult(intent, ViewPostDetailActivity.EDIT_COMMENT_REQUEST_CODE); + } else { + startActivity(intent); + } + + dismiss(); + }); + + deleteTextView.setOnClickListener(view -> { + dismiss(); + if (activity instanceof ViewPostDetailActivity) { + ((ViewPostDetailActivity) activity).deleteComment(commentData.getFullName(), bundle.getInt(EXTRA_POSITION)); + } else if (activity instanceof ViewUserDetailActivity) { + ((ViewUserDetailActivity) activity).deleteComment(commentData.getFullName()); + } + }); + } + + shareTextView.setOnClickListener(view -> { + dismiss(); + try { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, commentData.getPermalink()); + activity.startActivity(Intent.createChooser(intent, getString(R.string.share))); + } catch (ActivityNotFoundException e) { + Toast.makeText(activity, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); + } + }); + + copyTextView.setOnClickListener(view -> { + dismiss(); + CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment(); + Bundle copyBundle = new Bundle(); + copyBundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, commentData.getCommentMarkdown()); + copyBundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, commentData.getCommentRawText()); + copyTextBottomSheetFragment.setArguments(copyBundle); + copyTextBottomSheetFragment.show(activity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag()); + }); + + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (AppCompatActivity) context; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ModifyCommentBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ModifyCommentBottomSheetFragment.java deleted file mode 100644 index b0c43ffd..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ModifyCommentBottomSheetFragment.java +++ /dev/null @@ -1,88 +0,0 @@ -package ml.docilealligator.infinityforreddit.Fragment; - - -import android.app.Activity; -import android.content.Intent; -import android.content.res.Configuration; -import android.os.Build; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.fragment.app.Fragment; - -import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.Activity.EditCommentActivity; -import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity; -import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; -import ml.docilealligator.infinityforreddit.R; - - -/** - * A simple {@link Fragment} subclass. - */ -public class ModifyCommentBottomSheetFragment extends RoundedBottomSheetDialogFragment { - - public static final String EXTRA_COMMENT_FULLNAME = "ECF"; - public static final String EXTRA_COMMENT_CONTENT = "ECC"; - public static final String EXTRA_ACCESS_TOKEN = "EAT"; - public static final String EXTRA_POSITION = "EP"; - @BindView(R.id.edit_text_view_modify_comment_bottom_sheet_fragment) - TextView editTextView; - @BindView(R.id.delete_text_view_modify_comment_bottom_sheet_fragment) - TextView deleteTextView; - public ModifyCommentBottomSheetFragment() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_modify_comment_bottom_sheet, container, false); - ButterKnife.bind(this, rootView); - - Activity activity = getActivity(); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - - Bundle bundle = getArguments(); - String fullName = bundle.getString(EXTRA_COMMENT_FULLNAME); - String content = bundle.getString(EXTRA_COMMENT_CONTENT); - String accessToken = bundle.getString(EXTRA_ACCESS_TOKEN); - - editTextView.setOnClickListener(view -> { - 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); - intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION)); - if (activity instanceof ViewPostDetailActivity) { - activity.startActivityForResult(intent, ViewPostDetailActivity.EDIT_COMMENT_REQUEST_CODE); - } else { - startActivity(intent); - } - - dismiss(); - }); - - deleteTextView.setOnClickListener(view -> { - dismiss(); - if (activity instanceof ViewPostDetailActivity) { - ((ViewPostDetailActivity) activity).deleteComment(fullName, bundle.getInt(EXTRA_POSITION)); - } else if (activity instanceof ViewUserDetailActivity) { - ((ViewUserDetailActivity) activity).deleteComment(fullName); - } - }); - - return rootView; - } - -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java index c7cb5734..d5c86143 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java @@ -127,10 +127,12 @@ public class ParseComment { String parentId = singleCommentData.getString(JSONUtils.PARENT_ID_KEY); boolean isSubmitter = singleCommentData.getBoolean(JSONUtils.IS_SUBMITTER_KEY); String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY); - String commentContent = ""; + String commentMarkdown = ""; if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) { - commentContent = Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim()); + commentMarkdown = Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim()); } + String commentRawText = Utils.trimTrailingWhitespace( + Html.fromHtml(singleCommentData.getString(JSONUtils.BODY_HTML_KEY))).toString(); String permalink = Html.fromHtml(singleCommentData.getString(JSONUtils.PERMALINK_KEY)).toString(); int score = singleCommentData.getInt(JSONUtils.SCORE_KEY); int voteType; @@ -157,8 +159,9 @@ public class ParseComment { boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String); return new CommentData(id, fullName, author, authorFlair, linkAuthor, formattedSubmitTime, - submitTime, commentContent, linkId, subredditName, parentId, score, voteType, - isSubmitter, distinguished, permalink, depth, collapsed, hasReply, scoreHidden, saved); + submitTime, commentMarkdown, commentRawText, linkId, subredditName, parentId, score, + voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, + scoreHidden, saved); } @Nullable diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java index 91babc40..77338813 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java @@ -43,6 +43,7 @@ public class JSONUtils { public static final String REDDIT_VIDEO_PREVIEW_KEY = "reddit_video_preview"; public static final String STICKIED_KEY = "stickied"; public static final String BODY_KEY = "body"; + public static final String BODY_HTML_KEY = "body_html"; public static final String COLLAPSED_KEY = "collapsed"; public static final String IS_SUBMITTER_KEY = "is_submitter"; public static final String REPLIES_KEY = "replies"; |