mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-01 05:02:21 -05:00
bug fixes and various improvements for file transfer
This commit is contained in:
parent
7a90ca429b
commit
02cbda68a7
@ -251,14 +251,8 @@ public class HttpConnection implements Downloadable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateImageBounds() {
|
private void updateImageBounds() {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
||||||
options.inJustDecodeBounds = true;
|
|
||||||
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
|
||||||
int imageHeight = options.outHeight;
|
|
||||||
int imageWidth = options.outWidth;
|
|
||||||
message.setBody(mUrl.toString() + "|" + file.getSize() + '|'
|
|
||||||
+ imageWidth + '|' + imageHeight);
|
|
||||||
message.setType(Message.TYPE_IMAGE);
|
message.setType(Message.TYPE_IMAGE);
|
||||||
|
mXmppConnectionService.getFileBackend().updateFileParams(message);
|
||||||
mXmppConnectionService.updateMessage(message);
|
mXmppConnectionService.updateMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,6 +433,21 @@ public class FileBackend {
|
|||||||
return Uri.parse("file://" + file.getAbsolutePath());
|
return Uri.parse("file://" + file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateFileParams(Message message) {
|
||||||
|
DownloadableFile file = getFile(message);
|
||||||
|
if (message.getType() == Message.TYPE_IMAGE || file.getMimeType().startsWith("image/")) {
|
||||||
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
|
options.inJustDecodeBounds = true;
|
||||||
|
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
||||||
|
int imageHeight = options.outHeight;
|
||||||
|
int imageWidth = options.outWidth;
|
||||||
|
message.setBody(Long.toString(file.getSize()) + '|' + imageWidth + '|' + imageHeight);
|
||||||
|
} else {
|
||||||
|
message.setBody(Long.toString(file.getSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public class FileCopyException extends Exception {
|
public class FileCopyException extends Exception {
|
||||||
private static final long serialVersionUID = -1010013599132881427L;
|
private static final long serialVersionUID = -1010013599132881427L;
|
||||||
private int resId;
|
private int resId;
|
||||||
|
@ -311,6 +311,7 @@ public class XmppConnectionService extends Service {
|
|||||||
message.setType(Message.TYPE_FILE);
|
message.setType(Message.TYPE_FILE);
|
||||||
message.setStatus(Message.STATUS_OFFERED);
|
message.setStatus(Message.STATUS_OFFERED);
|
||||||
message.setRelativeFilePath(path);
|
message.setRelativeFilePath(path);
|
||||||
|
getFileBackend().updateFileParams(message);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -335,7 +336,6 @@ public class XmppConnectionService extends Service {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
DownloadableFile file = getFileBackend().copyImageToPrivateStorage(message, uri);
|
DownloadableFile file = getFileBackend().copyImageToPrivateStorage(message, uri);
|
||||||
message.setRelativeFilePath(file.getName());
|
|
||||||
if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) {
|
if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) {
|
||||||
getPgpEngine().encrypt(message, callback);
|
getPgpEngine().encrypt(message, callback);
|
||||||
} else {
|
} else {
|
||||||
|
@ -103,10 +103,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||||||
}
|
}
|
||||||
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
|
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
|
||||||
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
|
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
|
||||||
if (message.getType() == Message.TYPE_IMAGE
|
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getDownloadable() != null) {
|
||||||
|| message.getDownloadable() != null) {
|
|
||||||
ImageParams params = message.getImageParams();
|
ImageParams params = message.getImageParams();
|
||||||
if (params.size != 0) {
|
if (params.size > (1.5 * 1024 * 1024)) {
|
||||||
|
filesize = params.size / (1024 * 1024)+ " MB";
|
||||||
|
} else if (params.size > 0) {
|
||||||
filesize = params.size / 1024 + " KB";
|
filesize = params.size / 1024 + " KB";
|
||||||
}
|
}
|
||||||
if (message.getDownloadable() != null && message.getDownloadable().getStatus() == Downloadable.STATUS_FAILED) {
|
if (message.getDownloadable() != null && message.getDownloadable().getStatus() == Downloadable.STATUS_FAILED) {
|
||||||
@ -509,7 +510,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||||||
displayImageMessage(viewHolder, item);
|
displayImageMessage(viewHolder, item);
|
||||||
}
|
}
|
||||||
} else if (item.getType() == Message.TYPE_FILE) {
|
} else if (item.getType() == Message.TYPE_FILE) {
|
||||||
displayOpenableMessage(viewHolder,item);
|
if (item.getImageParams().width > 0) {
|
||||||
|
displayImageMessage(viewHolder,item);
|
||||||
|
} else {
|
||||||
|
displayOpenableMessage(viewHolder, item);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
if (activity.hasPgp()) {
|
if (activity.hasPgp()) {
|
||||||
|
@ -91,13 +91,7 @@ public class JingleConnection implements Downloadable {
|
|||||||
JingleConnection.this.mXmppConnectionService
|
JingleConnection.this.mXmppConnectionService
|
||||||
.getNotificationService().push(message);
|
.getNotificationService().push(message);
|
||||||
}
|
}
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
mXmppConnectionService.getFileBackend().updateFileParams(message);
|
||||||
options.inJustDecodeBounds = true;
|
|
||||||
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
|
||||||
int imageHeight = options.outHeight;
|
|
||||||
int imageWidth = options.outWidth;
|
|
||||||
message.setBody(Long.toString(file.getSize()) + '|'
|
|
||||||
+ imageWidth + '|' + imageHeight);
|
|
||||||
mXmppConnectionService.databaseBackend.createMessage(message);
|
mXmppConnectionService.databaseBackend.createMessage(message);
|
||||||
mXmppConnectionService.markMessage(message,
|
mXmppConnectionService.markMessage(message,
|
||||||
Message.STATUS_RECEIVED);
|
Message.STATUS_RECEIVED);
|
||||||
@ -306,6 +300,9 @@ public class JingleConnection implements Downloadable {
|
|||||||
if (!fileNameElement.getContent().isEmpty()) {
|
if (!fileNameElement.getContent().isEmpty()) {
|
||||||
String parts[] = fileNameElement.getContent().split("/");
|
String parts[] = fileNameElement.getContent().split("/");
|
||||||
suffix = parts[parts.length - 1];
|
suffix = parts[parts.length - 1];
|
||||||
|
if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
|
||||||
|
suffix = suffix.substring(0,suffix.length() - 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
message.setRelativeFilePath(message.getUuid()+"_"+suffix);
|
message.setRelativeFilePath(message.getUuid()+"_"+suffix);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user