diff --git a/app/src/main/assets/prism-autolinker.min.css b/app/src/main/assets/prism-autolinker.min.css new file mode 100644 index 0000000000..3c54381d78 --- /dev/null +++ b/app/src/main/assets/prism-autolinker.min.css @@ -0,0 +1 @@ +.token a{color:inherit} \ No newline at end of file diff --git a/app/src/main/assets/prism-autolinker.min.js b/app/src/main/assets/prism-autolinker.min.js new file mode 100644 index 0000000000..44aa79402a --- /dev/null +++ b/app/src/main/assets/prism-autolinker.min.js @@ -0,0 +1 @@ +!function(){if("undefined"!=typeof Prism){var i=/\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:=&!$'()*,;@]+(?:\?[\w\-+%~/.:=?&!$'()*,;@]*)?(?:#[\w\-+%~/.:#=?&!$'()*,;@]*)?/,n=/\b\S+@[\w.]+[a-z]{2}/,t=/\[([^\]]+)\]\(([^)]+)\)/,e=["comment","url","attr-value","string"];Prism.plugins.autolinker={processGrammar:function(r){r&&!r["url-link"]&&(Prism.languages.DFS(r,(function(r,a,l){e.indexOf(l)>-1&&!Array.isArray(a)&&(a.pattern||(a=this[r]={pattern:a}),a.inside=a.inside||{},"comment"==l&&(a.inside["md-link"]=t),"attr-value"==l?Prism.languages.insertBefore("inside","punctuation",{"url-link":i},a):a.inside["url-link"]=i,a.inside["email-link"]=n)})),r["url-link"]=i,r["email-link"]=n)}},Prism.hooks.add("before-highlight",(function(i){Prism.plugins.autolinker.processGrammar(i.grammar)})),Prism.hooks.add("wrap",(function(i){if(/-link$/.test(i.type)){i.tag="a";var n=i.content;if("email-link"==i.type&&0!=n.indexOf("mailto:"))n="mailto:"+n;else if("md-link"==i.type){var e=i.content.match(t);n=e[2],i.content=e[1]}i.attributes.href=n;try{i.content=decodeURIComponent(i.content)}catch(i){}}}))}}(); \ No newline at end of file diff --git a/app/src/main/java/eu/faircode/email/ActivityCode.java b/app/src/main/java/eu/faircode/email/ActivityCode.java index 2cccd1745c..49a1d7a965 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCode.java +++ b/app/src/main/java/eu/faircode/email/ActivityCode.java @@ -22,6 +22,7 @@ package eu.faircode.email; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; import android.text.Html; import android.text.TextUtils; @@ -32,6 +33,7 @@ import android.view.MenuItem; import android.view.View; import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.WebViewClient; import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; @@ -52,6 +54,7 @@ public class ActivityCode extends ActivityBase { private Group grpReady; private boolean lines = BuildConfig.DEBUG; + private boolean links = false; private boolean sanitize = BuildConfig.DEBUG; @Override @@ -60,6 +63,7 @@ public class ActivityCode extends ActivityBase { if (savedInstanceState != null) { lines = savedInstanceState.getBoolean("fair:lines"); + links = savedInstanceState.getBoolean("fair:links"); sanitize = savedInstanceState.getBoolean("fair:sanitize"); } @@ -93,6 +97,22 @@ public class ActivityCode extends ActivityBase { settings.setBlockNetworkImage(true); settings.setJavaScriptEnabled(true); + wvCode.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + Bundle args = new Bundle(); + args.putParcelable("uri", Uri.parse(url)); + args.putString("title", null); + args.putBoolean("always_confirm", true); + + FragmentDialogOpenLink fragment = new FragmentDialogOpenLink(); + fragment.setArguments(args); + fragment.show(getSupportFragmentManager(), "open:link"); + + return true; + } + }); + // Initialize grpReady.setVisibility(View.GONE); @@ -109,6 +129,7 @@ public class ActivityCode extends ActivityBase { @Override protected void onSaveInstanceState(Bundle outState) { outState.putBoolean("fair:lines", lines); + outState.putBoolean("fair:links", links); outState.putBoolean("fair:sanitize", sanitize); super.onSaveInstanceState(outState); } @@ -131,6 +152,12 @@ public class ActivityCode extends ActivityBase { ? R.drawable.twotone_speaker_notes_off_24 : R.drawable.twotone_speaker_notes_24); + menu.findItem(R.id.menu_links) + .setChecked(links) + .setIcon(links + ? R.drawable.twotone_link_off_24 + : R.drawable.twotone_link_24); + menu.findItem(R.id.menu_sanitize) .setVisible(BuildConfig.DEBUG || debug) .setChecked(sanitize) @@ -156,6 +183,11 @@ public class ActivityCode extends ActivityBase { invalidateOptionsMenu(); load(); return true; + } else if (itemId == R.id.menu_links) { + links = !links; + invalidateOptionsMenu(); + load(); + return true; } else if (itemId == R.id.menu_sanitize) { sanitize = !sanitize; invalidateOptionsMenu(); @@ -168,7 +200,7 @@ public class ActivityCode extends ActivityBase { private void load() { Intent intent = getIntent(); long id = intent.getLongExtra("id", -1L); - Log.i("Show code message=" + id + " lines=" + lines + " sanitize=" + sanitize); + Log.i("Show code message=" + id + " lines=" + lines + " links=" + links + " sanitize=" + sanitize); Bundle args = new Bundle(); args.putLong("id", id); @@ -233,12 +265,14 @@ public class ActivityCode extends ActivityBase { "" + " " + " " + + (links ? " " : "") + " " + "" + "" + " " + + (links ? " " : "") + "
" + Html.escapeHtml(code) + "
" + "" + ""; diff --git a/app/src/main/res/drawable/twotone_link_24.xml b/app/src/main/res/drawable/twotone_link_24.xml new file mode 100644 index 0000000000..9affeb9f87 --- /dev/null +++ b/app/src/main/res/drawable/twotone_link_24.xml @@ -0,0 +1,12 @@ + + + diff --git a/app/src/main/res/drawable/twotone_link_off_24.xml b/app/src/main/res/drawable/twotone_link_off_24.xml new file mode 100644 index 0000000000..d9d49a7bab --- /dev/null +++ b/app/src/main/res/drawable/twotone_link_off_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/menu/menu_code.xml b/app/src/main/res/menu/menu_code.xml index 73136c33fd..95f705a37f 100644 --- a/app/src/main/res/menu/menu_code.xml +++ b/app/src/main/res/menu/menu_code.xml @@ -8,6 +8,13 @@ android:title="@string/title_legend_line_numbers" app:showAsAction="always" /> + + Show original message Show reformatted message Show line numbers + Enable links Edit Default color Close hint