1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Resize replied images

This commit is contained in:
M66B 2019-07-06 13:46:38 +02:00
parent 28fd55a639
commit 18f0e29437

View file

@ -1839,6 +1839,8 @@ public class FragmentCompose extends FragmentBase {
}
}
db.attachment().setDownloaded(attachment.id, size);
if ("eu.faircode.email".equals(uri.getAuthority())) {
// content://eu.faircode.email/temporary/nnn.jpg
File tmp = new File(context.getFilesDir(), uri.getPath());
@ -1848,9 +1850,24 @@ public class FragmentCompose extends FragmentBase {
} else
Log.i("Authority=" + uri.getAuthority());
resizeAttachment(context, attachment);
} catch (IOException ex) {
// Reset progress on failure
Log.e(ex);
db.attachment().setError(attachment.id, Helper.formatThrowable(ex, false));
throw ex;
}
return attachment;
}
private static void resizeAttachment(Context context, EntityAttachment attachment) throws IOException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean autoresize = prefs.getBoolean("autoresize", true);
File file = attachment.getFile(context);
if (autoresize && file.exists() /* upload cancelled */ &&
("image/jpeg".equals(attachment.type) || "image/png".equals(attachment.type))) {
BitmapFactory.Options options = new BitmapFactory.Options();
@ -1890,21 +1907,11 @@ public class FragmentCompose extends FragmentBase {
scaled.recycle();
}
size = file.length();
DB db = DB.getInstance(context);
db.attachment().setDownloaded(attachment.id, file.length());
}
}
}
db.attachment().setDownloaded(attachment.id, size);
} catch (IOException ex) {
// Reset progress on failure
Log.e(ex);
db.attachment().setError(attachment.id, Helper.formatThrowable(ex, false));
throw ex;
}
return attachment;
}
private SimpleTask<EntityMessage> draftLoader = new SimpleTask<EntityMessage>() {
@ -2177,6 +2184,9 @@ public class FragmentCompose extends FragmentBase {
File target = attachment.getFile(context);
Helper.copy(source, target);
if (!"forward".equals(action))
resizeAttachment(context, attachment);
} else
args.putBoolean("incomplete", true);
}