Added option to enable view code links

pull/214/head
M66B 1 year ago
parent 5b50da3ca1
commit cf4d00badc

@ -0,0 +1 @@
.token a{color:inherit}

@ -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){}}}))}}();

@ -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 {
"<head>" +
" <meta charset=\"utf-8\" />" +
" <link href=\"file:///android_asset/prism.css\" rel=\"stylesheet\" />" +
(links ? " <link href=\"file:///android_asset/prism-autolinker.min.css\" rel=\"stylesheet\" />" : "") +
" <style>" +
" body { font-size: smaller !important; }" +
" </style>" +
"</head>" +
"<body>" +
" <script src=\"file:///android_asset/prism.js\"></script>" +
(links ? " <script src=\"file:///android_asset/prism-autolinker.min.js\"></script>" : "") +
" <pre><code class=\"" + clazz + "\">" + Html.escapeHtml(code) + "</code></pre>" +
"</body>" +
"</html>";

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M17,7h-4v2h4c1.65,0 3,1.35 3,3s-1.35,3 -3,3h-4v2h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5zM11,15L7,15c-1.65,0 -3,-1.35 -3,-3s1.35,-3 3,-3h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-2zM8,11h8v2L8,13z"
android:strokeAlpha="0.87"
android:fillAlpha="0.87"/>
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M14.39,11L16,12.61V11zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1 0,1.27 -0.77,2.37 -1.87,2.84l1.4,1.4C21.05,15.36 22,13.79 22,12c0,-2.76 -2.24,-5 -5,-5zM2,4.27l3.11,3.11C3.29,8.12 2,9.91 2,12c0,2.76 2.24,5 5,5h4v-1.9H7c-1.71,0 -3.1,-1.39 -3.1,-3.1 0,-1.59 1.21,-2.9 2.76,-3.07L8.73,11H8v2h2.73L13,15.27V17h1.73l4.01,4.01 1.41,-1.41L3.41,2.86 2,4.27z"/>
</vector>

@ -8,6 +8,13 @@
android:title="@string/title_legend_line_numbers"
app:showAsAction="always" />
<item
android:id="@+id/menu_links"
android:checkable="true"
android:icon="@drawable/twotone_link_24"
android:title="@string/title_legend_enable_links"
app:showAsAction="always" />
<item
android:id="@+id/menu_sanitize"
android:checkable="true"

@ -2138,6 +2138,7 @@
<string name="title_legend_show_full">Show original message</string>
<string name="title_legend_show_reformatted">Show reformatted message</string>
<string name="title_legend_line_numbers">Show line numbers</string>
<string name="title_legend_enable_links">Enable links</string>
<string name="title_legend_edit">Edit</string>
<string name="title_legend_default_color">Default color</string>
<string name="title_legend_close_hint">Close hint</string>

Loading…
Cancel
Save