Browse Source

allow link insertion without link text

pull/61/merge
Thodoris1999 6 years ago
parent
commit
e92e2fa75d
  1. 40
      app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

40
app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

@ -21,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.ScrollView; import android.widget.ScrollView;
@ -210,26 +211,33 @@ public class EditorView extends LinearLayout {
linkText.getEditText().setText( linkText.getEditText().setText(
editText.getText().toString().substring(editText.getSelectionStart(), editText.getSelectionEnd())); editText.getText().toString().substring(editText.getSelectionStart(), editText.getSelectionEnd()));
} }
new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog) AlertDialog linkDialog = new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog)
.setTitle(R.string.dialog_create_link_title) .setTitle(R.string.dialog_create_link_title)
.setView(dialogBody) .setView(dialogBody)
.setPositiveButton(R.string.ok, (dialog, which) -> { .setPositiveButton(R.string.ok, null)
if (TextUtils.isEmpty(Objects.requireNonNull(linkUrl.getEditText()).getText().toString())) { .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
linkUrl.setError(context.getString(R.string.input_field_required)); .create();
return; linkDialog.setOnShowListener(dialogInterface -> {
} Button button = linkDialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (TextUtils.isEmpty(Objects.requireNonNull(linkText.getEditText()).getText().toString())) { button.setOnClickListener(view12 -> {
linkUrl.setError(context.getString(R.string.input_field_required)); if (TextUtils.isEmpty(Objects.requireNonNull(linkUrl.getEditText()).getText().toString())) {
return; linkUrl.setError(context.getString(R.string.input_field_required));
} return;
}
if (hadTextSelection) editText.getText().delete(start, end); if (hadTextSelection) editText.getText().delete(start, end);
if (!TextUtils.isEmpty(linkText.getEditText().getText())) {
getText().insert(editText.getSelectionStart(), "[url=" + getText().insert(editText.getSelectionStart(), "[url=" +
Objects.requireNonNull(linkUrl.getEditText()).getText().toString() + "]" + linkUrl.getEditText().getText().toString() + "]" +
Objects.requireNonNull(linkText.getEditText()).getText().toString() + "[/url]"); linkText.getEditText().getText().toString() + "[/url]");
}) }
.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) else
.show(); getText().insert(editText.getSelectionStart(), "[url]" +
linkUrl.getEditText().getText().toString() + "[/url]");
linkDialog.dismiss();
});
});
linkDialog.show();
break; break;
} }
case R.drawable.ic_format_quote: { case R.drawable.ic_format_quote: {

Loading…
Cancel
Save