Allow changing and removing of links

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

@ -65,6 +65,7 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan; import android.text.style.ImageSpan;
import android.text.style.QuoteSpan; import android.text.style.QuoteSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -1409,6 +1410,20 @@ public class FragmentCompose extends FragmentBase {
private void onActionLink() { private void onActionLink() {
Uri uri = null; Uri 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); ClipboardManager cbm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (cbm != null && cbm.hasPrimaryClip()) { if (cbm != null && cbm.hasPrimaryClip()) {
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString(); String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString();
@ -1416,6 +1431,7 @@ public class FragmentCompose extends FragmentBase {
if (uri.getScheme() == null) if (uri.getScheme() == null)
uri = null; uri = null;
} }
}
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable("uri", uri); args.putParcelable("uri", uri);

@ -87,6 +87,12 @@ public class FragmentDialogLink extends FragmentDialogBase {
} }
}) })
.setNegativeButton(android.R.string.cancel, null) .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(); .create();
} }
} }

@ -117,6 +117,7 @@ public class StyleHelper {
ss.removeSpan(span); ss.removeSpan(span);
} }
if (url != null) {
if (start == end) { if (start == end) {
etBody.getText().insert(start, url); etBody.getText().insert(start, url);
end += url.length(); end += url.length();
@ -124,7 +125,9 @@ public class StyleHelper {
} }
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) for (Object span : spans)
ss.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ss.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

Loading…
Cancel
Save