From e9ffe5a13c3aea89a80dc745c4bec4ab96ff8d9d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 5 Jun 2020 22:26:36 +0800 Subject: Copying post title, post content and comment content is now available in CommentActivity. --- app/src/main/AndroidManifest.xml | 2 +- .../Activity/CommentActivity.java | 38 ++++++++++++++++++++-- .../Activity/ViewPostDetailActivity.java | 5 +-- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 8 +++-- .../Fragment/CopyTextBottomSheetFragment.java | 23 ++++++++----- .../infinityforreddit/Utils/Utils.java | 9 +++++ 6 files changed, 67 insertions(+), 18 deletions(-) (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index da3e366c..9980720a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -265,7 +265,7 @@ android:label="@string/comment_activity_label" android:parentActivityName=".Activity.MainActivity" android:theme="@style/AppTheme.NoActionBar" - android:windowSoftInputMode="adjustResize" /> + android:windowSoftInputMode="adjustResize"/> { + Utils.hideKeyboard(CommentActivity.this); + Bundle bundle = new Bundle(); + if (parentText == null) { + bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentTextMarkdown); + } else { + bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentText); + bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentTextMarkdown); + } + copyTextBottomSheetFragment.setArguments(bundle); + copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag()); + return true; + }); + markwon.setMarkdown(commentParentMarkwonView, parentTextMarkdown); + } + String parentBodyMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY); String parentBody = intent.getStringExtra(EXTRA_COMMENT_PARENT_BODY_KEY); - if (parentBody != null && !parentBody.equals("")) { + if (parentBodyMarkdown != null && !parentBodyMarkdown.equals("")) { contentMarkdownRecyclerView.setVisibility(View.VISIBLE); contentMarkdownRecyclerView.setNestedScrollingEnabled(false); Markwon postBodyMarkwon = Markwon.builder(this) @@ -167,6 +190,15 @@ public class CommentActivity extends BaseActivity { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { textView.setTextColor(markdownColor); + textView.setOnLongClickListener(view -> { + Utils.hideKeyboard(CommentActivity.this); + Bundle bundle = new Bundle(); + bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentBody); + bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentBodyMarkdown); + copyTextBottomSheetFragment.setArguments(bundle); + copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag()); + return true; + }); } @Override @@ -200,7 +232,7 @@ public class CommentActivity extends BaseActivity { .build(); contentMarkdownRecyclerView.setLayoutManager(new LinearLayoutManager(this)); contentMarkdownRecyclerView.setAdapter(markwonAdapter); - markwonAdapter.setMarkdown(postBodyMarkwon, parentBody); + markwonAdapter.setMarkdown(postBodyMarkwon, parentBodyMarkdown); markwonAdapter.notifyDataSetChanged(); } parentFullname = intent.getStringExtra(EXTRA_PARENT_FULLNAME_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index 387867de..348a14ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -1340,8 +1340,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } Intent intent = new Intent(this, CommentActivity.class); - intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle()); - intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfText()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, mPost.getTitle()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain()); intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName()); intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false); 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 6bb80f1a..005da2f0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1832,8 +1832,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - showCopyDialog(markdownText); - dismiss(); - }); - copyAllRawTextTextView.setOnClickListener(view -> { copyText(rawText); dismiss(); }); - copyAllMarkdownTextView.setOnClickListener(view -> { - copyText(markdownText); - dismiss(); - }); + if (markdownText != null) { + copyMarkdownTextView.setOnClickListener(view -> { + showCopyDialog(markdownText); + dismiss(); + }); + + copyAllMarkdownTextView.setOnClickListener(view -> { + copyText(markdownText); + dismiss(); + }); + } else { + copyMarkdownTextView.setVisibility(View.GONE); + copyAllMarkdownTextView.setVisibility(View.GONE); + } return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java index 159b03f0..329371dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java @@ -1,11 +1,13 @@ package ml.docilealligator.infinityforreddit.Utils; +import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkInfo; import android.text.Html; import android.text.Spannable; +import android.view.inputmethod.InputMethodManager; import android.widget.TextView; import androidx.appcompat.widget.Toolbar; @@ -117,4 +119,11 @@ public class Utils { } } } + + public static void hideKeyboard(Activity activity) { + InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); + if (inputMethodManager != null && activity.getCurrentFocus() != null) { + inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); + } + } } -- cgit v1.2.3