Commit b18a1c97 authored by Thomas's avatar Thomas
Browse files

Fix an issue with links

parent 255ee607
Pipeline #310849 passed with stage
in 8 minutes and 31 seconds
......@@ -66,6 +66,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -420,7 +421,7 @@ public class Status implements Parcelable {
Matcher matcher;
Pattern linkPattern = Pattern.compile("<a((?!href).)*href=\"([^\"]*)\"[^>]*(((?!</a).)*)</a>");
matcher = linkPattern.matcher(spannableString);
HashMap<String, String> targetedURL = new HashMap<>();
LinkedHashMap<String, String> targetedURL = new LinkedHashMap<>();
HashMap<String, Account> accountsMentionUnknown = new HashMap<>();
String liveInstance = Helper.getLiveInstance(context);
int i = 1;
......@@ -553,9 +554,9 @@ public class Status implements Parcelable {
}
if (accountsMentionUnknown.size() > 0) {
Iterator it = accountsMentionUnknown.entrySet().iterator();
Iterator<Map.Entry<String, Account>> it = accountsMentionUnknown.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
Map.Entry<String, Account> pair = (Map.Entry<String, Account>) it.next();
String key = (String) pair.getKey();
Account account = (Account) pair.getValue();
String targetedAccount = "@" + account.getAcct();
......@@ -603,19 +604,17 @@ public class Status implements Parcelable {
}
}
if (targetedURL.size() > 0) {
Iterator it = targetedURL.entrySet().iterator();
Iterator<Map.Entry<String, String>> it = targetedURL.entrySet().iterator();
int endPosition = 0;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
Map.Entry<String, String> pair = (Map.Entry<String, String>) it.next();
String key = ((String) pair.getKey()).split("\\|")[0];
String url = (String) pair.getValue();
if (spannableStringT.toString().toLowerCase().contains(key.toLowerCase())) {
//Accounts can be mentioned several times so we have to loop
int startPosition = spannableStringT.toString().toLowerCase().indexOf(key.toLowerCase(), endPosition);
if (startPosition < 0) {
startPosition = 0;
}
if (startPosition > 0) {
endPosition = startPosition + key.length();
if (key.contains("…") && !key.endsWith("…")) {
key = key.split("…")[0] + "…";
......@@ -780,6 +779,8 @@ public class Status implements Parcelable {
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
it.remove();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment