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();
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components.viewpager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Matrix;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
public class RtlSafeViewPager extends HackyViewPager {
|
||||
private final Matrix mirrorMatrix = new Matrix();
|
||||
private boolean rtl;
|
||||
|
||||
public RtlSafeViewPager(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public RtlSafeViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
updateLayoutDirection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRtlPropertiesChanged(int layoutDirection) {
|
||||
super.onRtlPropertiesChanged(layoutDirection);
|
||||
updateLayoutDirection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if (!isRtl()) {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
MotionEvent mirrored = getMirroredMotionEvent(ev);
|
||||
try {
|
||||
return super.onInterceptTouchEvent(mirrored);
|
||||
} finally {
|
||||
mirrored.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (!isRtl()) {
|
||||
return super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
MotionEvent mirrored = getMirroredMotionEvent(ev);
|
||||
try {
|
||||
return super.onTouchEvent(mirrored);
|
||||
} finally {
|
||||
mirrored.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRtl() {
|
||||
return rtl;
|
||||
}
|
||||
|
||||
private MotionEvent getMirroredMotionEvent(@NonNull MotionEvent ev) {
|
||||
MotionEvent mirrored = MotionEvent.obtain(ev);
|
||||
mirrorMatrix.reset();
|
||||
mirrorMatrix.setScale(-1f, 1f, getWidth() / 2f, 0f);
|
||||
mirrored.transform(mirrorMatrix);
|
||||
return mirrored;
|
||||
}
|
||||
|
||||
private void updateLayoutDirection() {
|
||||
rtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.components.viewpager.RtlSafeViewPager
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.components.viewpager.RtlSafeViewPager
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
app:tabSelectedTextColor="@color/white"
|
||||
app:tabMode="fixed" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.viewpager.RtlSafeViewPager
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/camera_sticker_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0px"
|
||||
|
||||
Reference in New Issue
Block a user