diff --git a/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java b/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java
index e1c569981..203e69d2e 100644
--- a/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java
+++ b/app/src/main/java/org/linphone/chat/ChatMessageViewHolder.java
@@ -28,8 +28,8 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.CountDownTimer;
-import android.text.Spanned;
import android.text.method.LinkMovementMethod;
+import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.MimeTypeMap;
@@ -221,9 +221,8 @@ public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements Vi
}
if (message.hasTextContent()) {
- String msg = message.getTextContent();
- Spanned text = LinphoneUtils.getTextWithHttpLinks(msg);
- messageText.setText(text);
+ messageText.setText(message.getTextContent());
+ Linkify.addLinks(messageText, Linkify.ALL);
messageText.setMovementMethod(LinkMovementMethod.getInstance());
messageText.setVisibility(View.VISIBLE);
}
diff --git a/app/src/main/java/org/linphone/utils/LinphoneUtils.java b/app/src/main/java/org/linphone/utils/LinphoneUtils.java
index 63c52ca65..09fbd9bb1 100644
--- a/app/src/main/java/org/linphone/utils/LinphoneUtils.java
+++ b/app/src/main/java/org/linphone/utils/LinphoneUtils.java
@@ -29,8 +29,6 @@ import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Looper;
import android.telephony.TelephonyManager;
-import android.text.Html;
-import android.text.Spanned;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
@@ -41,7 +39,6 @@ import androidx.core.content.ContextCompat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
-import java.util.regex.Pattern;
import org.linphone.LinphoneContext;
import org.linphone.LinphoneManager;
import org.linphone.R;
@@ -302,52 +299,6 @@ public final class LinphoneUtils {
}
}
- public static Spanned getTextWithHttpLinks(String text) {
- if (text == null) return null;
-
- if (text.contains("<")) {
- text = text.replace("<", "<");
- }
- if (text.contains(">")) {
- text = text.replace(">", ">");
- }
- if (text.contains("\n")) {
- text = text.replace("\n", "
");
- }
- if (text.contains("http://")) {
- int indexHttp = text.indexOf("http://");
- int indexFinHttp =
- text.indexOf(" ", indexHttp) == -1
- ? (text.indexOf("
", indexHttp) == -1
- ? text.length()
- : text.indexOf("
", indexHttp))
- : text.indexOf(" ", indexHttp);
- String link = text.substring(indexHttp, indexFinHttp);
- String linkWithoutScheme = link.replace("http://", "");
- text =
- text.replaceFirst(
- Pattern.quote(link),
- "" + linkWithoutScheme + "");
- }
- if (text.contains("https://")) {
- int indexHttp = text.indexOf("https://");
- int indexFinHttp =
- text.indexOf(" ", indexHttp) == -1
- ? (text.indexOf("
", indexHttp) == -1
- ? text.length()
- : text.indexOf("
", indexHttp))
- : text.indexOf(" ", indexHttp);
- String link = text.substring(indexHttp, indexFinHttp);
- String linkWithoutScheme = link.replace("https://", "");
- text =
- text.replaceFirst(
- Pattern.quote(link),
- "" + linkWithoutScheme + "");
- }
-
- return Html.fromHtml(text);
- }
-
public static void showTrustDeniedDialog(Context context) {
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);