Resize replied images

pull/157/head
M66B 6 years ago
parent 28fd55a639
commit 18f0e29437

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

Loading…
Cancel
Save