Added basic AMP support

pull/194/merge
M66B 4 years ago
parent e9873e1f6a
commit 472b3c5408

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
@ -34,6 +35,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
@ -293,8 +295,64 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
}
private void onShare(EntityAttachment attachment) {
String title = (attachment.name == null ? attachment.cid : attachment.name);
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);
if ("text/x-amp-html".equals(attachment.type)) {
new AlertDialog.Builder(context)
.setIcon(R.drawable.twotone_bolt_24)
.setTitle(R.string.title_ask_show_amp)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onAmp(attachment);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
} else {
String title = (attachment.name == null ? attachment.cid : attachment.name);
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);
}
}
private void onAmp(EntityAttachment attachment) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
new SimpleTask<String>() {
@Override
protected String onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityAttachment attachment = db.attachment().getAttachment(id);
if (attachment == null)
return null;
File file = attachment.getFile(context);
return Helper.readText(file);
}
@Override
protected void onExecuted(Bundle args, String html) {
if (html == null)
return;
Bundle hargs = new Bundle();
hargs.putString("html", html);
hargs.putBoolean("overview_mode", true);
hargs.putBoolean("safe_browsing", true);
hargs.putBoolean("force_light", true);
hargs.putBoolean("javascript", true);
FragmentDialogOpenFull dialog = new FragmentDialogOpenFull();
dialog.setArguments(hargs);
dialog.show(parentFragment.getParentFragmentManager(), "amp");
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "attachment:amp");
}
private void onDownload(EntityAttachment attachment) {

@ -3025,6 +3025,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
List<EntityAttachment> a = new ArrayList<>();
for (EntityAttachment attachment : attachments) {
boolean inline = (attachment.isEncryption() ||
"text/x-amp-html".equals(attachment.type) ||
(attachment.isInline() && attachment.isImage()));
if (inline && attachment.available)
has_inline = true;

@ -62,6 +62,7 @@ public class FragmentDialogOpenFull extends FragmentDialogBase {
boolean overview_mode = args.getBoolean("overview_mode");
boolean safe_browsing = args.getBoolean("safe_browsing");
boolean force_light = args.getBoolean("force_light");
boolean javascript = args.getBoolean("javascript");
final Context context = getContext();
@ -89,6 +90,8 @@ public class FragmentDialogOpenFull extends FragmentDialogBase {
if (WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK))
WebSettingsCompat.setForceDark(settings, dark ? FORCE_DARK_ON : FORCE_DARK_OFF);
settings.setJavaScriptEnabled(javascript);
settings.setLoadsImagesAutomatically(true);
settings.setBlockNetworkLoads(false);
settings.setBlockNetworkImage(false);

@ -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="M11,21h-1l1,-7H7.5c-0.88,0 -0.33,-0.75 -0.31,-0.78C8.48,10.94 10.42,7.54 13.01,3h1l-1,7h3.51c0.4,0 0.62,0.19 0.4,0.66C12.97,17.55 11,21 11,21z"/>
</vector>

@ -1211,6 +1211,7 @@
<string name="title_ask_show_html_images">Always show images on showing original messages</string>
<string name="title_ask_show_image">Showing images can leak privacy sensitive information</string>
<string name="title_ask_show_image_hint">Images recognized as tracking images will not be shown</string>
<string name="title_ask_show_amp">Show AMP variant of the message?</string>
<string name="title_ask_delete_local">Delete local messages? Messages will remain on the remote server.</string>
<string name="title_ask_help">Help improve FairEmail</string>
<string name="title_ask_reporting">Send error reports?</string>

Loading…
Cancel
Save