mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cb84e9fe3c | |||
| 02812b0f3b | |||
| 7f625d6e8d |
@@ -15,6 +15,7 @@ import chat.delta.rpc.types.HttpResponse;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Locale;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
@@ -120,6 +121,7 @@ public class FullMsgActivity extends WebViewActivity {
|
||||
try {
|
||||
FullMsgActivity activity = activityReference.get();
|
||||
String html = activity.dcContext.getMsgHtml(activity.msgId);
|
||||
html = withAutoTextDirection(html);
|
||||
|
||||
activity.runOnUiThread(
|
||||
() -> {
|
||||
@@ -141,6 +143,31 @@ public class FullMsgActivity extends WebViewActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private static String withAutoTextDirection(String html) {
|
||||
if (html == null || html.isEmpty()) {
|
||||
return html;
|
||||
}
|
||||
String lowercaseHtml = html.toLowerCase(Locale.US);
|
||||
int bodyTagStart = lowercaseHtml.indexOf("<body");
|
||||
if (bodyTagStart >= 0) {
|
||||
int bodyTagEnd = lowercaseHtml.indexOf(">", bodyTagStart);
|
||||
if (bodyTagEnd < 0) {
|
||||
return html;
|
||||
}
|
||||
String bodyTag = html.substring(bodyTagStart, bodyTagEnd + 1);
|
||||
String lowercaseBodyTag = lowercaseHtml.substring(bodyTagStart, bodyTagEnd + 1);
|
||||
if (lowercaseBodyTag.contains("dir=")) {
|
||||
return html;
|
||||
}
|
||||
if (lowercaseBodyTag.endsWith("/>")) {
|
||||
return html;
|
||||
}
|
||||
String updatedBodyTag = bodyTag.substring(0, bodyTag.length() - 1) + " dir=\"auto\">";
|
||||
return html.substring(0, bodyTagStart) + updatedBodyTag + html.substring(bodyTagEnd + 1);
|
||||
}
|
||||
return "<div dir=\"auto\">" + html + "</div>";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
Reference in New Issue
Block a user