mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 13:57:10 +01:00
Support link and header in markdown bottom bar.
This commit is contained in:
parent
7cbe3d043f
commit
c809215759
@ -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);
|
||||
|
30
app/src/main/res/layout/dialog_insert_link.xml
Normal file
30
app/src/main/res/layout/dialog_insert_link.xml
Normal file
@ -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>
|
37
app/src/main/res/layout/dialog_select_header.xml
Normal file
37
app/src/main/res/layout/dialog_select_header.xml
Normal file
@ -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>
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user