Refactoring

This commit is contained in:
M66B 2021-08-18 19:37:10 +02:00
parent f9e69b0919
commit 636c2b4a8f
5 changed files with 32 additions and 30 deletions

View File

@ -422,10 +422,10 @@ public abstract class DB extends RoomDatabase {
private static void createTriggers(@NonNull SupportSQLiteDatabase db) {
List<String> image = new ArrayList<>();
for (String img : Helper.IMAGE_TYPES)
for (String img : ImageHelper.IMAGE_TYPES)
image.add("'" + img + "'");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
for (String img : Helper.IMAGE_TYPES8)
for (String img : ImageHelper.IMAGE_TYPES8)
image.add("'" + img + "'");
String images = TextUtils.join(",", image);

View File

@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import static androidx.room.ForeignKey.CASCADE;
import android.content.Context;
import android.text.TextUtils;
@ -36,8 +38,6 @@ import java.util.Objects;
import javax.mail.Part;
import static androidx.room.ForeignKey.CASCADE;
@Entity(
tableName = EntityAttachment.TABLE_NAME,
foreignKeys = {
@ -91,7 +91,7 @@ public class EntityAttachment {
}
boolean isImage() {
return Helper.isImage(getMimeType());
return ImageHelper.isImage(getMimeType());
}
boolean isEncryption() {

View File

@ -7007,7 +7007,7 @@ public class FragmentCompose extends FragmentBase {
Long size;
boolean isImage() {
return Helper.isImage(type);
return ImageHelper.isImage(type);
}
}

View File

@ -121,7 +121,6 @@ import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@ -175,21 +174,6 @@ public class Helper {
")+"
);
// https://developer.android.com/guide/topics/media/media-formats#image-formats
static final List<String> IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList(
"image/bmp",
"image/gif",
"image/jpeg",
"image/jpg",
"image/png",
"image/webp"
));
static final List<String> IMAGE_TYPES8 = Collections.unmodifiableList(Arrays.asList(
"image/heic",
"image/heif"
));
private static final ExecutorService executor = getBackgroundExecutor(1, "helper");
static ExecutorService getBackgroundExecutor(int threads, final String name) {
@ -1579,14 +1563,6 @@ public class Helper {
//intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(initial));
}
static boolean isImage(String mimeType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
if (IMAGE_TYPES8.contains(mimeType))
return true;
return IMAGE_TYPES.contains(mimeType);
}
// Cryptography
static String sha256(String data) throws NoSuchAlgorithmException {

View File

@ -75,7 +75,10 @@ import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ExecutorService;
@ -91,6 +94,29 @@ class ImageHelper {
private static final int MAX_PROBE = 64 * 1024; // bytes
private static final int SLOW_CONNECTION = 2 * 1024; // Kbps
// https://developer.android.com/guide/topics/media/media-formats#image-formats
static final List<String> IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList(
"image/bmp",
"image/gif",
"image/jpeg",
"image/jpg",
"image/png",
"image/webp"
));
static final List<String> IMAGE_TYPES8 = Collections.unmodifiableList(Arrays.asList(
"image/heic",
"image/heif"
));
static boolean isImage(String mimeType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
if (IMAGE_TYPES8.contains(mimeType))
return true;
return IMAGE_TYPES.contains(mimeType);
}
static Bitmap generateIdenticon(@NonNull String email, int size, int pixels, Context context) {
byte[] hash = getHash(email);
float h = Math.abs(email.hashCode()) % 360;