aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java72
-rw-r--r--app/src/main/res/layout/dialog_insert_link.xml30
-rw-r--r--app/src/main/res/layout/dialog_select_header.xml37
-rw-r--r--app/src/main/res/values/strings.xml7
4 files changed, 144 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 0417428d..1dab8fc3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
@@ -14,6 +14,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
+import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
@@ -294,8 +295,33 @@ public class CommentActivity extends BaseActivity {
}
break;
}
- case MarkdownBottomBarRecyclerViewAdapter.LINK:
+ case MarkdownBottomBarRecyclerViewAdapter.LINK: {
+ View dialogView = getLayoutInflater().inflate(R.layout.dialog_insert_link, null);
+ EditText textEditText = dialogView.findViewById(R.id.edit_text_insert_link_dialog);
+ EditText linkEditText = dialogView.findViewById(R.id.edit_link_insert_link_dialog);
+
+ 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();
+ textEditText.setText(currentSelection);
+ }
+
+ new MaterialAlertDialogBuilder(CommentActivity.this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.insert_link)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (editTextDialogInterface, i1)
+ -> {
+ String text = textEditText.getText().toString();
+ String link = linkEditText.getText().toString();
+
+ commentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
+ "[" + text + "](" + link + ")", 0, "[]()".length() + text.length() + link.length());
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .show();
break;
+ }
case MarkdownBottomBarRecyclerViewAdapter.STRIKE_THROUGH: {
int start = Math.max(commentEditText.getSelectionStart(), 0);
int end = Math.max(commentEditText.getSelectionEnd(), 0);
@@ -310,8 +336,50 @@ public class CommentActivity extends BaseActivity {
}
break;
}
- case MarkdownBottomBarRecyclerViewAdapter.HEADER:
+ case MarkdownBottomBarRecyclerViewAdapter.HEADER: {
+ View dialogView = getLayoutInflater().inflate(R.layout.dialog_select_header, null);
+ SeekBar seekBar = dialogView.findViewById(R.id.seek_bar_dialog_select_header);
+ new MaterialAlertDialogBuilder(CommentActivity.this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.select_header_size)
+ .setView(dialogView)
+ .setPositiveButton(R.string.ok, (editTextDialogInterface, i1)
+ -> {
+ int start = Math.max(commentEditText.getSelectionStart(), 0);
+ int end = Math.max(commentEditText.getSelectionEnd(), 0);
+ String hashTags;
+ switch (seekBar.getProgress()) {
+ case 0:
+ hashTags = "######";
+ break;
+ case 1:
+ hashTags = "#####";
+ break;
+ case 2:
+ hashTags = "####";
+ break;
+ case 3:
+ hashTags = "###";
+ break;
+ case 4:
+ hashTags = "##";
+ break;
+ default:
+ hashTags = "#";
+ break;
+ }
+ if (end != start) {
+ String currentSelection = commentEditText.getText().subSequence(start, end).toString();
+ commentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
+ hashTags + currentSelection, 0, hashTags.length() + currentSelection.length());
+ } else {
+ commentEditText.getText().replace(start, end,
+ hashTags, 0, hashTags.length());
+ }
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .show();
break;
+ }
case MarkdownBottomBarRecyclerViewAdapter.ORDERED_LIST: {
int start = Math.max(commentEditText.getSelectionStart(), 0);
int end = Math.max(commentEditText.getSelectionEnd(), 0);
diff --git a/app/src/main/res/layout/dialog_insert_link.xml b/app/src/main/res/layout/dialog_insert_link.xml
new file mode 100644
index 00000000..c54e66ff
--- /dev/null
+++ b/app/src/main/res/layout/dialog_insert_link.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <EditText
+ android:id="@+id/edit_text_insert_link_dialog"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="24dp"
+ android:background="#00000000"
+ android:hint="@string/text_hint"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family" />
+
+ <EditText
+ android:id="@+id/edit_link_insert_link_dialog"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="24dp"
+ android:background="#00000000"
+ android:hint="@string/link_hint"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_select_header.xml b/app/src/main/res/layout/dialog_select_header.xml
new file mode 100644
index 00000000..14c68249
--- /dev/null
+++ b/app/src/main/res/layout/dialog_select_header.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:text="@string/header6"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family" />
+
+ <SeekBar
+ android:id="@+id/seek_bar_dialog_select_header"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical"
+ android:padding="16dp"
+ android:max="5"
+ android:theme="@style/Widget.AppCompat.SeekBar.Discrete" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:text="@string/header1"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6185b922..337f759d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -865,4 +865,11 @@
<string name="select_user_flair_failed">Cannot select user flair</string>
<string name="select_this_user_flair">Select this user flair?</string>
+ <string name="select_header_size">Select Header Size</string>
+ <string name="header1">H1</string>
+ <string name="header6">H6</string>
+ <string name="insert_link">Insert Link</string>
+ <string name="text_hint">Text</string>
+ <string name="link_hint">Link</string>
+
</resources>