aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-10-13 23:10:10 +0200
committerChristian Schneppe <christian@pix-art.de>2017-10-13 23:10:10 +0200
commit9a625ab0e6afdb706dd73cef932b42e63605aa1b (patch)
treeebb6b114416566e59661016d9d60689bbe8ca0d5 /src/main/java/de/pixart
parentd34d2d05ca371960294356be9735233b898c066a (diff)
add more file information to FileParams (apk file app name; vcard contacts name)
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java17
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java59
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java59
3 files changed, 101 insertions, 34 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index af8c2aafa..c51fa1638 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -3,6 +3,7 @@ package de.pixart.messenger.entities;
import android.content.ContentValues;
import android.database.Cursor;
import android.text.SpannableStringBuilder;
+import android.util.Log;
import com.vdurmont.emoji.EmojiManager;
@@ -740,7 +741,14 @@ public class Message extends AbstractEntity {
fileParams.width = parseInt(parts[1]);
fileParams.height = parseInt(parts[2]);
break;
+ case 6:
+ fileParams.url = parseUrl(parts[0]);
+ fileParams.size = parseLong(parts[1]);
+ fileParams.subject = parseString(parts[5]);
+ break;
+
}
+ Log.d(Config.LOGTAG, "FileParams: " + body);
}
return fileParams;
}
@@ -769,6 +777,14 @@ public class Message extends AbstractEntity {
}
}
+ private static String parseString(String value) {
+ try {
+ return value;
+ } catch (Exception e) {
+ return "";
+ }
+ }
+
public void untie() {
this.mNextMessage = null;
this.mPreviousMessage = null;
@@ -796,6 +812,7 @@ public class Message extends AbstractEntity {
public int width = 0;
public int height = 0;
public int runtime = 0;
+ public String subject = "";
}
public void setFingerprint(String fingerprint) {
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 350dfb7c9..32e6c72ab 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -4,6 +4,8 @@ import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -37,6 +39,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.URL;
import java.security.DigestOutputStream;
@@ -58,6 +61,8 @@ import de.pixart.messenger.utils.FileUtils;
import de.pixart.messenger.utils.FileWriterException;
import de.pixart.messenger.utils.MimeUtils;
import de.pixart.messenger.xmpp.pep.Avatar;
+import ezvcard.Ezvcard;
+import ezvcard.VCard;
public class FileBackend {
@@ -826,6 +831,8 @@ public class FileBackend {
boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/"));
boolean video = mime != null && mime.startsWith("video/");
boolean audio = mime != null && mime.startsWith("audio/");
+ boolean vcard = mime != null && mime.contains("vcard");
+ boolean apk = mime != null && mime.equals("application/vnd.android.package-archive");
final StringBuilder body = new StringBuilder();
if (url != null) {
body.append(url.toString());
@@ -841,6 +848,10 @@ public class FileBackend {
}
} else if (audio) {
body.append("|0|0|").append(getMediaRuntime(file));
+ } else if (vcard) {
+ body.append("|0|0|0|").append(getVCard(file));
+ } else if (apk) {
+ body.append("|0|0|0|").append(getAPK(file, mXmppConnectionService.getApplicationContext()));
}
message.setBody(body.toString());
}
@@ -865,6 +876,54 @@ public class FileBackend {
}
}
+ private String getAPK (File file, Context context) {
+ String APKName;
+ //final Drawable icon;
+ final PackageManager pm = context.getPackageManager();
+ final PackageInfo pi = pm.getPackageArchiveInfo(file.toString(), 0);
+ pi.applicationInfo.sourceDir = file.toString();
+ pi.applicationInfo.publicSourceDir = file.toString();
+ //icon = pi.applicationInfo.loadIcon(pm);
+ final String AppName = (String) pi.applicationInfo.loadLabel(pm);
+ final String AppVersion = (String) pi.versionName;
+ Log.d(Config.LOGTAG, "APK name: " + AppName);
+ APKName = " (" + AppName + " " + AppVersion + ")";
+ try {
+ byte[] data = APKName.getBytes("UTF-8");
+ APKName = Base64.encodeToString(data, Base64.DEFAULT);
+
+ } catch (UnsupportedEncodingException e) {
+ APKName = "";
+ e.printStackTrace();
+ }
+ return APKName;
+ }
+
+ private String getVCard (File file) {
+ VCard VCard = new VCard();
+ String VCardName = "";
+ try {
+ VCard = Ezvcard.parse(file).first();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (VCard != null) {
+ final String version = VCard.getVersion().toString();
+ Log.d(Config.LOGTAG, "VCard version: " + version);
+ final String name = VCard.getFormattedName().getValue();
+ VCardName = " (" + name + ")";
+ }
+ try {
+ byte[] data = VCardName.getBytes("UTF-8");
+ VCardName = Base64.encodeToString(data, Base64.DEFAULT);
+
+ } catch (UnsupportedEncodingException e) {
+ VCardName = "";
+ e.printStackTrace();
+ }
+ return VCardName;
+ }
+
private Dimensions getImageDimensions(File file) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index c3693c24b..ef40825db 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -2,7 +2,6 @@ package de.pixart.messenger.ui.adapter;
import android.content.ActivityNotFoundException;
import android.content.Intent;
-import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
@@ -22,8 +21,8 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.text.util.Linkify;
+import android.util.Base64;
import android.util.DisplayMetrics;
-import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
@@ -43,8 +42,7 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.vdurmont.emoji.EmojiManager;
-import java.io.File;
-import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.List;
@@ -78,8 +76,6 @@ import de.pixart.messenger.utils.GeoHelper;
import de.pixart.messenger.utils.Patterns;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xmpp.mam.MamReference;
-import ezvcard.Ezvcard;
-import ezvcard.VCard;
public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
@@ -562,14 +558,13 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE);
final String mimeType = message.getMimeType();
- final File file = new File(activity.xmppConnectionService.getFileBackend().getFile(message).toString());
if (mimeType != null) {
if (message.getMimeType().contains("pdf")) {
viewHolder.download_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_file_pdf_grey600_48dp, 0, 0, 0);
viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message)));
} else if (message.getMimeType().contains("vcard")) {
try {
- showVCard(message, file, viewHolder);
+ showVCard(message, viewHolder);
} catch (Exception e) {
e.printStackTrace();
}
@@ -578,7 +573,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message)));
} else if (message.getMimeType().equals("application/vnd.android.package-archive")) {
try {
- showAPK(message, file, viewHolder);
+ showAPK(message, viewHolder);
} catch (Exception e) {
e.printStackTrace();
}
@@ -596,35 +591,31 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
});
}
- private void showAPK(final Message message, final File file, ViewHolder viewHolder) {
- final String APKName;
- //final Drawable icon;
- final PackageManager pm = getContext().getPackageManager();
- final PackageInfo pi = pm.getPackageArchiveInfo(file.toString(), 0);
- pi.applicationInfo.sourceDir = file.toString();
- pi.applicationInfo.publicSourceDir = file.toString();
- //icon = pi.applicationInfo.loadIcon(pm);
- final String AppName = (String) pi.applicationInfo.loadLabel(pm);
- final String AppVersion = (String) pi.versionName;
- Log.d(Config.LOGTAG, "APK name: " + AppName);
- APKName = " (" + AppName + " " + AppVersion + ")";
+ private void showAPK(final Message message, ViewHolder viewHolder) {
+ String APKName = "";
+ if (message.getFileParams().subject.length() != 0) {
+ try {
+ byte[] data = Base64.decode(message.getFileParams().subject, Base64.DEFAULT);
+ APKName = new String(data, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ APKName = "";
+ e.printStackTrace();
+ }
+ }
viewHolder.download_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_file_grey600_48dp, 0, 0, 0);
viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message) + APKName));
}
- private void showVCard(final Message message, final File file, ViewHolder viewHolder) {
- VCard vcard = new VCard();
- String VCardName = null;
- try {
- vcard = Ezvcard.parse(file).first();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (vcard != null) {
- final String version = vcard.getVersion().toString();
- Log.d(Config.LOGTAG, "VCard version: " + version);
- final String name = vcard.getFormattedName().getValue();
- VCardName = " (" + name + ")";
+ private void showVCard(final Message message, ViewHolder viewHolder) {
+ String VCardName = "";
+ if (message.getFileParams().subject.length() != 0) {
+ try {
+ byte[] data = Base64.decode(message.getFileParams().subject, Base64.DEFAULT);
+ VCardName = new String(data, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ VCardName = "";
+ e.printStackTrace();
+ }
}
viewHolder.download_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_account_card_details_grey600_48dp, 0, 0, 0);
viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message) + VCardName));