mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-26 01:09:13 -05:00
added download button for images not accepted automatically
This commit is contained in:
parent
aa5f775fc7
commit
9a8e55acd1
@ -1,5 +1,6 @@
|
|||||||
package eu.siacs.conversations.entities;
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.xmpp.jingle.JingleConnection;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ public class Message extends AbstractEntity {
|
|||||||
|
|
||||||
public static final String TABLENAME = "messages";
|
public static final String TABLENAME = "messages";
|
||||||
|
|
||||||
|
public static final int STATUS_RECEIVED_OFFER = -2;
|
||||||
public static final int STATUS_RECIEVING = -1;
|
public static final int STATUS_RECIEVING = -1;
|
||||||
public static final int STATUS_RECIEVED = 0;
|
public static final int STATUS_RECIEVED = 0;
|
||||||
public static final int STATUS_UNSEND = 1;
|
public static final int STATUS_UNSEND = 1;
|
||||||
@ -16,6 +18,7 @@ public class Message extends AbstractEntity {
|
|||||||
public static final int STATUS_SEND_FAILED = 3;
|
public static final int STATUS_SEND_FAILED = 3;
|
||||||
public static final int STATUS_SEND_REJECTED = 4;
|
public static final int STATUS_SEND_REJECTED = 4;
|
||||||
public static final int STATUS_PREPARING = 5;
|
public static final int STATUS_PREPARING = 5;
|
||||||
|
public static final int STATUS_OFFERED = 6;
|
||||||
|
|
||||||
public static final int ENCRYPTION_NONE = 0;
|
public static final int ENCRYPTION_NONE = 0;
|
||||||
public static final int ENCRYPTION_PGP = 1;
|
public static final int ENCRYPTION_PGP = 1;
|
||||||
@ -45,6 +48,8 @@ public class Message extends AbstractEntity {
|
|||||||
|
|
||||||
protected transient Conversation conversation = null;
|
protected transient Conversation conversation = null;
|
||||||
|
|
||||||
|
protected transient JingleConnection jingleConnection = null;
|
||||||
|
|
||||||
public Message(Conversation conversation, String body, int encryption) {
|
public Message(Conversation conversation, String body, int encryption) {
|
||||||
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
||||||
conversation.getContactJid(), body, System.currentTimeMillis(), encryption,
|
conversation.getContactJid(), body, System.currentTimeMillis(), encryption,
|
||||||
@ -173,4 +178,12 @@ public class Message extends AbstractEntity {
|
|||||||
public void setPresence(String presence) {
|
public void setPresence(String presence) {
|
||||||
this.counterpart = this.counterpart.split("/")[0] + "/" + presence;
|
this.counterpart = this.counterpart.split("/")[0] + "/" + presence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setJingleConnection(JingleConnection connection) {
|
||||||
|
this.jingleConnection = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JingleConnection getJingleConnection() {
|
||||||
|
return this.jingleConnection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,8 +423,7 @@ public class XmppConnectionService extends Service {
|
|||||||
convChangedListener.onConversationListChanged();
|
convChangedListener.onConversationListChanged();
|
||||||
}
|
}
|
||||||
getFileBackend().copyImageToPrivateStorage(message, uri);
|
getFileBackend().copyImageToPrivateStorage(message, uri);
|
||||||
message.setStatus(Message.STATUS_UNSEND);
|
message.setStatus(Message.STATUS_OFFERED);
|
||||||
databaseBackend.createMessage(message);
|
|
||||||
if (convChangedListener!=null) {
|
if (convChangedListener!=null) {
|
||||||
convChangedListener.onConversationListChanged();
|
convChangedListener.onConversationListChanged();
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import eu.siacs.conversations.entities.MucOptions;
|
|||||||
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.utils.UIHelper;
|
import eu.siacs.conversations.utils.UIHelper;
|
||||||
|
import eu.siacs.conversations.xmpp.jingle.JingleConnection;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -42,6 +43,7 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
@ -217,6 +219,8 @@ public class ConversationFragment extends Fragment {
|
|||||||
viewHolder.contact_picture = (ImageView) view
|
viewHolder.contact_picture = (ImageView) view
|
||||||
.findViewById(R.id.message_photo);
|
.findViewById(R.id.message_photo);
|
||||||
|
|
||||||
|
viewHolder.download_button = (Button) view.findViewById(R.id.download_button);
|
||||||
|
|
||||||
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
||||||
|
|
||||||
viewHolder.contact_picture.setImageBitmap(mBitmapCache
|
viewHolder.contact_picture.setImageBitmap(mBitmapCache
|
||||||
@ -265,19 +269,33 @@ public class ConversationFragment extends Fragment {
|
|||||||
|
|
||||||
|
|
||||||
if (item.getType() == Message.TYPE_IMAGE) {
|
if (item.getType() == Message.TYPE_IMAGE) {
|
||||||
if (item.getStatus() == Message.STATUS_PREPARING) {
|
if ((item.getStatus() == Message.STATUS_PREPARING)||(item.getStatus() == Message.STATUS_RECIEVING)) {
|
||||||
viewHolder.image.setVisibility(View.GONE);
|
viewHolder.image.setVisibility(View.GONE);
|
||||||
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
||||||
|
if (item.getStatus() == Message.STATUS_PREPARING) {
|
||||||
viewHolder.messageBody.setText(getString(R.string.preparing_image));
|
viewHolder.messageBody.setText(getString(R.string.preparing_image));
|
||||||
|
} else if (item.getStatus() == Message.STATUS_RECIEVING) {
|
||||||
|
viewHolder.download_button.setVisibility(View.GONE);
|
||||||
|
viewHolder.messageBody.setText(getString(R.string.receiving_image));
|
||||||
|
}
|
||||||
viewHolder.messageBody.setTextColor(0xff33B5E5);
|
viewHolder.messageBody.setTextColor(0xff33B5E5);
|
||||||
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC);
|
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC);
|
||||||
} else if (item.getStatus() == Message.STATUS_RECIEVING) {
|
} else if (item.getStatus() == Message.STATUS_RECEIVED_OFFER) {
|
||||||
viewHolder.image.setVisibility(View.GONE);
|
viewHolder.image.setVisibility(View.GONE);
|
||||||
viewHolder.messageBody.setVisibility(View.GONE);
|
viewHolder.messageBody.setVisibility(View.GONE);
|
||||||
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
||||||
viewHolder.messageBody.setText(getString(R.string.receiving_image));
|
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
||||||
viewHolder.messageBody.setTextColor(0xff33B5E5);
|
|
||||||
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC);
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
JingleConnection connection = item.getJingleConnection();
|
||||||
|
if (connection!=null) {
|
||||||
|
connection.accept();
|
||||||
|
} else {
|
||||||
|
Log.d("xmppService","attached jingle connection was null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Bitmap thumbnail = activity.xmppConnectionService.getFileBackend().getThumbnailFromMessage(item,(int) (metrics.density * 288));
|
Bitmap thumbnail = activity.xmppConnectionService.getFileBackend().getThumbnailFromMessage(item,(int) (metrics.density * 288));
|
||||||
@ -331,6 +349,11 @@ public class ConversationFragment extends Fragment {
|
|||||||
viewHolder.time.setTextColor(0xFF8e8e8e);
|
viewHolder.time.setTextColor(0xFF8e8e8e);
|
||||||
viewHolder.time.setText("sending\u2026");
|
viewHolder.time.setText("sending\u2026");
|
||||||
break;
|
break;
|
||||||
|
case Message.STATUS_OFFERED:
|
||||||
|
viewHolder.time.setTypeface(null, Typeface.ITALIC);
|
||||||
|
viewHolder.time.setTextColor(0xFF8e8e8e);
|
||||||
|
viewHolder.time.setText("offering\u2026");
|
||||||
|
break;
|
||||||
case Message.STATUS_SEND_FAILED:
|
case Message.STATUS_SEND_FAILED:
|
||||||
viewHolder.time.setText(getString(R.string.send_failed) + " \u00B7 " + UIHelper.readableTimeDifference(item
|
viewHolder.time.setText(getString(R.string.send_failed) + " \u00B7 " + UIHelper.readableTimeDifference(item
|
||||||
.getTimeSent()));
|
.getTimeSent()));
|
||||||
@ -636,6 +659,7 @@ public class ConversationFragment extends Fragment {
|
|||||||
|
|
||||||
private static class ViewHolder {
|
private static class ViewHolder {
|
||||||
|
|
||||||
|
protected Button download_button;
|
||||||
protected ImageView image;
|
protected ImageView image;
|
||||||
protected ImageView indicator;
|
protected ImageView indicator;
|
||||||
protected TextView time;
|
protected TextView time;
|
||||||
|
@ -50,6 +50,8 @@ public class JingleConnection {
|
|||||||
private boolean receivedCandidate = false;
|
private boolean receivedCandidate = false;
|
||||||
private boolean sentCandidate = false;
|
private boolean sentCandidate = false;
|
||||||
|
|
||||||
|
private boolean acceptedAutomatically = false;
|
||||||
|
|
||||||
private JingleTransport transport = null;
|
private JingleTransport transport = null;
|
||||||
|
|
||||||
private OnIqPacketReceived responseListener = new OnIqPacketReceived() {
|
private OnIqPacketReceived responseListener = new OnIqPacketReceived() {
|
||||||
@ -69,8 +71,12 @@ public class JingleConnection {
|
|||||||
public void onFileTransmitted(JingleFile file) {
|
public void onFileTransmitted(JingleFile file) {
|
||||||
if (responder.equals(account.getFullJid())) {
|
if (responder.equals(account.getFullJid())) {
|
||||||
sendSuccess();
|
sendSuccess();
|
||||||
|
if (acceptedAutomatically) {
|
||||||
|
message.markUnread();
|
||||||
|
}
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_RECIEVED);
|
mXmppConnectionService.markMessage(message, Message.STATUS_RECIEVED);
|
||||||
}
|
}
|
||||||
|
mXmppConnectionService.databaseBackend.createMessage(message);
|
||||||
Log.d("xmppService","sucessfully transmitted file. sha1:"+file.getSha1Sum());
|
Log.d("xmppService","sucessfully transmitted file. sha1:"+file.getSha1Sum());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -126,7 +132,7 @@ public class JingleConnection {
|
|||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
} else if (packet.isAction("session-accept")) {
|
} else if (packet.isAction("session-accept")) {
|
||||||
accept(packet);
|
receiveAccept(packet);
|
||||||
} else if (packet.isAction("transport-info")) {
|
} else if (packet.isAction("transport-info")) {
|
||||||
receiveTransportInfo(packet);
|
receiveTransportInfo(packet);
|
||||||
} else if (packet.isAction("transport-replace")) {
|
} else if (packet.isAction("transport-replace")) {
|
||||||
@ -189,7 +195,8 @@ public class JingleConnection {
|
|||||||
Conversation conversation = this.mXmppConnectionService.findOrCreateConversation(account, packet.getFrom().split("/")[0], false);
|
Conversation conversation = this.mXmppConnectionService.findOrCreateConversation(account, packet.getFrom().split("/")[0], false);
|
||||||
this.message = new Message(conversation, "receiving image file", Message.ENCRYPTION_NONE);
|
this.message = new Message(conversation, "receiving image file", Message.ENCRYPTION_NONE);
|
||||||
this.message.setType(Message.TYPE_IMAGE);
|
this.message.setType(Message.TYPE_IMAGE);
|
||||||
this.message.setStatus(Message.STATUS_RECIEVING);
|
this.message.setStatus(Message.STATUS_RECEIVED_OFFER);
|
||||||
|
this.message.setJingleConnection(this);
|
||||||
String[] fromParts = packet.getFrom().split("/");
|
String[] fromParts = packet.getFrom().split("/");
|
||||||
this.message.setPresence(fromParts[1]);
|
this.message.setPresence(fromParts[1]);
|
||||||
this.account = account;
|
this.account = account;
|
||||||
@ -206,15 +213,16 @@ public class JingleConnection {
|
|||||||
Element fileName = fileOffer.findChild("name");
|
Element fileName = fileOffer.findChild("name");
|
||||||
this.file.setExpectedSize(Long.parseLong(fileSize.getContent()));
|
this.file.setExpectedSize(Long.parseLong(fileSize.getContent()));
|
||||||
conversation.getMessages().add(message);
|
conversation.getMessages().add(message);
|
||||||
this.mXmppConnectionService.databaseBackend.createMessage(message);
|
if (this.file.getExpectedSize()<=this.mJingleConnectionManager.getAutoAcceptFileSize()) {
|
||||||
|
Log.d("xmppService","auto accepting file from "+packet.getFrom());
|
||||||
|
this.acceptedAutomatically = true;
|
||||||
|
this.sendAccept();
|
||||||
|
} else {
|
||||||
|
message.markUnread();
|
||||||
|
Log.d("xmppService","not auto accepting new file offer with size: "+this.file.getExpectedSize()+" allowed size:"+this.mJingleConnectionManager.getAutoAcceptFileSize());
|
||||||
if (this.mXmppConnectionService.convChangedListener!=null) {
|
if (this.mXmppConnectionService.convChangedListener!=null) {
|
||||||
this.mXmppConnectionService.convChangedListener.onConversationListChanged();
|
this.mXmppConnectionService.convChangedListener.onConversationListChanged();
|
||||||
}
|
}
|
||||||
if (this.file.getExpectedSize()<=this.mJingleConnectionManager.getAutoAcceptFileSize()) {
|
|
||||||
Log.d("xmppService","auto accepting file from "+packet.getFrom());
|
|
||||||
this.sendAccept();
|
|
||||||
} else {
|
|
||||||
Log.d("xmppService","not auto accepting new file offer with size: "+this.file.getExpectedSize()+" allowed size:"+this.mJingleConnectionManager.getAutoAcceptFileSize());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d("xmppService","no file offer was attached. aborting");
|
Log.d("xmppService","no file offer was attached. aborting");
|
||||||
@ -249,6 +257,7 @@ public class JingleConnection {
|
|||||||
|
|
||||||
private void sendAccept() {
|
private void sendAccept() {
|
||||||
status = STATUS_ACCEPTED;
|
status = STATUS_ACCEPTED;
|
||||||
|
mXmppConnectionService.markMessage(message, Message.STATUS_RECIEVING);
|
||||||
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
|
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -308,10 +317,11 @@ public class JingleConnection {
|
|||||||
account.getXmppConnection().sendIqPacket(packet,responseListener);
|
account.getXmppConnection().sendIqPacket(packet,responseListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void accept(JinglePacket packet) {
|
private void receiveAccept(JinglePacket packet) {
|
||||||
Content content = packet.getJingleContent();
|
Content content = packet.getJingleContent();
|
||||||
mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
|
mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
|
||||||
this.status = STATUS_ACCEPTED;
|
this.status = STATUS_ACCEPTED;
|
||||||
|
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
|
||||||
this.connectNextCandidate();
|
this.connectNextCandidate();
|
||||||
IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT);
|
IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT);
|
||||||
account.getXmppConnection().sendIqPacket(response, null);
|
account.getXmppConnection().sendIqPacket(response, null);
|
||||||
@ -639,4 +649,18 @@ public class JingleConnection {
|
|||||||
public JingleTransport getTransport() {
|
public JingleTransport getTransport() {
|
||||||
return this.transport;
|
return this.transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void accept() {
|
||||||
|
if (status==STATUS_INITIATED) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendAccept();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
} else {
|
||||||
|
Log.d("xmppService","status ("+status+") was not ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ public class JingleInbandTransport extends JingleTransport {
|
|||||||
int count = fileInputStream.read(buffer);
|
int count = fileInputStream.read(buffer);
|
||||||
if (count==-1) {
|
if (count==-1) {
|
||||||
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
|
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
|
||||||
|
fileInputStream.close();
|
||||||
this.onFileTransmitted.onFileTransmitted(file);
|
this.onFileTransmitted.onFileTransmitted(file);
|
||||||
} else {
|
} else {
|
||||||
this.digest.update(buffer);
|
this.digest.update(buffer);
|
||||||
@ -155,6 +156,7 @@ public class JingleInbandTransport extends JingleTransport {
|
|||||||
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
|
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
|
||||||
Log.d("xmppService","file name: "+file.getAbsolutePath());
|
Log.d("xmppService","file name: "+file.getAbsolutePath());
|
||||||
fileOutputStream.flush();
|
fileOutputStream.flush();
|
||||||
|
fileOutputStream.close();
|
||||||
this.onFileTransmitted.onFileTransmitted(file);
|
this.onFileTransmitted.onFileTransmitted(file);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user