Small improvements

pull/162/head
M66B 6 years ago
parent ad9199df68
commit 90fd7b440f

@ -1461,7 +1461,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (show_full) { if (show_full) {
HtmlHelper.removeViewportLimitations(document); HtmlHelper.removeViewportLimitations(document);
if (inline || show_images) if (inline || show_images)
HtmlHelper.embedImages(context, message.id, document); HtmlHelper.embedInlineImages(context, message.id, document);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean disable_tracking = prefs.getBoolean("disable_tracking", true); boolean disable_tracking = prefs.getBoolean("disable_tracking", true);

@ -4362,7 +4362,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
String html = Helper.readText(file); String html = Helper.readText(file);
Document document = JsoupEx.parse(html); Document document = JsoupEx.parse(html);
HtmlHelper.embedImages(context, id, document); HtmlHelper.embedInlineImages(context, id, document);
Element body = document.body(); Element body = document.body();
if (body != null) { if (body != null) {

@ -371,7 +371,9 @@ public class HtmlHelper {
if (width != 0 || height != 0) { if (width != 0 || height != 0) {
String src = img.attr("src"); String src = img.attr("src");
ImageHelper.AnnotatedSource a = new ImageHelper.AnnotatedSource(src, width, height); String tracking = img.attr("tracking");
ImageHelper.AnnotatedSource a = new ImageHelper.AnnotatedSource(
src, width, height, "true".equals(tracking));
img.attr("src", a.getAnnotated()); img.attr("src", a.getAnnotated());
} }
} }
@ -489,7 +491,7 @@ public class HtmlHelper {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("data:image/png;base64,"); sb.append("data:image/png;base64,");
sb.append(Base64.encodeToString(bos.toByteArray(), Base64.DEFAULT)); sb.append(Base64.encodeToString(bos.toByteArray(), Base64.NO_WRAP));
// Build list of allowed hosts // Build list of allowed hosts
List<String> hosts = new ArrayList<>(); List<String> hosts = new ArrayList<>();
@ -505,6 +507,7 @@ public class HtmlHelper {
// Images // Images
for (Element img : document.select("img")) { for (Element img : document.select("img")) {
img.removeAttr("tracking");
String src = img.attr("src"); String src = img.attr("src");
if (!TextUtils.isEmpty(src) && isTrackingPixel(img)) { if (!TextUtils.isEmpty(src) && isTrackingPixel(img)) {
Uri uri = Uri.parse(img.attr("src")); Uri uri = Uri.parse(img.attr("src"));
@ -514,7 +517,8 @@ public class HtmlHelper {
img.attr("alt", context.getString(R.string.title_legend_tracking_pixel)); img.attr("alt", context.getString(R.string.title_legend_tracking_pixel));
img.attr("height", "24"); img.attr("height", "24");
img.attr("width", "24"); img.attr("width", "24");
img.attr("style", "display: block !important;"); img.attr("style", "display:block !important; width:24px !important; height:24px !important;");
img.attr("tracking", "true");
} }
} }
} }
@ -534,7 +538,7 @@ public class HtmlHelper {
} }
} }
static void embedImages(Context context, long id, Document document) throws IOException { static void embedInlineImages(Context context, long id, Document document) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
for (Element img : document.select("img")) { for (Element img : document.select("img")) {
String src = img.attr("src"); String src = img.attr("src");
@ -552,7 +556,7 @@ public class HtmlHelper {
sb.append("data:"); sb.append("data:");
sb.append(attachment.type); sb.append(attachment.type);
sb.append(";base64,"); sb.append(";base64,");
sb.append(Base64.encodeToString(bytes, Base64.DEFAULT)); sb.append(Base64.encodeToString(bytes, Base64.NO_WRAP));
img.attr("src", sb.toString()); img.attr("src", sb.toString());
} }

@ -234,7 +234,7 @@ class ImageHelper {
} }
// Data URI // Data URI
if (data && (show || inline)) if (data && (show || inline || a.tracking))
try { try {
Drawable d = getDataDrawable(context, a.source); Drawable d = getDataDrawable(context, a.source);
if (view != null) if (view != null)
@ -459,6 +459,7 @@ class ImageHelper {
private String source; private String source;
private int width = 0; private int width = 0;
private int height = 0; private int height = 0;
private boolean tracking = false;
// Encapsulate some ugliness // Encapsulate some ugliness
@ -469,24 +470,25 @@ class ImageHelper {
int pos = source.substring(0, source.length() - 3).lastIndexOf("###"); int pos = source.substring(0, source.length() - 3).lastIndexOf("###");
if (pos > 0) { if (pos > 0) {
int x = source.indexOf("x", pos + 3); int x = source.indexOf("x", pos + 3);
if (x > 0) int s = source.indexOf(":", pos + 3);
if (x > 0 && s > x)
try { try {
this.width = Integer.parseInt(source.substring(pos + 3, x)); this.width = Integer.parseInt(source.substring(pos + 3, x));
this.height = Integer.parseInt(source.substring(x + 1, source.length() - 3)); this.height = Integer.parseInt(source.substring(x + 1, s));
this.tracking = Boolean.parseBoolean(source.substring(s + 1, source.length() - 3));
this.source = source.substring(0, pos); this.source = source.substring(0, pos);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
Log.e(ex); Log.e(ex);
this.width = 0;
this.height = 0;
} }
} }
} }
} }
AnnotatedSource(String source, int width, int height) { AnnotatedSource(String source, int width, int height, boolean tracking) {
this.source = source; this.source = source;
this.width = width; this.width = width;
this.height = height; this.height = height;
this.tracking = tracking;
} }
public String getSource() { public String getSource() {
@ -496,7 +498,7 @@ class ImageHelper {
String getAnnotated() { String getAnnotated() {
return (width == 0 && height == 0 return (width == 0 && height == 0
? source ? source
: source + "###" + width + "x" + height + "###"); : source + "###" + width + "x" + height + ":" + tracking + "###");
} }
} }
} }

Loading…
Cancel
Save