Fix some crashes

This commit is contained in:
Thomas 2022-05-05 17:35:10 +02:00
parent a9f39ee1c6
commit d30175d372
2 changed files with 12 additions and 8 deletions

View file

@ -161,13 +161,15 @@ public class SpannableHelper {
while (matcherALink.find()) {
int matchStart = matcherALink.start() - offSetTruncate;
int matchEnd = matchStart + matcherALink.group().length();
//Get real URL
/*if (matcherALink.start(1) > matcherALink.end(1) || matcherALink.end() > content.length()) {
continue;
}*/
final String url = content.toString().substring(matchStart, matchEnd);
String newURL = Helper.transformURL(context, url);
content.replace(matchStart, matchEnd, newURL);
//If URL has been transformed
if (newURL.compareTo(url) != 0) {
content.replace(matchStart, matchEnd, newURL);
offSetTruncate += (newURL.length() - url.length());
matchEnd = matchStart + newURL.length();
}
//Truncate URL if needed
//TODO: add an option to disable truncated URLs
String urlText = newURL;
@ -177,8 +179,6 @@ public class SpannableHelper {
content.replace(matchStart, matchEnd, urlText);
matchEnd = matchStart + 31;
offSetTruncate += (newURL.length() - urlText.length());
} else {
matchEnd = matchStart + (newURL.length());
}
if (!urlText.startsWith("http")) {

View file

@ -19,6 +19,8 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -169,7 +171,9 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
holder.timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
holder.binding.statusContent.invalidate();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> holder.binding.statusContent.invalidate();
mainHandler.post(myRunnable);
}
}, 100, 100);
}