diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-18 02:24:41 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-18 02:24:41 +0000 |
commit | 7cbe3d043f3fd3a5f80387e362df2f52709e4cfd (patch) | |
tree | a77027e1d201d3c3d36e1f17a5d3b4866b9df46e /app/src | |
parent | 2f27074478538206dc8cb1f762365535b9de20f0 (diff) | |
download | infinity-for-reddit-7cbe3d043f3fd3a5f80387e362df2f52709e4cfd.tar infinity-for-reddit-7cbe3d043f3fd3a5f80387e362df2f52709e4cfd.tar.gz infinity-for-reddit-7cbe3d043f3fd3a5f80387e362df2f52709e4cfd.tar.bz2 infinity-for-reddit-7cbe3d043f3fd3a5f80387e362df2f52709e4cfd.tar.lz infinity-for-reddit-7cbe3d043f3fd3a5f80387e362df2f52709e4cfd.tar.xz infinity-for-reddit-7cbe3d043f3fd3a5f80387e362df2f52709e4cfd.tar.zst infinity-for-reddit-7cbe3d043f3fd3a5f80387e362df2f52709e4cfd.zip |
Implement some markdown syntax item in CommentActivity.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java | 90 |
1 files changed, 88 insertions, 2 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 2138e6b5..0417428d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java @@ -9,7 +9,6 @@ import android.os.Bundle; import android.text.Spanned; import android.text.style.SuperscriptSpan; import android.text.util.Linkify; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -266,7 +265,94 @@ public class CommentActivity extends BaseActivity { MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() { @Override public void onClick(int item) { - Log.i("asasdf", "s " + item); + switch (item) { + case MarkdownBottomBarRecyclerViewAdapter.BOLD: { + int start = Math.max(commentEditText.getSelectionStart(), 0); + int end = Math.max(commentEditText.getSelectionEnd(), 0); + if (end != start) { + String currentSelection = commentEditText.getText().subSequence(start, end).toString(); + commentEditText.getText().replace(Math.min(start, end), Math.max(start, end), + "**" + currentSelection + "**", 0, "****".length() + currentSelection.length()); + } else { + commentEditText.getText().replace(start, end, + "****", 0, "****".length()); + commentEditText.setSelection(start + "**".length()); + } + break; + } + case MarkdownBottomBarRecyclerViewAdapter.ITALIC: { + int start = Math.max(commentEditText.getSelectionStart(), 0); + int end = Math.max(commentEditText.getSelectionEnd(), 0); + if (end != start) { + String currentSelection = commentEditText.getText().subSequence(start, end).toString(); + commentEditText.getText().replace(Math.min(start, end), Math.max(start, end), + "*" + currentSelection + "*", 0, "**".length() + currentSelection.length()); + } else { + commentEditText.getText().replace(start, end, + "**", 0, "**".length()); + commentEditText.setSelection(start + "*".length()); + } + break; + } + case MarkdownBottomBarRecyclerViewAdapter.LINK: + break; + case MarkdownBottomBarRecyclerViewAdapter.STRIKE_THROUGH: { + int start = Math.max(commentEditText.getSelectionStart(), 0); + int end = Math.max(commentEditText.getSelectionEnd(), 0); + if (end != start) { + String currentSelection = commentEditText.getText().subSequence(start, end).toString(); + commentEditText.getText().replace(Math.min(start, end), Math.max(start, end), + "~~" + currentSelection + "~~", 0, "~~~~".length() + currentSelection.length()); + } else { + commentEditText.getText().replace(start, end, + "~~~~", 0, "~~~~".length()); + commentEditText.setSelection(start + "~~".length()); + } + break; + } + case MarkdownBottomBarRecyclerViewAdapter.HEADER: + break; + case MarkdownBottomBarRecyclerViewAdapter.ORDERED_LIST: { + int start = Math.max(commentEditText.getSelectionStart(), 0); + int end = Math.max(commentEditText.getSelectionEnd(), 0); + if (end != start) { + String currentSelection = commentEditText.getText().subSequence(start, end).toString(); + commentEditText.getText().replace(Math.min(start, end), Math.max(start, end), + "1. " + currentSelection, 0, "1. ".length() + currentSelection.length()); + } else { + commentEditText.getText().replace(start, end, + "1. ", 0, "1. ".length()); + } + break; + } + case MarkdownBottomBarRecyclerViewAdapter.UNORDERED_LIST: { + int start = Math.max(commentEditText.getSelectionStart(), 0); + int end = Math.max(commentEditText.getSelectionEnd(), 0); + if (end != start) { + String currentSelection = commentEditText.getText().subSequence(start, end).toString(); + commentEditText.getText().replace(Math.min(start, end), Math.max(start, end), + "* " + currentSelection, 0, "* ".length() + currentSelection.length()); + } else { + commentEditText.getText().replace(start, end, + "* ", 0, "* ".length()); + } + break; + } + case MarkdownBottomBarRecyclerViewAdapter.SPOILER: { + int start = Math.max(commentEditText.getSelectionStart(), 0); + int end = Math.max(commentEditText.getSelectionEnd(), 0); + if (end != start) { + String currentSelection = commentEditText.getText().subSequence(start, end).toString(); + commentEditText.getText().replace(Math.min(start, end), Math.max(start, end), + ">!" + currentSelection + "!<", 0, ">!!<".length() + currentSelection.length()); + } else { + commentEditText.getText().replace(start, end, + ">!!<", 0, ">!!<".length()); + commentEditText.setSelection(start + ">!".length()); + } + break; + } + } } }); |