diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-10-14 19:27:49 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-10-14 19:27:49 +0200 |
commit | 262128c8f9152330b61bc5b4358337ff2fd0fdcf (patch) | |
tree | 5cde45244e7a6ed933025abb608f7c8b9d395c6f /src/eu/siacs/conversations/ui | |
parent | 031b739af8122e0c6a2926c3f9db78e207560f64 (diff) |
recreate http connection after restart. fixes stale download button. better failing
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 5 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/adapter/MessageAdapter.java | 51 |
2 files changed, 48 insertions, 8 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 3d4cffee..984bf7c9 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -1,12 +1,17 @@ package eu.siacs.conversations.ui; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; import java.util.ArrayList; import java.util.List; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Downloadable; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.Message.ImageParams; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 581a410c..028ab002 100644 --- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.ui.adapter; +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashMap; import java.util.List; @@ -225,10 +227,19 @@ public class MessageAdapter extends ArrayAdapter<Message> { viewHolder.messageBody.setVisibility(View.VISIBLE); if (message.getBody() != null) { if (message.getType() != Message.TYPE_PRIVATE) { - String body = Config.PARSE_EMOTICONS ? UIHelper - .transformAsciiEmoticons(message.getMergedBody()) - : message.getMergedBody(); - viewHolder.messageBody.setText(body); + if (message.getType() == Message.TYPE_IMAGE) { + String orign = message.getImageParams().origin; + if (orign!=null) { + viewHolder.messageBody.setText(orign); + } else { + viewHolder.messageBody.setText(message.getBody()); + } + } else { + String body = Config.PARSE_EMOTICONS ? UIHelper + .transformAsciiEmoticons(message.getMergedBody()) + : message.getMergedBody(); + viewHolder.messageBody.setText(body); + } } else { String privateMarker; if (message.getStatus() <= Message.STATUS_RECEIVED) { @@ -474,6 +485,8 @@ public class MessageAdapter extends ArrayAdapter<Message> { displayInfoMessage(viewHolder, R.string.receiving_image); } else if (item.getStatus() == Message.STATUS_RECEIVED_CHECKING) { displayInfoMessage(viewHolder, R.string.checking_image); + } else if (item.getStatus() == Message.STATUS_RECEPTION_FAILED) { + displayTextMessage(viewHolder, item); } else if (item.getStatus() == Message.STATUS_RECEIVED_OFFER) { viewHolder.image.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); @@ -483,10 +496,10 @@ public class MessageAdapter extends ArrayAdapter<Message> { @Override public void onClick(View v) { - Downloadable downloadable = item - .getDownloadable(); - if (downloadable != null) { - downloadable.start(); + if (!startDonwloadable(item)) { + activity.xmppConnectionService.markMessage( + item, + Message.STATUS_RECEPTION_FAILED); } } }); @@ -527,6 +540,28 @@ public class MessageAdapter extends ArrayAdapter<Message> { return view; } + public boolean startDonwloadable(Message message) { + Downloadable downloadable = message.getDownloadable(); + if (downloadable != null) { + downloadable.start(); + return true; + } else { + ImageParams params = message.getImageParams(); + if (params.origin != null) { + try { + URL url = new URL(params.origin); + activity.xmppConnectionService.getHttpConnectionManager() + .createNewConnection(message, url); + return true; + } catch (MalformedURLException e) { + return false; + } + } else { + return false; + } + } + } + private static class ViewHolder { protected LinearLayout message_box; |