made httpconnection (download) ready all kind of files
This commit is contained in:
parent
6af97c724c
commit
aca9d8036c
|
@ -98,7 +98,7 @@ public class PgpEngine {
|
||||||
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
|
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
|
||||||
OpenPgpApi.RESULT_CODE_ERROR)) {
|
OpenPgpApi.RESULT_CODE_ERROR)) {
|
||||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||||
URL url = message.getImageParams().url;
|
URL url = message.getFileParams().url;
|
||||||
mXmppConnectionService.getFileBackend().updateFileParams(message,url);
|
mXmppConnectionService.getFileBackend().updateFileParams(message,url);
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
PgpEngine.this.mXmppConnectionService
|
PgpEngine.this.mXmppConnectionService
|
||||||
|
@ -147,7 +147,7 @@ public class PgpEngine {
|
||||||
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||||
String body;
|
String body;
|
||||||
if (message.hasFileOnRemoteHost()) {
|
if (message.hasFileOnRemoteHost()) {
|
||||||
body = message.getImageParams().url.toString();
|
body = message.getFileParams().url.toString();
|
||||||
} else {
|
} else {
|
||||||
body = message.getBody();
|
body = message.getBody();
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,12 +485,12 @@ public class Message extends AbstractEntity {
|
||||||
return body != null && UIHelper.HEARTS.contains(body.trim());
|
return body != null && UIHelper.HEARTS.contains(body.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageParams getImageParams() {
|
public FileParams getFileParams() {
|
||||||
ImageParams params = getLegacyImageParams();
|
FileParams params = getLegacyFileParams();
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
params = new ImageParams();
|
params = new FileParams();
|
||||||
if (this.downloadable != null) {
|
if (this.downloadable != null) {
|
||||||
params.size = this.downloadable.getFileSize();
|
params.size = this.downloadable.getFileSize();
|
||||||
}
|
}
|
||||||
|
@ -498,18 +498,42 @@ public class Message extends AbstractEntity {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
String parts[] = body.split("\\|");
|
String parts[] = body.split("\\|");
|
||||||
if (parts.length == 1) {
|
switch (parts.length) {
|
||||||
|
case 1:
|
||||||
try {
|
try {
|
||||||
params.size = Long.parseLong(parts[0]);
|
params.size = Long.parseLong(parts[0]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
params.origin = parts[0];
|
|
||||||
try {
|
try {
|
||||||
params.url = new URL(parts[0]);
|
params.url = new URL(parts[0]);
|
||||||
} catch (MalformedURLException e1) {
|
} catch (MalformedURLException e1) {
|
||||||
params.url = null;
|
params.url = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (parts.length == 3) {
|
break;
|
||||||
|
case 2:
|
||||||
|
case 4:
|
||||||
|
try {
|
||||||
|
params.url = new URL(parts[0]);
|
||||||
|
} catch (MalformedURLException e1) {
|
||||||
|
params.url = null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
params.size = Long.parseLong(parts[1]);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
params.size = 0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
params.width = Integer.parseInt(parts[2]);
|
||||||
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||||
|
params.width = 0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
params.height = Integer.parseInt(parts[3]);
|
||||||
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||||
|
params.height = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
try {
|
try {
|
||||||
params.size = Long.parseLong(parts[0]);
|
params.size = Long.parseLong(parts[0]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
@ -525,34 +549,13 @@ public class Message extends AbstractEntity {
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
params.height = 0;
|
params.height = 0;
|
||||||
}
|
}
|
||||||
} else if (parts.length == 4) {
|
break;
|
||||||
params.origin = parts[0];
|
|
||||||
try {
|
|
||||||
params.url = new URL(parts[0]);
|
|
||||||
} catch (MalformedURLException e1) {
|
|
||||||
params.url = null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
params.size = Long.parseLong(parts[1]);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
params.size = 0;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
params.width = Integer.parseInt(parts[2]);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
params.width = 0;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
params.height = Integer.parseInt(parts[3]);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
params.height = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageParams getLegacyImageParams() {
|
public FileParams getLegacyFileParams() {
|
||||||
ImageParams params = new ImageParams();
|
FileParams params = new FileParams();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
@ -589,18 +592,17 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasFileOnRemoteHost() {
|
public boolean hasFileOnRemoteHost() {
|
||||||
return isFileOrImage() && getImageParams().url != null;
|
return isFileOrImage() && getFileParams().url != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needsUploading() {
|
public boolean needsUploading() {
|
||||||
return isFileOrImage() && getImageParams().url == null;
|
return isFileOrImage() && getFileParams().url == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ImageParams {
|
public class FileParams {
|
||||||
public URL url;
|
public URL url;
|
||||||
public long size = 0;
|
public long size = 0;
|
||||||
public int width = 0;
|
public int width = 0;
|
||||||
public int height = 0;
|
public int height = 0;
|
||||||
public String origin;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
try {
|
try {
|
||||||
String content;
|
String content;
|
||||||
if (message.hasFileOnRemoteHost()) {
|
if (message.hasFileOnRemoteHost()) {
|
||||||
content = message.getImageParams().url.toString();
|
content = message.getFileParams().url.toString();
|
||||||
} else {
|
} else {
|
||||||
content = message.getBody();
|
content = message.getBody();
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
public MessagePacket generateChat(Message message, boolean addDelay) {
|
public MessagePacket generateChat(Message message, boolean addDelay) {
|
||||||
MessagePacket packet = preparePacket(message, addDelay);
|
MessagePacket packet = preparePacket(message, addDelay);
|
||||||
if (message.hasFileOnRemoteHost()) {
|
if (message.hasFileOnRemoteHost()) {
|
||||||
packet.setBody(message.getImageParams().url.toString());
|
packet.setBody(message.getFileParams().url.toString());
|
||||||
} else {
|
} else {
|
||||||
packet.setBody(message.getBody());
|
packet.setBody(message.getBody());
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,7 +269,7 @@ public class HttpConnection implements Downloadable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateImageBounds() {
|
private void updateImageBounds() {
|
||||||
message.setType(Message.TYPE_IMAGE);
|
message.setType(Message.TYPE_FILE);
|
||||||
mXmppConnectionService.getFileBackend().updateFileParams(message, mUrl);
|
mXmppConnectionService.getFileBackend().updateFileParams(message, mUrl);
|
||||||
mXmppConnectionService.updateMessage(message);
|
mXmppConnectionService.updateMessage(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,11 +154,11 @@ public class HttpUploadConnection implements Downloadable {
|
||||||
int code = connection.getResponseCode();
|
int code = connection.getResponseCode();
|
||||||
if (code == 200) {
|
if (code == 200) {
|
||||||
Log.d(Config.LOGTAG, "finished uploading file");
|
Log.d(Config.LOGTAG, "finished uploading file");
|
||||||
Message.ImageParams params = message.getImageParams();
|
Message.FileParams params = message.getFileParams();
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
mGetUrl = new URL(mGetUrl.toString() + "#" + CryptoHelper.bytesToHex(key));
|
mGetUrl = new URL(mGetUrl.toString() + "#" + CryptoHelper.bytesToHex(key));
|
||||||
}
|
}
|
||||||
message.setBody(mGetUrl.toString()+"|"+String.valueOf(params.size)+"|"+String.valueOf(params.width)+"|"+String.valueOf(params.height));
|
mXmppConnectionService.getFileBackend().updateFileParams(message, mGetUrl);
|
||||||
message.setDownloadable(null);
|
message.setDownloadable(null);
|
||||||
message.setCounterpart(message.getConversation().getJid().toBareJid());
|
message.setCounterpart(message.getConversation().getJid().toBareJid());
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
|
|
|
@ -499,7 +499,11 @@ public class FileBackend {
|
||||||
message.setBody(url.toString()+"|"+Long.toString(file.getSize()) + '|' + imageWidth + '|' + imageHeight);
|
message.setBody(url.toString()+"|"+Long.toString(file.getSize()) + '|' + imageWidth + '|' + imageHeight);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (url != null) {
|
||||||
message.setBody(url.toString()+"|"+Long.toString(file.getSize()));
|
message.setBody(url.toString()+"|"+Long.toString(file.getSize()));
|
||||||
|
} else {
|
||||||
|
message.setBody(Long.toString(file.getSize()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,7 +543,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||||
url = message.getBody();
|
url = message.getBody();
|
||||||
} else {
|
} else {
|
||||||
resId = R.string.image_url;
|
resId = R.string.image_url;
|
||||||
url = message.getImageParams().url.toString();
|
url = message.getFileParams().url.toString();
|
||||||
}
|
}
|
||||||
if (activity.copyTextToClipboard(url, resId)) {
|
if (activity.copyTextToClipboard(url, resId)) {
|
||||||
Toast.makeText(activity, R.string.url_copied_to_clipboard,
|
Toast.makeText(activity, R.string.url_copied_to_clipboard,
|
||||||
|
|
|
@ -3,7 +3,6 @@ package eu.siacs.conversations.ui.adapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
@ -69,7 +68,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|
||||||
convName.setTypeface(null, Typeface.NORMAL);
|
convName.setTypeface(null, Typeface.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getImageParams().width > 0
|
if (message.getFileParams().width > 0
|
||||||
&& (message.getDownloadable() == null
|
&& (message.getDownloadable() == null
|
||||||
|| message.getDownloadable().getStatus() != Downloadable.STATUS_DELETED)) {
|
|| message.getDownloadable().getStatus() != Downloadable.STATUS_DELETED)) {
|
||||||
mLastMessage.setVisibility(View.GONE);
|
mLastMessage.setVisibility(View.GONE);
|
||||||
|
|
|
@ -32,7 +32,7 @@ import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Downloadable;
|
import eu.siacs.conversations.entities.Downloadable;
|
||||||
import eu.siacs.conversations.entities.DownloadableFile;
|
import eu.siacs.conversations.entities.DownloadableFile;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.entities.Message.ImageParams;
|
import eu.siacs.conversations.entities.Message.FileParams;
|
||||||
import eu.siacs.conversations.ui.ConversationActivity;
|
import eu.siacs.conversations.ui.ConversationActivity;
|
||||||
import eu.siacs.conversations.utils.GeoHelper;
|
import eu.siacs.conversations.utils.GeoHelper;
|
||||||
import eu.siacs.conversations.utils.UIHelper;
|
import eu.siacs.conversations.utils.UIHelper;
|
||||||
|
@ -100,7 +100,7 @@ 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 || message.getType() == Message.TYPE_FILE || message.getDownloadable() != null) {
|
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getDownloadable() != null) {
|
||||||
ImageParams params = message.getImageParams();
|
FileParams params = message.getFileParams();
|
||||||
if (params.size > (1.5 * 1024 * 1024)) {
|
if (params.size > (1.5 * 1024 * 1024)) {
|
||||||
filesize = params.size / (1024 * 1024)+ " MiB";
|
filesize = params.size / (1024 * 1024)+ " MiB";
|
||||||
} else if (params.size > 0) {
|
} else if (params.size > 0) {
|
||||||
|
@ -339,7 +339,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
}
|
}
|
||||||
viewHolder.messageBody.setVisibility(View.GONE);
|
viewHolder.messageBody.setVisibility(View.GONE);
|
||||||
viewHolder.image.setVisibility(View.VISIBLE);
|
viewHolder.image.setVisibility(View.VISIBLE);
|
||||||
ImageParams params = message.getImageParams();
|
FileParams params = message.getFileParams();
|
||||||
double target = metrics.density * 288;
|
double target = metrics.density * 288;
|
||||||
int scalledW;
|
int scalledW;
|
||||||
int scalledH;
|
int scalledH;
|
||||||
|
@ -494,7 +494,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
} else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
} else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
displayImageMessage(viewHolder, message);
|
displayImageMessage(viewHolder, message);
|
||||||
} else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
} else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
if (message.getImageParams().width > 0) {
|
if (message.getFileParams().width > 0) {
|
||||||
displayImageMessage(viewHolder,message);
|
displayImageMessage(viewHolder,message);
|
||||||
} else {
|
} else {
|
||||||
displayOpenableMessage(viewHolder, message);
|
displayOpenableMessage(viewHolder, message);
|
||||||
|
|
Loading…
Reference in New Issue