From 4a5e0aff96e03416afa271ea436fd4604fc55d84 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 18 Nov 2020 20:34:41 +0100 Subject: [PATCH] Added long press to open full --- .../eu/faircode/email/AdapterMessage.java | 94 +++++++++++++++++++ .../main/res/layout/fragment_open_full.xml | 15 +++ 2 files changed, 109 insertions(+) create mode 100644 app/src/main/res/layout/fragment_open_full.xml diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 4b86206b99..b7b79767d8 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -93,6 +93,7 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.view.textclassifier.ConversationAction; import android.view.textclassifier.ConversationActions; +import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.Button; import android.widget.CheckBox; @@ -118,6 +119,7 @@ import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.ColorUtils; import androidx.core.util.PatternsCompat; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; @@ -730,6 +732,7 @@ public class AdapterMessage extends RecyclerView.Adapter() { + @Override + protected String onExecute(Context context, Bundle args) throws Throwable { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean overview_mode = prefs.getBoolean("overview_mode", false); + boolean disable_tracking = prefs.getBoolean("disable_tracking", true); + + long id = args.getLong("id"); + File file = EntityMessage.getFile(context, id); + Document document = JsoupEx.parse(file); + + HtmlHelper.cleanup(document); + HtmlHelper.setViewport(document, overview_mode); + HtmlHelper.embedInlineImages(context, message.id, document, true); + if (disable_tracking) + HtmlHelper.removeTrackingPixels(context, document); + + return document.html(); + } + + @Override + protected void onExecuted(Bundle args, String html) { + Bundle fargs = new Bundle(); + fargs.putString("html", html); + fargs.putString("subject", args.getString("subject")); + + FragmentOpenFull fragment = new FragmentOpenFull(); + fragment.setArguments(fargs); + + FragmentTransaction fragmentTransaction = parentFragment.getParentFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("open"); + fragmentTransaction.commit(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.execute(context, owner, args, "open"); + } + private void onActionUnsubscribe(TupleMessageEx message) { Uri uri = Uri.parse(message.unsubscribe); onOpenLink(uri, context.getString(R.string.title_legend_show_unsubscribe)); @@ -6468,4 +6521,45 @@ public class AdapterMessage extends RecyclerView.Adapter= Build.VERSION_CODES.O) + settings.setSafeBrowsingEnabled(safe_browsing); + + settings.setLoadsImagesAutomatically(true); + settings.setBlockNetworkLoads(false); + settings.setBlockNetworkImage(false); + + wv.loadDataWithBaseURL(null, html, "text/html", StandardCharsets.UTF_8.name(), null); + + return view; + } + } } diff --git a/app/src/main/res/layout/fragment_open_full.xml b/app/src/main/res/layout/fragment_open_full.xml new file mode 100644 index 0000000000..f64b094dfd --- /dev/null +++ b/app/src/main/res/layout/fragment_open_full.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file