From f93e4ca81341e7ed5379792468fa1610266676df Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 30 Sep 2018 15:20:30 +0000 Subject: [PATCH] Fixed out of memory on viewing large original messages --- .../eu/faircode/email/FragmentMessage.java | 26 ++++++------------- .../eu/faircode/email/FragmentWebView.java | 26 +++++++++++++++---- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 1d43233f..1a713730 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -796,26 +796,16 @@ public class FragmentMessage extends FragmentEx { } private void onMenuShowHtml() { - new SimpleTask() { - @Override - protected String onLoad(Context context, Bundle args) throws Throwable { - return message.read(context); - } - - @Override - protected void onLoaded(Bundle a, String html) { - Bundle args = new Bundle(); - args.putString("html", html); - args.putString("from", MessageHelper.getFormattedAddresses(message.from, true)); + Bundle args = new Bundle(); + args.putLong("id", message.id); + args.putString("from", MessageHelper.getFormattedAddresses(message.from, true)); - FragmentWebView fragment = new FragmentWebView(); - fragment.setArguments(args); + FragmentWebView fragment = new FragmentWebView(); + fragment.setArguments(args); - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("webview"); - fragmentTransaction.commit(); - } - }.load(this, new Bundle()); + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("webview"); + fragmentTransaction.commit(); } private void onMenuUnseen() { diff --git a/app/src/main/java/eu/faircode/email/FragmentWebView.java b/app/src/main/java/eu/faircode/email/FragmentWebView.java index cd758c0c..d7226189 100644 --- a/app/src/main/java/eu/faircode/email/FragmentWebView.java +++ b/app/src/main/java/eu/faircode/email/FragmentWebView.java @@ -19,6 +19,7 @@ package eu.faircode.email; Copyright 2018 by Marcel Bokhorst (M66B) */ +import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; @@ -82,11 +83,26 @@ public class FragmentWebView extends FragmentEx { String url = args.getString("url"); webview.loadUrl(url); setSubtitle(url); - } else if (args.containsKey("html")) { - String html = args.getString("html"); - String from = args.getString("from"); - webview.loadDataWithBaseURL("email://", html, "text/html", "UTF-8", null); - setSubtitle(from); + } else if (args.containsKey("id")) { + new SimpleTask() { + @Override + protected String onLoad(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + return EntityMessage.read(context, id); + } + + @Override + protected void onLoaded(Bundle args, String html) { + String from = args.getString("from"); + webview.loadDataWithBaseURL("email://", html, "text/html", "UTF-8", null); + setSubtitle(from); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getContext(), ex); + } + }.load(this, args); } ((ActivityBase) getActivity()).addBackPressedListener(new ActivityBase.IBackPressedListener() {