forked from mirrors/Fedilab
Fix issue #366 - Text with links not displayed
This commit is contained in:
parent
e7dd2ac5d2
commit
c68b4b6b2e
1 changed files with 9 additions and 17 deletions
|
@ -41,7 +41,6 @@ import android.text.style.URLSpan;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.URLUtil;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -152,6 +151,7 @@ public class SpannableHelper {
|
||||||
} else if (announcement != null) {
|
} else if (announcement != null) {
|
||||||
emojiList = announcement.emojis;
|
emojiList = announcement.emojis;
|
||||||
}
|
}
|
||||||
|
//UrlDetails will contain links having a text different from the url
|
||||||
HashMap<String, String> urlDetails = new HashMap<>();
|
HashMap<String, String> urlDetails = new HashMap<>();
|
||||||
if (convertHtml) {
|
if (convertHtml) {
|
||||||
Matcher matcherALink = Helper.aLink.matcher(text);
|
Matcher matcherALink = Helper.aLink.matcher(text);
|
||||||
|
@ -163,7 +163,7 @@ public class SpannableHelper {
|
||||||
if (urlText != null && urlText.startsWith(">")) {
|
if (urlText != null && urlText.startsWith(">")) {
|
||||||
urlText = urlText.substring(1);
|
urlText = urlText.substring(1);
|
||||||
}
|
}
|
||||||
if (url != null && urlText != null && !url.equals(urlText) && !urlText.contains("<span")) {
|
if (url != null && urlText != null && !url.equalsIgnoreCase(urlText) && !urlText.contains("<span")) {
|
||||||
urlDetails.put(url, urlText);
|
urlDetails.put(url, urlText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,16 +231,15 @@ public class SpannableHelper {
|
||||||
|
|
||||||
|
|
||||||
final String url = content.toString().substring(matchStart, matchEnd);
|
final String url = content.toString().substring(matchStart, matchEnd);
|
||||||
|
if (urlDetails.containsKey(url)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String newURL = Helper.transformURL(context, url);
|
String newURL = Helper.transformURL(context, url);
|
||||||
//If URL has been transformed
|
//If URL has been transformed
|
||||||
if (newURL.compareTo(url) != 0) {
|
if (newURL.compareTo(url) != 0) {
|
||||||
content.replace(matchStart, matchEnd, newURL);
|
content.replace(matchStart, matchEnd, newURL);
|
||||||
offSetTruncate -= (newURL.length() - url.length());
|
offSetTruncate -= (newURL.length() - url.length());
|
||||||
matchEnd = matchStart + newURL.length();
|
matchEnd = matchStart + newURL.length();
|
||||||
//The transformed URL was in the list of URLs having a different names
|
|
||||||
if (urlDetails.containsKey(url)) {
|
|
||||||
urlDetails.put(newURL, urlDetails.get(url));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Truncate URL if needed
|
//Truncate URL if needed
|
||||||
|
@ -252,14 +251,7 @@ public class SpannableHelper {
|
||||||
content.replace(matchStart, matchEnd, urlText);
|
content.replace(matchStart, matchEnd, urlText);
|
||||||
matchEnd = matchStart + 31;
|
matchEnd = matchStart + 31;
|
||||||
offSetTruncate += (newURL.length() - urlText.length());
|
offSetTruncate += (newURL.length() - urlText.length());
|
||||||
} /*else if (urlDetails.containsKey(urlText) && urlDetails.get(urlText) != null) {
|
}
|
||||||
urlText = urlDetails.get(urlText);
|
|
||||||
if (urlText != null) {
|
|
||||||
content.replace(matchStart, matchEnd, urlText);
|
|
||||||
matchEnd = matchStart + urlText.length();
|
|
||||||
offSetTruncate += (newURL.length() - urlText.length());
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
if (matchEnd <= content.length() && matchEnd >= matchStart) {
|
if (matchEnd <= content.length() && matchEnd >= matchStart) {
|
||||||
|
@ -351,7 +343,7 @@ public class SpannableHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
httpsURLConnection.getInputStream().close();
|
httpsURLConnection.getInputStream().close();
|
||||||
if (redirect != null && finalURl1 != null && redirect.compareTo(finalURl1) != 0) {
|
if (redirect != null && redirect.compareTo(finalURl1) != 0) {
|
||||||
URL redirectURL = new URL(redirect);
|
URL redirectURL = new URL(redirect);
|
||||||
String host = redirectURL.getHost();
|
String host = redirectURL.getHost();
|
||||||
String protocol = redirectURL.getProtocol();
|
String protocol = redirectURL.getProtocol();
|
||||||
|
@ -476,7 +468,7 @@ public class SpannableHelper {
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : urlDetails.entrySet()) {
|
for (Map.Entry<String, String> entry : urlDetails.entrySet()) {
|
||||||
String value = entry.getValue();
|
String value = entry.getValue();
|
||||||
if (value.startsWith("@") || value.startsWith("#") || !URLUtil.isValidUrl(value)) {
|
if (value.startsWith("@") || value.startsWith("#")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SpannableString contentUrl;
|
SpannableString contentUrl;
|
||||||
|
@ -485,7 +477,7 @@ public class SpannableHelper {
|
||||||
else
|
else
|
||||||
contentUrl = new SpannableString(Html.fromHtml(value));
|
contentUrl = new SpannableString(Html.fromHtml(value));
|
||||||
|
|
||||||
Pattern word = Pattern.compile(contentUrl.toString());
|
Pattern word = Pattern.compile(Pattern.quote(contentUrl.toString()));
|
||||||
Matcher matcherLink = word.matcher(content);
|
Matcher matcherLink = word.matcher(content);
|
||||||
while (matcherLink.find()) {
|
while (matcherLink.find()) {
|
||||||
String url = entry.getKey();
|
String url = entry.getKey();
|
||||||
|
|
Loading…
Reference in a new issue