try to limit full size avatars to under minimum file auto accept size

Daniel Gultsch created

at that resolution it should rarely go over anyway

Change summary

src/main/java/eu/siacs/conversations/Config.java                           |  9 
src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java |  4 
src/main/java/eu/siacs/conversations/xmpp/manager/AvatarManager.java       | 32 
src/main/java/im/conversations/android/xmpp/model/upload/Request.java      |  8 
4 files changed, 33 insertions(+), 20 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/Config.java 🔗

@@ -75,12 +75,9 @@ public final class Config {
     public static final int CONNECT_DISCO_TIMEOUT = 20;
     public static final int MINI_GRACE_PERIOD = 750;
 
-    // media file formats. Homogenous Android or Conversations only deployments can switch to opus
-    // and webp
-    public static final int AVATAR_SIZE = 192;
-    public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.JPEG;
-    public static final int AVATAR_FULL_SIZE = 1024;
-    public static final int AVATAR_CHAR_LIMIT = 9400;
+    public static final int AVATAR_THUMBNAIL_SIZE = 192;
+    public static final int AVATAR_THUMBNAIL_CHAR_LIMIT = 9400;
+    public static final int AVATAR_FULL_SIZE = 1280;
 
     public static final int IMAGE_SIZE = 1920;
     public static final Bitmap.CompressFormat IMAGE_FORMAT = Bitmap.CompressFormat.JPEG;

src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java 🔗

@@ -192,8 +192,8 @@ public class PublishProfilePictureActivity extends XmppActivity
         cropImageOptions.fixAspectRatio = true;
         cropImageOptions.outputCompressFormat = Bitmap.CompressFormat.PNG;
         cropImageOptions.imageSourceIncludeCamera = false;
-        cropImageOptions.minCropResultHeight = Config.AVATAR_SIZE;
-        cropImageOptions.minCropResultWidth = Config.AVATAR_SIZE;
+        cropImageOptions.minCropResultHeight = Config.AVATAR_THUMBNAIL_SIZE;
+        cropImageOptions.minCropResultWidth = Config.AVATAR_THUMBNAIL_SIZE;
         return cropImageOptions;
     }
 

src/main/java/eu/siacs/conversations/xmpp/manager/AvatarManager.java 🔗

@@ -24,6 +24,7 @@ import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import eu.siacs.conversations.AppSettings;
 import eu.siacs.conversations.Config;
+import eu.siacs.conversations.R;
 import eu.siacs.conversations.entities.Contact;
 import eu.siacs.conversations.entities.Conversation;
 import eu.siacs.conversations.entities.Conversational;
@@ -544,19 +545,30 @@ public class AvatarManager extends AbstractManager {
         final ListenableFuture<Info> avatarFuture;
         if (hasAlphaChannel) {
             avatarThumbnailFuture =
-                    resizeAndStoreAvatarAsync(image, Config.AVATAR_SIZE / 2, ImageFormat.PNG);
+                    resizeAndStoreAvatarAsync(
+                            image, Config.AVATAR_THUMBNAIL_SIZE / 2, ImageFormat.PNG);
             avatarFuture =
                     resizeAndStoreAvatarAsync(image, Config.AVATAR_FULL_SIZE / 2, ImageFormat.PNG);
         } else {
+            final int autoAcceptFileSize =
+                    context.getResources().getInteger(R.integer.auto_accept_filesize);
             avatarThumbnailFuture =
                     resizeAndStoreAvatarAsync(
-                            image, Config.AVATAR_SIZE, ImageFormat.JPEG, Config.AVATAR_CHAR_LIMIT);
+                            image,
+                            Config.AVATAR_THUMBNAIL_SIZE,
+                            ImageFormat.JPEG,
+                            Config.AVATAR_THUMBNAIL_CHAR_LIMIT);
             avatarFuture =
-                    resizeAndStoreAvatarAsync(image, Config.AVATAR_FULL_SIZE, ImageFormat.JPEG);
+                    resizeAndStoreAvatarAsync(
+                            image, Config.AVATAR_FULL_SIZE, ImageFormat.JPEG, autoAcceptFileSize);
 
             if (Compatibility.twentyEight() && !PhoneHelper.isEmulator()) {
                 final var avatarHeifFuture =
-                        resizeAndStoreAvatarAsync(image, Config.AVATAR_FULL_SIZE, ImageFormat.HEIF);
+                        resizeAndStoreAvatarAsync(
+                                image,
+                                Config.AVATAR_FULL_SIZE,
+                                ImageFormat.HEIF,
+                                autoAcceptFileSize);
                 final var avatarHeifWithUrlFuture =
                         Futures.transformAsync(
                                 avatarHeifFuture, this::upload, MoreExecutors.directExecutor());
@@ -564,7 +576,11 @@ public class AvatarManager extends AbstractManager {
             }
             if (Compatibility.thirtyFour() && !PhoneHelper.isEmulator()) {
                 final var avatarAvifFuture =
-                        resizeAndStoreAvatarAsync(image, Config.AVATAR_FULL_SIZE, ImageFormat.AVIF);
+                        resizeAndStoreAvatarAsync(
+                                image,
+                                Config.AVATAR_FULL_SIZE,
+                                ImageFormat.AVIF,
+                                autoAcceptFileSize);
                 final var avatarAvifWithUrlFuture =
                         Futures.transformAsync(
                                 avatarAvifFuture, this::upload, MoreExecutors.directExecutor());
@@ -653,13 +669,13 @@ public class AvatarManager extends AbstractManager {
                         hasAlphaChannel -> {
                             if (hasAlphaChannel) {
                                 return resizeAndStoreAvatarAsync(
-                                        image, Config.AVATAR_SIZE / 2, ImageFormat.PNG);
+                                        image, Config.AVATAR_THUMBNAIL_SIZE / 2, ImageFormat.PNG);
                             } else {
                                 return resizeAndStoreAvatarAsync(
                                         image,
-                                        Config.AVATAR_SIZE,
+                                        Config.AVATAR_THUMBNAIL_SIZE,
                                         ImageFormat.JPEG,
-                                        Config.AVATAR_CHAR_LIMIT);
+                                        Config.AVATAR_THUMBNAIL_CHAR_LIMIT);
                             }
                         },
                         MoreExecutors.directExecutor());

src/main/java/im/conversations/android/xmpp/model/upload/Request.java 🔗

@@ -10,15 +10,15 @@ public class Request extends Extension {
         super(Request.class);
     }
 
-    public void setFilename(String filename) {
+    public void setFilename(final String filename) {
         this.setAttribute("filename", filename);
     }
 
-    public void setSize(long size) {
+    public void setSize(final long size) {
         this.setAttribute("size", size);
     }
 
-    public void setContentType(String type) {
-        this.setAttribute("content-ype", type);
+    public void setContentType(final String type) {
+        this.setAttribute("content-type", type);
     }
 }