mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 07:01:05 +00:00
Use open link dialog for EML viewer
This commit is contained in:
parent
508c8df68b
commit
134e10c691
1 changed files with 51 additions and 2 deletions
|
@ -28,12 +28,16 @@ import android.content.SharedPreferences;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Layout;
|
||||||
|
import android.text.Spannable;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.ArrowKeyMovementMethod;
|
||||||
|
import android.text.style.URLSpan;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -115,7 +119,52 @@ public class ActivityEML extends ActivityBase {
|
||||||
rvAttachment.setLayoutManager(llm);
|
rvAttachment.setLayoutManager(llm);
|
||||||
|
|
||||||
tvBody.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT);
|
tvBody.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT);
|
||||||
tvBody.setMovementMethod(LinkMovementMethod.getInstance());
|
tvBody.setMovementMethod(new ArrowKeyMovementMethod() {
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
|
int x = (int) event.getX();
|
||||||
|
int y = (int) event.getY();
|
||||||
|
|
||||||
|
x -= widget.getTotalPaddingLeft();
|
||||||
|
y -= widget.getTotalPaddingTop();
|
||||||
|
|
||||||
|
x += widget.getScrollX();
|
||||||
|
y += widget.getScrollY();
|
||||||
|
|
||||||
|
Layout layout = widget.getLayout();
|
||||||
|
int line = layout.getLineForVertical(y);
|
||||||
|
int off = layout.getOffsetForHorizontal(line, x);
|
||||||
|
|
||||||
|
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
|
||||||
|
if (link.length > 0) {
|
||||||
|
String url = link[0].getURL();
|
||||||
|
Uri uri = Uri.parse(url);
|
||||||
|
if (uri.getScheme() == null)
|
||||||
|
uri = Uri.parse("https://" + url);
|
||||||
|
|
||||||
|
int start = buffer.getSpanStart(link[0]);
|
||||||
|
int end = buffer.getSpanEnd(link[0]);
|
||||||
|
String title = (start < 0 || end < 0 || end <= start
|
||||||
|
? null : buffer.subSequence(start, end).toString());
|
||||||
|
if (url.equals(title))
|
||||||
|
title = null;
|
||||||
|
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable("uri", uri);
|
||||||
|
args.putString("title", title);
|
||||||
|
|
||||||
|
FragmentDialogOpenLink fragment = new FragmentDialogOpenLink();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
fragment.show(getSupportFragmentManager(), "open:link");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onTouchEvent(widget, buffer, event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
vSeparatorAttachments.setVisibility(View.GONE);
|
vSeparatorAttachments.setVisibility(View.GONE);
|
||||||
grpReady.setVisibility(View.GONE);
|
grpReady.setVisibility(View.GONE);
|
||||||
|
|
Loading…
Reference in a new issue