aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-03-31 13:30:16 +0200
committerChristian Schneppe <christian@pix-art.de>2019-03-31 13:30:16 +0200
commitf2423a674a662d932d65de9712ae50aea38879dd (patch)
tree0289e7274b866e933978263ab60b86a8bb886635 /src/main/java/de/pixart/messenger
parentd301d25e28c1d381994d305da7f2cb14bce87333 (diff)
fix url detection for webpreviews
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java12
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/MyLinkify.java2
-rw-r--r--src/main/java/de/pixart/messenger/utils/RichPreview.java2
4 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index c8850c278..a5f81ff5b 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -607,6 +607,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
this.getBody().length() + message.getBody().length() <= Config.MAX_DISPLAY_MESSAGE_CHARS &&
!message.isGeoUri()&&
!this.isGeoUri() &&
+ !message.isWebUri() &&
!this.isWebUri() &&
!message.treatAsDownloadable() &&
!this.treatAsDownloadable() &&
@@ -788,7 +789,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
public synchronized boolean isWebUri() {
String url = body.trim();
if (isWebUri == null) {
- isWebUri = URLUtil.isValidUrl(url) && Patterns.WEB_URL.matcher(url).matches() && !url.contains(" ");
+ isWebUri = Patterns.AUTOLINK_WEB_URL.matcher(url).matches() && !url.contains(" ");
}
return isWebUri;
}
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 203b3a343..a97f68cd8 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -41,6 +41,7 @@ import com.squareup.picasso.Picasso;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.List;
+import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -85,6 +86,7 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static de.pixart.messenger.ui.SettingsActivity.PLAY_GIF_INSIDE;
import static de.pixart.messenger.ui.SettingsActivity.SHOW_LINKS_INSIDE;
import static de.pixart.messenger.ui.SettingsActivity.SHOW_MAPS_INSIDE;
+import static de.pixart.messenger.ui.util.MyLinkify.removeTrailingBracket;
public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
@@ -715,7 +717,15 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(WRAP_CONTENT, scaledH);
layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
viewHolder.richlinkview.setLayoutParams(layoutParams);
- viewHolder.richlinkview.setLink(body.toString(), message.getUuid(), dataSaverDisabled, new RichPreview.ViewListener() {
+ final String url = body.toString();
+ String weburl;
+ final String lcUrl = url.toLowerCase(Locale.US);
+ if (lcUrl.startsWith("http://") || lcUrl.startsWith("https://")) {
+ weburl = removeTrailingBracket(url);
+ } else {
+ weburl = "http://" + removeTrailingBracket(url);
+ }
+ viewHolder.richlinkview.setLink(weburl, message.getUuid(), dataSaverDisabled, new RichPreview.ViewListener() {
@Override
public void onSuccess(boolean status) {
diff --git a/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java b/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java
index 59de9be6d..fb271cd7c 100644
--- a/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java
+++ b/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java
@@ -55,7 +55,7 @@ public class MyLinkify {
}
};
- private static String removeTrailingBracket(final String url) {
+ public static String removeTrailingBracket(final String url) {
int numOpenBrackets = 0;
for (char c : url.toCharArray()) {
if (c == '(') {
diff --git a/src/main/java/de/pixart/messenger/utils/RichPreview.java b/src/main/java/de/pixart/messenger/utils/RichPreview.java
index 7824478d6..e0bff1cf2 100644
--- a/src/main/java/de/pixart/messenger/utils/RichPreview.java
+++ b/src/main/java/de/pixart/messenger/utils/RichPreview.java
@@ -125,7 +125,7 @@ public class RichPreview {
}
private String resolveURL(String url, String part) {
- if (URLUtil.isValidUrl(part)) {
+ if (Patterns.AUTOLINK_WEB_URL.matcher(part).matches() && !part.contains(" ")) {
return part;
} else {
URI base_uri = null;