Added debug option to turn off webp

This commit is contained in:
M66B 2023-09-30 07:37:05 +02:00
parent 8079a14fd3
commit a38ca28ee5
5 changed files with 44 additions and 3 deletions

View File

@ -20,6 +20,7 @@ package eu.faircode.email;
*/ */
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimatedImageDrawable; import android.graphics.drawable.AnimatedImageDrawable;
@ -40,6 +41,7 @@ import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent; import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListUpdateCallback; import androidx.recyclerview.widget.ListUpdateCallback;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -106,6 +108,14 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
String type = args.getString("type"); String type = args.getString("type");
int max = args.getInt("max"); int max = args.getInt("max");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean webp = prefs.getBoolean("webp", true);
if ("image/webp".equalsIgnoreCase(type) && !webp) {
args.putBoolean("nowebp", true);
return null;
}
args.putLong("size", file.length()); args.putLong("size", file.length());
try { try {
@ -142,7 +152,10 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
@Override @Override
protected void onExecuted(Bundle args, Drawable image) { protected void onExecuted(Bundle args, Drawable image) {
if (image == null) if (image == null)
ivImage.setImageResource(R.drawable.twotone_broken_image_24); if (args.getBoolean("nowebp"))
ivImage.setImageResource(R.drawable.twotone_warning_24);
else
ivImage.setImageResource(R.drawable.twotone_broken_image_24);
else else
ivImage.setImageDrawable(image); ivImage.setImageDrawable(image);

View File

@ -240,6 +240,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swNativeDkim; private SwitchCompat swNativeDkim;
private SwitchCompat swNativeArc; private SwitchCompat swNativeArc;
private EditText etNativeArcWhitelist; private EditText etNativeArcWhitelist;
private SwitchCompat swWebp;
private SwitchCompat swEasyCorrect; private SwitchCompat swEasyCorrect;
private SwitchCompat swInfra; private SwitchCompat swInfra;
private SwitchCompat swTldFlags; private SwitchCompat swTldFlags;
@ -311,7 +312,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"max_backoff_power", "logarithmic_backoff", "max_backoff_power", "logarithmic_backoff",
"exact_alarms", "exact_alarms",
"native_dkim", "native_arc", "native_arc_whitelist", "native_dkim", "native_arc", "native_arc_whitelist",
"easy_correct", "infra", "tld_flags", "dup_msgids", "thread_byref", "mdn", "app_chooser", "delete_confirmation", "global_keywords", "test_iab" "webp", "easy_correct", "infra", "tld_flags", "dup_msgids", "thread_byref", "mdn",
"app_chooser", "delete_confirmation", "global_keywords", "test_iab"
}; };
private final static String[] RESET_QUESTIONS = new String[]{ private final static String[] RESET_QUESTIONS = new String[]{
@ -500,6 +502,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swNativeDkim = view.findViewById(R.id.swNativeDkim); swNativeDkim = view.findViewById(R.id.swNativeDkim);
swNativeArc = view.findViewById(R.id.swNativeArc); swNativeArc = view.findViewById(R.id.swNativeArc);
etNativeArcWhitelist = view.findViewById(R.id.etNativeArcWhitelist); etNativeArcWhitelist = view.findViewById(R.id.etNativeArcWhitelist);
swWebp = view.findViewById(R.id.swWebp);
swEasyCorrect = view.findViewById(R.id.swEasyCorrect); swEasyCorrect = view.findViewById(R.id.swEasyCorrect);
swInfra = view.findViewById(R.id.swInfra); swInfra = view.findViewById(R.id.swInfra);
swTldFlags = view.findViewById(R.id.swTldFlags); swTldFlags = view.findViewById(R.id.swTldFlags);
@ -1883,6 +1886,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
swWebp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("webp", checked).apply();
}
});
swEasyCorrect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swEasyCorrect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -2706,6 +2716,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swNativeArc.setChecked(prefs.getBoolean("native_arc", true)); swNativeArc.setChecked(prefs.getBoolean("native_arc", true));
etNativeArcWhitelist.setEnabled(swNativeDkim.isEnabled() && swNativeDkim.isChecked()); etNativeArcWhitelist.setEnabled(swNativeDkim.isEnabled() && swNativeDkim.isChecked());
etNativeArcWhitelist.setText(prefs.getString("native_arc_whitelist", null)); etNativeArcWhitelist.setText(prefs.getString("native_arc_whitelist", null));
swWebp.setChecked(prefs.getBoolean("webp", true));
swEasyCorrect.setChecked(prefs.getBoolean("easy_correct", false)); swEasyCorrect.setChecked(prefs.getBoolean("easy_correct", false));
swInfra.setChecked(prefs.getBoolean("infra", false)); swInfra.setChecked(prefs.getBoolean("infra", false));
swTldFlags.setChecked(prefs.getBoolean("tld_flags", false)); swTldFlags.setChecked(prefs.getBoolean("tld_flags", false));

View File

@ -318,6 +318,7 @@ class ImageHelper {
boolean show, int zoom, final float scale, final TextView view) { boolean show, int zoom, final float scale, final TextView view) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean inline = prefs.getBoolean("inline_images", false); boolean inline = prefs.getBoolean("inline_images", false);
boolean webp = prefs.getBoolean("webp", true);
final int px = Helper.dp2pixels(context, (zoom + 1) * 24); final int px = Helper.dp2pixels(context, (zoom + 1) * 24);
final Resources res = context.getResources(); final Resources res = context.getResources();
@ -345,6 +346,10 @@ class ImageHelper {
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24); Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px); d.setBounds(0, 0, px, px);
return d; return d;
} else if ("image/webp".equalsIgnoreCase(attachment.type) && !webp) {
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_warning_24);
d.setBounds(0, 0, px, px);
return d;
} else if (!attachment.available) { } else if (!attachment.available) {
Log.i("Image not available CID=" + cid); Log.i("Image not available CID=" + cid);
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_photo_library_24); Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_photo_library_24);

View File

@ -2066,6 +2066,17 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNativeArc" /> app:layout_constraintTop_toBottomOf="@id/swNativeArc" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swWebp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_webp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etNativeArcWhitelist"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swEasyCorrect" android:id="@+id/swEasyCorrect"
android:layout_width="0dp" android:layout_width="0dp"
@ -2074,7 +2085,7 @@
android:text="@string/title_advanced_easy_correct" android:text="@string/title_advanced_easy_correct"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etNativeArcWhitelist" app:layout_constraintTop_toBottomOf="@id/swWebp"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

View File

@ -907,6 +907,7 @@
<string name="title_advanced_exact_alarms" translatable="false">Use exact timers</string> <string name="title_advanced_exact_alarms" translatable="false">Use exact timers</string>
<string name="title_advanced_native_dkim" translatable="false">Native DKIM verification</string> <string name="title_advanced_native_dkim" translatable="false">Native DKIM verification</string>
<string name="title_advanced_native_arc" translatable="false">Native ARC verification</string> <string name="title_advanced_native_arc" translatable="false">Native ARC verification</string>
<string name="title_advanced_webp" translatable="false">Webp</string>
<string name="title_advanced_easy_correct" translatable="false">Easy correct</string> <string name="title_advanced_easy_correct" translatable="false">Easy correct</string>
<string name="title_advanced_infra" translatable="false">Show infrastructure</string> <string name="title_advanced_infra" translatable="false">Show infrastructure</string>
<string name="title_advanced_tld_flags" translatable="false">Show TLD flags</string> <string name="title_advanced_tld_flags" translatable="false">Show TLD flags</string>