some mime and pgp fixes for file transfer
This commit is contained in:
parent
16847a30c8
commit
e7a70a46e0
|
@ -3,7 +3,6 @@ package eu.siacs.conversations.crypto;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -24,7 +23,6 @@ import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.ui.UiCallback;
|
import eu.siacs.conversations.ui.UiCallback;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
public class PgpEngine {
|
public class PgpEngine {
|
||||||
|
@ -98,24 +96,7 @@ public class PgpEngine {
|
||||||
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.getImageParams().url;
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
mXmppConnectionService.getFileBackend().updateFileParams(message,url);
|
||||||
options.inJustDecodeBounds = true;
|
|
||||||
BitmapFactory.decodeFile(
|
|
||||||
outputFile.getAbsolutePath(), options);
|
|
||||||
int imageHeight = options.outHeight;
|
|
||||||
int imageWidth = options.outWidth;
|
|
||||||
if (url == null) {
|
|
||||||
message.setBody(Long.toString(outputFile
|
|
||||||
.getSize())
|
|
||||||
+ '|'
|
|
||||||
+ imageWidth
|
|
||||||
+ '|'
|
|
||||||
+ imageHeight);
|
|
||||||
} else {
|
|
||||||
message.setBody(url.toString() + "|"
|
|
||||||
+ Long.toString(outputFile.getSize())
|
|
||||||
+ '|' + imageWidth + '|' + imageHeight);
|
|
||||||
}
|
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
PgpEngine.this.mXmppConnectionService
|
PgpEngine.this.mXmppConnectionService
|
||||||
.updateMessage(message);
|
.updateMessage(message);
|
||||||
|
|
|
@ -55,13 +55,15 @@ public class DownloadableFile extends File {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMimeType() {
|
public String getMimeType() {
|
||||||
if (mime==null) {
|
String path = this.getAbsolutePath();
|
||||||
mime = URLConnection.guessContentTypeFromName(this.getAbsolutePath());
|
String mime = URLConnection.guessContentTypeFromName(path);
|
||||||
if (mime == null) {
|
if (mime != null) {
|
||||||
mime = "";
|
return mime;
|
||||||
}
|
} else if (mime == null && path.endsWith(".webp")) {
|
||||||
|
return "image/webp";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
return mime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpectedSize(long size) {
|
public void setExpectedSize(long size) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class FileBackend {
|
||||||
if (path != null && !path.isEmpty()) {
|
if (path != null && !path.isEmpty()) {
|
||||||
String[] parts = path.split("\\.");
|
String[] parts = path.split("\\.");
|
||||||
extension = "."+parts[parts.length - 1];
|
extension = "."+parts[parts.length - 1];
|
||||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
} else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_TEXT) {
|
||||||
extension = ".webp";
|
extension = ".webp";
|
||||||
} else {
|
} else {
|
||||||
extension = "";
|
extension = "";
|
||||||
|
|
|
@ -15,7 +15,6 @@ import android.os.SystemClock;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.v4.widget.SlidingPaneLayout;
|
import android.support.v4.widget.SlidingPaneLayout;
|
||||||
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -32,7 +31,6 @@ import android.widget.Toast;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
@ -80,7 +78,7 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
|
|
||||||
private ArrayAdapter<Conversation> listAdapter;
|
private ArrayAdapter<Conversation> listAdapter;
|
||||||
|
|
||||||
private Toast prepareImageToast;
|
private Toast prepareFileToast;
|
||||||
|
|
||||||
|
|
||||||
public List<Conversation> getConversationList() {
|
public List<Conversation> getConversationList() {
|
||||||
|
@ -782,15 +780,19 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachFileToConversation(Conversation conversation, Uri uri) {
|
private void attachFileToConversation(Conversation conversation, Uri uri) {
|
||||||
|
prepareFileToast = Toast.makeText(getApplicationContext(),
|
||||||
|
getText(R.string.preparing_file), Toast.LENGTH_LONG);
|
||||||
|
prepareFileToast.show();
|
||||||
xmppConnectionService.attachFileToConversation(conversation,uri, new UiCallback<Message>() {
|
xmppConnectionService.attachFileToConversation(conversation,uri, new UiCallback<Message>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(Message message) {
|
public void success(Message message) {
|
||||||
|
hidePrepareFileToast();
|
||||||
xmppConnectionService.sendMessage(message);
|
xmppConnectionService.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int errorCode, Message message) {
|
public void error(int errorCode, Message message) {
|
||||||
|
displayErrorDialog(errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -801,16 +803,16 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachImageToConversation(Conversation conversation, Uri uri) {
|
private void attachImageToConversation(Conversation conversation, Uri uri) {
|
||||||
prepareImageToast = Toast.makeText(getApplicationContext(),
|
prepareFileToast = Toast.makeText(getApplicationContext(),
|
||||||
getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
||||||
prepareImageToast.show();
|
prepareFileToast.show();
|
||||||
xmppConnectionService.attachImageToConversation(conversation, uri,
|
xmppConnectionService.attachImageToConversation(conversation, uri,
|
||||||
new UiCallback<Message>() {
|
new UiCallback<Message>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi,
|
public void userInputRequried(PendingIntent pi,
|
||||||
Message object) {
|
Message object) {
|
||||||
hidePrepareImageToast();
|
hidePrepareFileToast();
|
||||||
ConversationActivity.this.runIntent(pi,
|
ConversationActivity.this.runIntent(pi,
|
||||||
ConversationActivity.REQUEST_SEND_PGP_IMAGE);
|
ConversationActivity.REQUEST_SEND_PGP_IMAGE);
|
||||||
}
|
}
|
||||||
|
@ -822,19 +824,19 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int error, Message message) {
|
public void error(int error, Message message) {
|
||||||
hidePrepareImageToast();
|
hidePrepareFileToast();
|
||||||
displayErrorDialog(error);
|
displayErrorDialog(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hidePrepareImageToast() {
|
private void hidePrepareFileToast() {
|
||||||
if (prepareImageToast != null) {
|
if (prepareFileToast != null) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
prepareImageToast.cancel();
|
prepareFileToast.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,15 +281,16 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayOpenableMessage(ViewHolder viewHolder,final Message message) {
|
private void displayOpenableMessage(ViewHolder viewHolder,final Message message) {
|
||||||
|
final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
||||||
viewHolder.image.setVisibility(View.GONE);
|
viewHolder.image.setVisibility(View.GONE);
|
||||||
viewHolder.messageBody.setVisibility(View.GONE);
|
viewHolder.messageBody.setVisibility(View.GONE);
|
||||||
viewHolder.download_button.setVisibility(View.VISIBLE);
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
||||||
viewHolder.download_button.setText(activity.getString(R.string.open_file,activity.xmppConnectionService.getFileBackend().getFile(message).getMimeType()));
|
viewHolder.download_button.setText(activity.getString(R.string.open_file,file.getMimeType()));
|
||||||
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
openDonwloadable(message);
|
openDonwloadable(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
viewHolder.download_button.setOnLongClickListener(openContextMenu);
|
viewHolder.download_button.setOnLongClickListener(openContextMenu);
|
||||||
|
@ -506,43 +507,35 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
} else if (d.getStatus() == Downloadable.STATUS_FAILED) {
|
} else if (d.getStatus() == Downloadable.STATUS_FAILED) {
|
||||||
displayInfoMessage(viewHolder, activity.getString(R.string.image_transmission_failed));
|
displayInfoMessage(viewHolder, activity.getString(R.string.image_transmission_failed));
|
||||||
}
|
}
|
||||||
} else if (item.getType() == Message.TYPE_IMAGE) {
|
} else if (item.getType() == Message.TYPE_IMAGE && item.getEncryption() != Message.ENCRYPTION_PGP && item.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
displayImageMessage(viewHolder, item);
|
||||||
displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message));
|
} else if (item.getType() == Message.TYPE_FILE && item.getEncryption() != Message.ENCRYPTION_PGP && item.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
|
||||||
displayDecryptionFailed(viewHolder);
|
|
||||||
} else {
|
|
||||||
displayImageMessage(viewHolder, item);
|
|
||||||
}
|
|
||||||
} else if (item.getType() == Message.TYPE_FILE) {
|
|
||||||
if (item.getImageParams().width > 0) {
|
if (item.getImageParams().width > 0) {
|
||||||
displayImageMessage(viewHolder,item);
|
displayImageMessage(viewHolder,item);
|
||||||
} else {
|
} else {
|
||||||
displayOpenableMessage(viewHolder, item);
|
displayOpenableMessage(viewHolder, item);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
if (activity.hasPgp()) {
|
||||||
if (activity.hasPgp()) {
|
displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message));
|
||||||
displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message));
|
|
||||||
} else {
|
|
||||||
displayInfoMessage(viewHolder,
|
|
||||||
activity.getString(R.string.install_openkeychain));
|
|
||||||
if (viewHolder != null) {
|
|
||||||
viewHolder.message_box
|
|
||||||
.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
activity.showInstallPgpDialog();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
|
||||||
displayDecryptionFailed(viewHolder);
|
|
||||||
} else {
|
} else {
|
||||||
displayTextMessage(viewHolder, item);
|
displayInfoMessage(viewHolder,
|
||||||
|
activity.getString(R.string.install_openkeychain));
|
||||||
|
if (viewHolder != null) {
|
||||||
|
viewHolder.message_box
|
||||||
|
.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
activity.showInstallPgpDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
|
displayDecryptionFailed(viewHolder);
|
||||||
|
} else {
|
||||||
|
displayTextMessage(viewHolder, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayStatus(viewHolder, item);
|
displayStatus(viewHolder, item);
|
||||||
|
@ -560,8 +553,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openDonwloadable(Message message) {
|
public void openDonwloadable(DownloadableFile file) {
|
||||||
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
Log.d(Config.LOGTAG,"file "+file.getAbsolutePath());
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setDataAndType(Uri.fromFile(file), file.getMimeType());
|
intent.setDataAndType(Uri.fromFile(file), file.getMimeType());
|
||||||
getContext().startActivity(intent);
|
getContext().startActivity(intent);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.siacs.conversations.xmpp.jingle;
|
package eu.siacs.conversations.xmpp.jingle;
|
||||||
|
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -97,6 +98,9 @@ public class JingleConnection implements Downloadable {
|
||||||
Message.STATUS_RECEIVED);
|
Message.STATUS_RECEIVED);
|
||||||
} else {
|
} else {
|
||||||
message.setDownloadable(null);
|
message.setDownloadable(null);
|
||||||
|
if (message.getEncryption() != Message.ENCRYPTION_PGP) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Log.d(Config.LOGTAG,
|
Log.d(Config.LOGTAG,
|
||||||
"sucessfully transmitted file:" + file.getAbsolutePath());
|
"sucessfully transmitted file:" + file.getAbsolutePath());
|
||||||
|
@ -922,6 +926,21 @@ public class JingleConnection implements Downloadable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMimeType() {
|
public String getMimeType() {
|
||||||
return this.file.getMimeType();
|
if (this.message.getType() == Message.TYPE_FILE) {
|
||||||
|
String mime = null;
|
||||||
|
String path = this.message.getRelativeFilePath();
|
||||||
|
if (path != null && !this.message.getRelativeFilePath().isEmpty()) {
|
||||||
|
mime = URLConnection.guessContentTypeFromName(this.message.getRelativeFilePath());
|
||||||
|
if (mime!=null) {
|
||||||
|
return mime;
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "image/webp";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,4 +316,5 @@
|
||||||
<string name="download_file">Download %s file</string>
|
<string name="download_file">Download %s file</string>
|
||||||
<string name="open_file">Open %s file</string>
|
<string name="open_file">Open %s file</string>
|
||||||
<string name="sending_file">sending (%1$d%% completed)</string>
|
<string name="sending_file">sending (%1$d%% completed)</string>
|
||||||
|
<string name="preparing_file">Preparing file for transmission</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue