Allow changing and removing of links

pull/178/head
M66B 5 years ago
parent 1e5bf48912
commit 8f00303717

@ -65,6 +65,7 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.QuoteSpan;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -1409,12 +1410,27 @@ public class FragmentCompose extends FragmentBase {
private void onActionLink() {
Uri uri = null;
ClipboardManager cbm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (cbm != null && cbm.hasPrimaryClip()) {
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString();
uri = Uri.parse(link);
if (uri.getScheme() == null)
uri = null;
if (etBody.hasSelection()) {
int start = etBody.getSelectionStart();
URLSpan[] spans = etBody.getText().getSpans(start, start, URLSpan.class);
if (spans.length > 0) {
String url = spans[0].getURL();
if (url != null) {
uri = Uri.parse(url);
if (uri.getScheme() == null)
uri = null;
}
}
}
if (uri == null) {
ClipboardManager cbm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (cbm != null && cbm.hasPrimaryClip()) {
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString();
uri = Uri.parse(link);
if (uri.getScheme() == null)
uri = null;
}
}
Bundle args = new Bundle();

@ -87,6 +87,12 @@ public class FragmentDialogLink extends FragmentDialogBase {
}
})
.setNegativeButton(android.R.string.cancel, null)
.setNeutralButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sendResult(RESULT_OK);
}
})
.create();
}
}

@ -117,14 +117,17 @@ public class StyleHelper {
ss.removeSpan(span);
}
if (start == end) {
etBody.getText().insert(start, url);
end += url.length();
ss = new SpannableString(etBody.getText());
}
if (url != null) {
if (start == end) {
etBody.getText().insert(start, url);
end += url.length();
ss = new SpannableString(etBody.getText());
}
ss.setSpan(new URLSpan(url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new URLSpan(url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
// Restore other spans
for (Object span : spans)
ss.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

Loading…
Cancel
Save