aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java38
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java23
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java9
5 files changed, 66 insertions, 17 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
index 3dfb6298..b1ea2f30 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
@@ -51,16 +51,20 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
+import ml.docilealligator.infinityforreddit.Fragment.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SendComment;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;
public class CommentActivity extends BaseActivity {
public static final String EXTRA_COMMENT_PARENT_TEXT_KEY = "ECPTK";
+ public static final String EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY = "ECPTMK";
public static final String EXTRA_COMMENT_PARENT_BODY_KEY = "ECPBK";
+ public static final String EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY = "ECPBMK";
public static final String EXTRA_PARENT_FULLNAME_KEY = "EPFK";
public static final String EXTRA_PARENT_DEPTH_KEY = "EPDK";
public static final String EXTRA_PARENT_POSITION_KEY = "EPPK";
@@ -133,6 +137,9 @@ public class CommentActivity extends BaseActivity {
}
Intent intent = getIntent();
+ String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
+ String parentText = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY);
+ CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() {
@Override
@@ -157,9 +164,25 @@ public class CommentActivity extends BaseActivity {
)
)
.build();
- markwon.setMarkdown(commentParentMarkwonView, intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY));
+ if (parentTextMarkdown != null) {
+ commentParentMarkwonView.setOnLongClickListener(view -> {
+ 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<Recy
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_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_IS_REPLYING_KEY, false);
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
@@ -2751,7 +2752,8 @@ 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.getCommentMarkdown());
+ intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, comment.getCommentMarkdown());
+ intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentRawText());
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName());
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java
index f53f6c09..b0b6469d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java
@@ -60,20 +60,25 @@ public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragmen
dismiss();
});
- copyMarkdownTextView.setOnClickListener(view -> {
- 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);
+ }
+ }
}