From 9d87fe8f6cdfc3f698cfbe03e9e78abf92c7f118 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 6 Feb 2022 11:03:36 +0100 Subject: [PATCH] Added view original signature --- CHANGELOG.md | 1 + app/src/main/assets/CHANGELOG.md | 1 + .../eu/faircode/email/ActivitySignature.java | 18 ++++ .../eu/faircode/email/AdapterMessage.java | 66 ++---------- .../email/FragmentDialogOpenFull.java | 102 ++++++++++++++++++ .../main/res/layout/activity_signature.xml | 14 +++ metadata/en-US/changelogs/1832.txt | 1 + 7 files changed, 143 insertions(+), 60 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/FragmentDialogOpenFull.java diff --git a/CHANGELOG.md b/CHANGELOG.md index bd2c56f0c7..1bfca540ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Next version * Added option to disable divider lines for tabular layout +* Added view original signature ### 1.1832 - 2022-02-05 diff --git a/app/src/main/assets/CHANGELOG.md b/app/src/main/assets/CHANGELOG.md index bd2c56f0c7..1bfca540ac 100644 --- a/app/src/main/assets/CHANGELOG.md +++ b/app/src/main/assets/CHANGELOG.md @@ -7,6 +7,7 @@ ### Next version * Added option to disable divider lines for tabular layout +* Added view original signature ### 1.1832 - 2022-02-05 diff --git a/app/src/main/java/eu/faircode/email/ActivitySignature.java b/app/src/main/java/eu/faircode/email/ActivitySignature.java index d66cf841de..8144ee7312 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySignature.java +++ b/app/src/main/java/eu/faircode/email/ActivitySignature.java @@ -43,6 +43,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; +import android.widget.ImageButton; import android.widget.TextView; import androidx.annotation.NonNull; @@ -61,6 +62,7 @@ public class ActivitySignature extends ActivityBase { private ViewGroup view; private TextView tvHtmlRemark; private EditTextCompose etText; + private ImageButton ibFull; private BottomNavigationView style_bar; private BottomNavigationView bottom_navigation; @@ -84,6 +86,7 @@ public class ActivitySignature extends ActivityBase { tvHtmlRemark = findViewById(R.id.tvHtmlRemark); etText = findViewById(R.id.etText); + ibFull = findViewById(R.id.ibFull); style_bar = findViewById(R.id.style_bar); bottom_navigation = findViewById(R.id.bottom_navigation); @@ -114,6 +117,21 @@ public class ActivitySignature extends ActivityBase { } }); + ibFull.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Bundle args = new Bundle(); + args.putString("html", getHtml()); + args.putBoolean("overview_mode", false); + args.putBoolean("safe_browsing", false); + args.putBoolean("force_light", true); + + FragmentDialogOpenFull dialog = new FragmentDialogOpenFull(); + dialog.setArguments(args); + dialog.show(getSupportFragmentManager(), "signature"); + } + }); + style_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 09d2c55473..f71b7efb52 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -4796,8 +4796,14 @@ public class AdapterMessage extends RecyclerView.Adapter= Build.VERSION_CODES.O) - settings.setSafeBrowsingEnabled(safe_browsing); - - boolean dark = (Helper.isDarkTheme(context) && !force_light); - if (WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK)) - WebSettingsCompat.setForceDark(settings, dark ? FORCE_DARK_ON : FORCE_DARK_OFF); - - settings.setLoadsImagesAutomatically(true); - settings.setBlockNetworkLoads(false); - settings.setBlockNetworkImage(false); - - wv.loadDataWithBaseURL(null, html, "text/html", StandardCharsets.UTF_8.name(), null); - - return view; - } - } - public static class FragmentDialogPrint extends FragmentDialogBase { @NonNull @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogOpenFull.java b/app/src/main/java/eu/faircode/email/FragmentDialogOpenFull.java new file mode 100644 index 0000000000..84ea46262f --- /dev/null +++ b/app/src/main/java/eu/faircode/email/FragmentDialogOpenFull.java @@ -0,0 +1,102 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2022 by Marcel Bokhorst (M66B) +*/ + +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; +import static androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF; +import static androidx.webkit.WebSettingsCompat.FORCE_DARK_ON; + +import android.app.Dialog; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Build; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebSettings; +import android.webkit.WebView; + +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import androidx.preference.PreferenceManager; +import androidx.webkit.WebSettingsCompat; +import androidx.webkit.WebViewFeature; + +import java.nio.charset.StandardCharsets; + +public class FragmentDialogOpenFull extends FragmentDialogBase { + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setStyle(DialogFragment.STYLE_NORMAL, R.style.fullScreenDialog); + } + + @Override + public void onStart() { + super.onStart(); + Dialog dialog = getDialog(); + if (dialog != null) + dialog.getWindow().setLayout(MATCH_PARENT, MATCH_PARENT); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + Bundle args = getArguments(); + String html = args.getString("html"); + boolean overview_mode = args.getBoolean("overview_mode"); + boolean safe_browsing = args.getBoolean("safe_browsing"); + boolean force_light = args.getBoolean("force_light"); + + final Context context = getContext(); + + View view = inflater.inflate(R.layout.fragment_open_full, container, false); + WebView wv = view.findViewById(R.id.wv); + + WebSettings settings = wv.getSettings(); + settings.setUserAgentString(WebViewEx.getUserAgent(context, wv)); + settings.setUseWideViewPort(true); + settings.setLoadWithOverviewMode(overview_mode); + + settings.setBuiltInZoomControls(true); + settings.setDisplayZoomControls(false); + + settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); + + settings.setAllowFileAccess(false); + settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + settings.setSafeBrowsingEnabled(safe_browsing); + + boolean dark = (Helper.isDarkTheme(context) && !force_light); + if (WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK)) + WebSettingsCompat.setForceDark(settings, dark ? FORCE_DARK_ON : FORCE_DARK_OFF); + + 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/activity_signature.xml b/app/src/main/res/layout/activity_signature.xml index 863333306f..d79addfaf3 100644 --- a/app/src/main/res/layout/activity_signature.xml +++ b/app/src/main/res/layout/activity_signature.xml @@ -39,6 +39,20 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvHtmlRemark" /> + +