allow redownloading files from remote hosts. fixes #1504

This commit is contained in:
Daniel Gultsch 2015-10-17 15:23:46 +02:00
parent e9e31b1c9b
commit 0f405c2e11
2 changed files with 13 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import eu.siacs.conversations.R;
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.Transferable; import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.entities.TransferablePlaceholder;
import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.AbstractConnectionManager; import eu.siacs.conversations.services.AbstractConnectionManager;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
@ -66,7 +67,11 @@ public class HttpDownloadConnection implements Transferable {
this.message = message; this.message = message;
this.message.setTransferable(this); this.message.setTransferable(this);
try { try {
if (message.hasFileOnRemoteHost()) {
mUrl = message.getFileParams().url;
} else {
mUrl = new URL(message.getBody()); mUrl = new URL(message.getBody());
}
String[] parts = mUrl.getPath().toLowerCase().split("\\."); String[] parts = mUrl.getPath().toLowerCase().split("\\.");
String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null; String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null;
String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null; String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null;
@ -106,7 +111,11 @@ public class HttpDownloadConnection implements Transferable {
public void cancel() { public void cancel() {
mHttpConnectionManager.finishConnection(this); mHttpConnectionManager.finishConnection(this);
if (message.isFileOrImage()) {
message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
} else {
message.setTransferable(null); message.setTransferable(null);
}
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
} }

View File

@ -489,7 +489,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|| m.treatAsDownloadable() == Message.Decision.MUST) { || m.treatAsDownloadable() == Message.Decision.MUST) {
copyUrl.setVisible(true); copyUrl.setVisible(true);
} }
if (m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER) { if ((m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER)
|| (m.isFileOrImage() && m.getTransferable() instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
downloadFile.setVisible(true); downloadFile.setVisible(true);
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m))); downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
} }