allow cancellation of waiting files

This commit is contained in:
Daniel Gultsch 2015-01-02 14:27:49 +01:00
parent bcd3be59ce
commit 3df23a4f75
2 changed files with 23 additions and 19 deletions

View file

@ -518,6 +518,10 @@ public class Message extends AbstractEntity {
this.mPreviousMessage = null; this.mPreviousMessage = null;
} }
public boolean isFileOrImage() {
return type == TYPE_FILE || type == TYPE_IMAGE;
}
public class ImageParams { public class ImageParams {
public URL url; public URL url;
public long size = 0; public long size = 0;

View file

@ -396,7 +396,8 @@ public class ConversationFragment extends Fragment {
} }
private void populateContextMenu(ContextMenu menu) { private void populateContextMenu(ContextMenu menu) {
if (this.selectedMessage.getType() != Message.TYPE_STATUS) { final Message m = this.selectedMessage;
if (m.getType() != Message.TYPE_STATUS) {
activity.getMenuInflater().inflate(R.menu.message_context, menu); activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options); menu.setHeaderTitle(R.string.message_options);
MenuItem copyText = menu.findItem(R.id.copy_text); MenuItem copyText = menu.findItem(R.id.copy_text);
@ -405,29 +406,26 @@ public class ConversationFragment extends Fragment {
MenuItem copyUrl = menu.findItem(R.id.copy_url); MenuItem copyUrl = menu.findItem(R.id.copy_url);
MenuItem downloadImage = menu.findItem(R.id.download_image); MenuItem downloadImage = menu.findItem(R.id.download_image);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission); MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
if (this.selectedMessage.getType() != Message.TYPE_TEXT if (m.getType() != Message.TYPE_TEXT || m.getDownloadable() != null) {
|| this.selectedMessage.getDownloadable() != null) {
copyText.setVisible(false); copyText.setVisible(false);
} }
if (this.selectedMessage.getType() != Message.TYPE_IMAGE if (m.getType() != Message.TYPE_IMAGE || m.getDownloadable() != null) {
|| this.selectedMessage.getDownloadable() != null) {
shareImage.setVisible(false); shareImage.setVisible(false);
} }
if (this.selectedMessage.getStatus() != Message.STATUS_SEND_FAILED) { if (m.getStatus() != Message.STATUS_SEND_FAILED) {
sendAgain.setVisible(false); sendAgain.setVisible(false);
} }
if ((this.selectedMessage.getType() != Message.TYPE_IMAGE && this.selectedMessage if ((m.getType() != Message.TYPE_IMAGE && m.getDownloadable() == null)
.getDownloadable() == null) || m.getImageParams().url == null) {
|| this.selectedMessage.getImageParams().url == null) {
copyUrl.setVisible(false); copyUrl.setVisible(false);
} }
if (this.selectedMessage.getType() != Message.TYPE_TEXT if (m.getType() != Message.TYPE_TEXT
|| this.selectedMessage.getDownloadable() != null || m.getDownloadable() != null
|| !this.selectedMessage.bodyContainsDownloadable()) { || !m.bodyContainsDownloadable()) {
downloadImage.setVisible(false); downloadImage.setVisible(false);
} }
if (this.selectedMessage.getDownloadable() == null if (!((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder))
|| this.selectedMessage.getDownloadable() instanceof DownloadablePlaceholder) { || (m.isFileOrImage() && m.getStatus() == Message.STATUS_WAITING))) {
cancelTransmission.setVisible(false); cancelTransmission.setVisible(false);
} }
} }
@ -508,6 +506,8 @@ public class ConversationFragment extends Fragment {
Downloadable downloadable = message.getDownloadable(); Downloadable downloadable = message.getDownloadable();
if (downloadable!=null) { if (downloadable!=null) {
downloadable.cancel(); downloadable.cancel();
} else {
activity.xmppConnectionService.markMessage(message,Message.STATUS_SEND_FAILED);
} }
} }