aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Message.java40
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java10
3 files changed, 41 insertions, 14 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index bb3140c3..8dbb0535 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -81,6 +81,7 @@ public class Message extends AbstractEntity {
private Message mNextMessage = null;
private Message mPreviousMessage = null;
private String axolotlFingerprint = null;
+ private Decision mTreatAsDownloadAble = Decision.NOT_DECIDED;
private Message() {
@@ -467,6 +468,7 @@ public class Message extends AbstractEntity {
MUST,
SHOULD,
NEVER,
+ NOT_DECIDED,
}
private String extractRelevantExtension(URL url) {
@@ -515,44 +517,64 @@ public class Message extends AbstractEntity {
}
}
+ /**
+ * in case of later found error with decision, set it to a value which does not affect anything, hopefully
+ */
+ public void setNoDownloadable() {
+ mTreatAsDownloadAble = Decision.NEVER;
+ }
+
public Decision treatAsDownloadable() {
+ // only test this ones, body will not change
+ if (mTreatAsDownloadAble != Decision.NOT_DECIDED) {
+ return mTreatAsDownloadAble;
+ }
/**
* there are a few cases where spaces result in an unwanted behavior, e.g.
* "http://example.com/image.jpg" text that will not be shown /abc.png"
* or more than one image link in one message.
*/
if (getBody().contains(" ")) {
- return Decision.NEVER;
+ mTreatAsDownloadAble = Decision.NEVER;
+ return mTreatAsDownloadAble;
}
try {
URL url = new URL(body);
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
- return Decision.NEVER;
+ mTreatAsDownloadAble = Decision.NEVER;
+ return mTreatAsDownloadAble;
} else if (oob) {
- return Decision.MUST;
+ mTreatAsDownloadAble = Decision.MUST;
+ return mTreatAsDownloadAble;
}
String extension = extractRelevantExtension(url);
if (extension == null) {
- return Decision.NEVER;
+ mTreatAsDownloadAble = Decision.NEVER;
+ return mTreatAsDownloadAble;
}
String ref = url.getRef();
boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}");
if (encrypted) {
if (MimeUtils.guessMimeTypeFromExtension(extension) != null) {
- return Decision.MUST;
+ mTreatAsDownloadAble = Decision.MUST;
+ return mTreatAsDownloadAble;
} else {
- return Decision.NEVER;
+ mTreatAsDownloadAble = Decision.NEVER;
+ return mTreatAsDownloadAble;
}
} else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension)
|| Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) {
- return Decision.SHOULD;
+ mTreatAsDownloadAble = Decision.SHOULD;
+ return mTreatAsDownloadAble;
} else {
- return Decision.NEVER;
+ mTreatAsDownloadAble = Decision.NEVER;
+ return mTreatAsDownloadAble;
}
} catch (MalformedURLException e) {
- return Decision.NEVER;
+ mTreatAsDownloadAble = Decision.NEVER;
+ return mTreatAsDownloadAble;
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
index 0e50dd4d..1517e5d1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java
@@ -10,12 +10,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.MalformedURLException;
-import java.net.Proxy;
import java.net.URL;
-import java.util.Arrays;
import java.util.concurrent.CancellationException;
import javax.net.ssl.HttpsURLConnection;
@@ -183,6 +179,7 @@ public class HttpDownloadConnection implements Transferable {
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
return;
} catch (RemoteFileNotFoundException e) {
+ message.setNoDownloadable();
cancel();
return;
} catch (IOException e) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index e700d6e9..e35c0f97 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -561,8 +561,16 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|| (t != null && t instanceof HttpDownloadConnection)) {
copyUrl.setVisible(true);
}
+ boolean b1 = true;
+ b1 &= m.getType() == Message.TYPE_TEXT;
+ b1 &= t == null;
+ b1 &= m.treatAsDownloadable() != Message.Decision.NEVER;
+ boolean b2 = true;
+ b2 &= m.isFileOrImage();
+ b2 &= t instanceof TransferablePlaceholder;
+ b2 &= m.hasFileOnRemoteHost();
if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER)
- || (m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
+ || (t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
downloadFile.setVisible(true);
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
}