Copying comments is now available. Some UI tweaks.

This commit is contained in:
Alex Ning 2020-01-30 20:38:35 +08:00
parent 5e401a6a96
commit ff5a60c827
17 changed files with 348 additions and 216 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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";

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M14.12,10.47L12,12.59l-2.13,-2.12 -1.41,1.41L10.59,14l-2.12,2.12 1.41,1.41L12,15.41l2.12,2.12 1.41,-1.41L13.41,14l2.12,-2.12zM15.5,4l-1,-1h-5l-1,1H5v2h14V4zM6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM8,9h8v10H8V9z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M14.06,9.02l0.92,0.92L5.92,19L5,19v-0.92l9.06,-9.06M17.66,3c-0.25,0 -0.51,0.1 -0.7,0.29l-1.83,1.83 3.75,3.75 1.83,-1.83c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.2,-0.2 -0.45,-0.29 -0.71,-0.29zM14.06,6.19L3,17.25L3,21h3.75L17.81,9.94l-3.75,-3.75z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92s2.92,-1.31 2.92,-2.92c0,-1.61 -1.31,-2.92 -2.92,-2.92zM18,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM6,13c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,20.02c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M14.12,10.47L12,12.59l-2.13,-2.12 -1.41,1.41L10.59,14l-2.12,2.12 1.41,1.41L12,15.41l2.12,2.12 1.41,-1.41L13.41,14l2.12,-2.12zM15.5,4l-1,-1h-5l-1,1H5v2h14V4zM6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM8,9h8v10H8V9z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M14.06,9.02l0.92,0.92L5.92,19L5,19v-0.92l9.06,-9.06M17.66,3c-0.25,0 -0.51,0.1 -0.7,0.29l-1.83,1.83 3.75,3.75 1.83,-1.83c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.2,-0.2 -0.45,-0.29 -0.71,-0.29zM14.06,6.19L3,17.25L3,21h3.75L17.81,9.94l-3.75,-3.75z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92s2.92,-1.31 2.92,-2.92c0,-1.61 -1.31,-2.92 -2.92,-2.92zM18,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM6,13c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,20.02c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1z"/>
</vector>

View File

@ -0,0 +1,86 @@
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/edit_text_view_comment_more_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableStart="@drawable/ic_edit_24dp"
android:drawablePadding="48dp"
android:focusable="true"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="32dp"
android:paddingBottom="16dp"
android:text="@string/edit"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default"
android:visibility="gone" />
<TextView
android:id="@+id/delete_text_view_comment_more_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableStart="@drawable/ic_delete_24dp"
android:drawablePadding="48dp"
android:focusable="true"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="32dp"
android:paddingBottom="16dp"
android:text="@string/delete"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default"
android:visibility="gone" />
<TextView
android:id="@+id/save_text_view_comment_more_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableStart="@drawable/ic_share_24dp"
android:drawablePadding="48dp"
android:focusable="true"
android:gravity="center_vertical"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="32dp"
android:paddingBottom="16dp"
android:text="@string/share"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default" />
<TextView
android:id="@+id/copy_text_view_comment_more_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableStart="@drawable/ic_copy_24dp"
android:drawablePadding="48dp"
android:focusable="true"
android:gravity="center_vertical"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="32dp"
android:paddingBottom="16dp"
android:text="@string/copy_text"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:orientation="vertical"
tools:context=".Fragment.ModifyCommentBottomSheetFragment">
<TextView
android:id="@+id/edit_text_view_modify_comment_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/edit"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/delete_text_view_modify_comment_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/delete"
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>

View File

@ -154,7 +154,6 @@
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_more_vert_grey_24dp"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@+id/expand_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
@ -198,11 +197,11 @@
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_reply_grey_24dp"
app:layout_constraintEnd_toStartOf="@id/share_button_item_post_comment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
<!--<ImageView
android:id="@+id/share_button_item_post_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -214,7 +213,7 @@
android:src="@drawable/ic_share_grey_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent"/>-->
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -411,4 +411,7 @@
<string name="copy_raw_text">Copy Raw Text</string>
<string name="copy_all_markdown">Copy All Markdown</string>
<string name="copy_all_raw_text">Copy All Raw Text</string>
<string name="save_comment">Save comment</string>
<string name="unsave_comment">Unsave comment</string>
</resources>