diff options
author | lookshe <github@lookshe.org> | 2016-03-20 15:14:42 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-03-20 15:14:42 +0100 |
commit | 50dad467eeb63e767777733e9b280864f16e81f7 (patch) | |
tree | 2b73032bae17a18be9f638d42943d7d2f01baed8 /src/main/java/de/thedevstack/conversationsplus | |
parent | d535496598ef2d294a375b117b20e4a54e1da2d3 (diff) | |
parent | 89082f1c68fb60cf6e7c1d8533696976377fcfde (diff) |
Merge branch 'trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java | 142 |
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 03401e3c..e3dab516 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java @@ -104,29 +104,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 @@ -140,46 +118,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); + } + } + } } |