aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-12-16 21:55:02 +0100
committersteckbrief <steckbrief@chefmail.de>2015-12-16 21:55:02 +0100
commit4f0061293e1d8e90d2828deeb6b72d8a2c8bd509 (patch)
treea365b75f1d8cd49639b0e6b597aeb48ea82b1773 /src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
parentf49b979cbe96a81c7f20f209bec7e5a1c9f3c24f (diff)
parentc26335f3e366110366eb89025a42875bcb7840a9 (diff)
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
new file mode 100644
index 00000000..9fedada6
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
@@ -0,0 +1,72 @@
+package de.thedevstack.conversationsplus.utils;
+
+import android.graphics.BitmapFactory;
+
+import java.net.URL;
+
+import eu.siacs.conversations.entities.DownloadableFile;
+import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.persistance.FileBackend;
+
+/**
+ * Created by tzur on 15.12.2015.
+ */
+public final class MessageUtil {
+ public static void updateMessageWithImageDetails(Message message, String filePath, long size, int imageWidth, int imageHeight) {
+ message.setRelativeFilePath(filePath);
+ MessageUtil.updateMessageBodyWithImageParams(message, size, imageWidth, imageHeight);
+ }
+
+ public static void updateFileParams(Message message) {
+ updateFileParams(message, null);
+ }
+
+ public static void updateFileParams(Message message, URL url) {
+ DownloadableFile file = FileBackend.getFile(message);
+ int imageWidth = -1;
+ int imageHeight = -1;
+ if (message.getType() == Message.TYPE_IMAGE || file.getMimeType().startsWith("image/")) {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeFile(file.getAbsolutePath(), options);
+ imageHeight = options.outHeight;
+ imageWidth = options.outWidth;
+ }
+
+ MessageUtil.updateMessageBodyWithFileParams(message, url, file.getSize(), imageWidth, imageHeight);
+ }
+
+ private static void updateMessageBodyWithFileParams(Message message, URL url, long fileSize, int imageWidth, int imageHeight) {
+ message.setBody(MessageUtil.getMessageBodyWithImageParams(url, fileSize, imageWidth, imageHeight));
+ }
+
+ private static void updateMessageBodyWithImageParams(Message message, long size, int imageWidth, int imageHeight) {
+ MessageUtil.updateMessageBodyWithImageParams(message, null, size, imageWidth, imageHeight);
+ }
+
+ private static void updateMessageBodyWithImageParams(Message message, URL url, long size, int imageWidth, int imageHeight) {
+ message.setBody(MessageUtil.getMessageBodyWithImageParams(url, size, imageWidth, imageHeight));
+ }
+
+ private static String getMessageBodyWithImageParams(URL url, long size, int imageWidth, int imageHeight) {
+ StringBuilder sb = new StringBuilder();
+ if (null != url) {
+ sb.append(url.toString());
+ sb.append('|');
+ }
+ sb.append(size);
+ if (-1 < imageWidth) {
+ sb.append('|');
+ sb.append(imageWidth);
+ }
+ if (-1 < imageHeight) {
+ sb.append('|');
+ sb.append(imageHeight);
+ }
+ return sb.toString();
+ }
+
+ private MessageUtil() {
+ // Static helper class
+ }
+}