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