aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-20 13:04:27 +0100
committerlookshe <github@lookshe.org>2016-03-20 13:04:27 +0100
commit89082f1c68fb60cf6e7c1d8533696976377fcfde (patch)
tree4b22b8199f32b4fc68814e807d603a5182722941 /src
parenta92ef6f07749b4b18cf3e9eb1722e572c545cabe (diff)
Fixes FS#168 - Not possible to share more than one picture at once
Diffstat (limited to '')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java142
1 files changed, 83 insertions, 59 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
index 8897d8da..231f738c 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
@@ -103,29 +103,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
- ConversationsPlusApplication.executeFileAdding(new Runnable() {
-
- @Override
- public void run() {
- try {
- Bitmap resizedAndRotatedImage = ImageUtil.resizeAndRotateImage(uri);
- DownloadableFile file = FileBackend.compressImageAndCopyToPrivateStorage(message, resizedAndRotatedImage);
- String filePath = file.getAbsolutePath();
- long imageSize = file.getSize();
- int imageWidth = resizedAndRotatedImage.getWidth();
- int imageHeight = resizedAndRotatedImage.getHeight();
- MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
- if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
- xmppConnectionService.getPgpEngine().encrypt(message, callback);
- } else {
- callback.success(message);
- }
- } catch (final UiException e) {
- Logging.e("pictureresizesending", "Error while sending resized picture. " + e.getMessage());
- callback.error(e.getResId(), message);
- }
- }
- });
+ ConversationsPlusApplication.executeFileAdding(new OnYesRunnable(message, uri));
}
@Override
@@ -139,46 +117,92 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
- ConversationsPlusApplication.executeFileAdding(new Runnable() {
- @Override
- public void run() {
- InputStream is = null;
- try {
- is = StreamUtil.openInputStreamFromContentResolver(uri);
- long imageSize = is.available();
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(is, null, options);
- int imageHeight = options.outHeight;
- int imageWidth = options.outWidth;
- String filePath = FileUtils.getPath(uri);
- MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
- if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
- xmppConnectionService.getPgpEngine().encrypt(message, callback);
- } else {
- callback.success(message);
- }
- } catch (FileNotFoundException e) {
- Logging.e("picturesending", "File not found to send not resized. " + e.getMessage());
- callback.error(R.string.error_file_not_found, message);
- } catch (IOException e) {
- Logging.e("picturesending", "Error while sending not resized picture. " + e.getMessage());
- callback.error(R.string.error_io_exception, message);
- } finally {
- if (null != is) {
- try {
- is.close();
- } catch (IOException e) {
- Logging.w("picturesending", "Error while closing stream for sending not resized picture. " + e.getMessage());
- }
- }
- }
- }
- });
+ ConversationsPlusApplication.executeFileAdding(new OnNoRunnable(message, uri));
}
@Override
public void onRemember(UserDecision decision) {
ConversationsPlusPreferences.applyResizePicture(decision);
}
+
+ private abstract class OnClickRunnable implements Runnable {
+
+ protected final Message message;
+ protected final Uri uri;
+
+ public OnClickRunnable(Message message, Uri uri) {
+ this.message = message;
+ this.uri = uri;
+ }
+ }
+
+ private class OnNoRunnable extends OnClickRunnable {
+
+ public OnNoRunnable(Message message, Uri uri) {
+ super(message, uri);
+ }
+
+ @Override
+ public void run() {
+ InputStream is = null;
+ try {
+ is = StreamUtil.openInputStreamFromContentResolver(uri);
+ long imageSize = is.available();
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeStream(is, null, options);
+ int imageHeight = options.outHeight;
+ int imageWidth = options.outWidth;
+ String filePath = FileUtils.getPath(uri);
+ MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ xmppConnectionService.getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success(message);
+ }
+ } catch (FileNotFoundException e) {
+ Logging.e("picturesending", "File not found to send not resized. " + e.getMessage());
+ callback.error(R.string.error_file_not_found, message);
+ } catch (IOException e) {
+ Logging.e("picturesending", "Error while sending not resized picture. " + e.getMessage());
+ callback.error(R.string.error_io_exception, message);
+ } finally {
+ if (null != is) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ Logging.w("picturesending", "Error while closing stream for sending not resized picture. " + e.getMessage());
+ }
+ }
+ }
+ }
+ }
+
+ private class OnYesRunnable extends OnClickRunnable {
+
+ public OnYesRunnable(Message message, Uri uri) {
+ super(message, uri);
+ }
+
+ @Override
+ public void run() {
+ try {
+ Bitmap resizedAndRotatedImage = ImageUtil.resizeAndRotateImage(uri);
+ DownloadableFile file = FileBackend.compressImageAndCopyToPrivateStorage(message, resizedAndRotatedImage);
+ String filePath = file.getAbsolutePath();
+ long imageSize = file.getSize();
+ int imageWidth = resizedAndRotatedImage.getWidth();
+ int imageHeight = resizedAndRotatedImage.getHeight();
+ MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
+ xmppConnectionService.getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success(message);
+ }
+ } catch (final UiException e) {
+ Logging.e("pictureresizesending", "Error while sending resized picture. " + e.getMessage());
+ callback.error(e.getResId(), message);
+ }
+ }
+ }
}