Skip to content

Commit

Permalink
Match email addresses before web urls
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Dec 12, 2019
1 parent a6b4ccb commit f62140b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ android {
testBuildType "mockdata"

defaultConfig {
versionCode 266
versionCode 267
versionName "4.20"
minSdkVersion 17
targetSdkVersion 29
Expand Down
64 changes: 32 additions & 32 deletions src/com/irccloud/android/ColorFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,38 @@ public boolean acceptMatch(CharSequence s, int start, int end) {
}
};

Linkify.addLinks(output, Patterns.EMAIL_ADDRESS, "mailto:", noOverlapFilter, null);
Linkify.addLinks(output, Pattern.compile("ircs?://[^<>\",\\s]+"), null, noOverlapFilter, new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
char last = url.charAt(url.length() - 1);
if (isPunctuation(last)) {
url = url.substring(0, url.length() - 1);
last = url.charAt(url.length() - 1);
}

if (quotes.containsKey(String.valueOf(last))) {
char open = quotes.get(String.valueOf(last)).charAt(0);
int countOpen = 0, countClose = 0;
for (int i = 0; i < url.length(); i++) {
char c = url.charAt(i);
if (c == open)
countOpen++;
else if (c == last)
countClose++;
}
if (countOpen != countClose) {
url = url.substring(0, url.length() - 1);
}
}

return url.replace("#", "%23");
}
});
Linkify.addLinks(output, Pattern.compile("spotify:([a-zA-Z0-9:]+)"), null, noOverlapFilter, new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return "https://open.spotify.com/" + url.substring(8).replace(":", "/");
}
});
Linkify.addLinks(output, WEB_URL, null, new MatchFilter() {
public final boolean acceptMatch(CharSequence s, int start, int end) {
if (start >= 6 && s.subSequence(start - 6, end).toString().toLowerCase().startsWith("irc://"))
Expand Down Expand Up @@ -2504,38 +2536,6 @@ else if (lower.startsWith("https://"))
return url;
}
});
Linkify.addLinks(output, Patterns.EMAIL_ADDRESS, "mailto:", noOverlapFilter, null);
Linkify.addLinks(output, Pattern.compile("ircs?://[^<>\",\\s]+"), null, noOverlapFilter, new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
char last = url.charAt(url.length() - 1);
if (isPunctuation(last)) {
url = url.substring(0, url.length() - 1);
last = url.charAt(url.length() - 1);
}

if (quotes.containsKey(String.valueOf(last))) {
char open = quotes.get(String.valueOf(last)).charAt(0);
int countOpen = 0, countClose = 0;
for (int i = 0; i < url.length(); i++) {
char c = url.charAt(i);
if (c == open)
countOpen++;
else if (c == last)
countClose++;
}
if (countOpen != countClose) {
url = url.substring(0, url.length() - 1);
}
}

return url.replace("#", "%23");
}
});
Linkify.addLinks(output, Pattern.compile("spotify:([a-zA-Z0-9:]+)"), null, noOverlapFilter, new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return "https://open.spotify.com/" + url.substring(8).replace(":", "/");
}
});
if (server != null) {
Linkify.addLinks(output, Pattern.compile(pattern), null, new MatchFilter() {
public final boolean acceptMatch(CharSequence s, int start, int end) {
Expand Down

0 comments on commit f62140b

Please sign in to comment.