[app] Scroll WebView (#776)
This commit is contained in:
parent
aed23f65e8
commit
2d907cb911
|
|
@ -162,8 +162,6 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.Listene
|
||||||
} else {
|
} else {
|
||||||
body = HTML_TEMPLATE.replace("@body@", text);
|
body = HTML_TEMPLATE.replace("@body@", text);
|
||||||
}
|
}
|
||||||
body = body.replace("src=\"/", "src=\"/Xposed-Modules-Repo/" + module.getName() + "/raw/main/")
|
|
||||||
.replace("href=\"/", "href=\"/Xposed-Modules-Repo/" + module.getName() + "/blob/main/");
|
|
||||||
view.setWebViewClient(new WebViewClient() {
|
view.setWebViewClient(new WebViewClient() {
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.lsposed.manager.ui.widget;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewParent;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.view.ScrollingView;
|
||||||
|
import androidx.viewpager2.widget.ViewPager2;
|
||||||
|
|
||||||
|
public class ScrollWebView extends WebView {
|
||||||
|
public ScrollWebView(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScrollWebView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScrollWebView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScrollWebView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
var viewParent = findViewParentIfNeeds(this);
|
||||||
|
if (viewParent != null) viewParent.requestDisallowInterceptTouchEvent(true);
|
||||||
|
}
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
|
||||||
|
if (clampedX) {
|
||||||
|
var viewParent = findViewParentIfNeeds(this);
|
||||||
|
if (viewParent != null) viewParent.requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ViewParent findViewParentIfNeeds(View v) {
|
||||||
|
var parent = v.getParent();
|
||||||
|
if (parent == null) return null;
|
||||||
|
if (parent instanceof ViewPager2 || parent instanceof ScrollingView) {
|
||||||
|
return parent;
|
||||||
|
} else if (parent instanceof View) {
|
||||||
|
return findViewParentIfNeeds((View) parent);
|
||||||
|
} else {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
app:borderTopDrawable="@null"
|
app:borderTopDrawable="@null"
|
||||||
app:borderBottomVisibility="never">
|
app:borderBottomVisibility="never">
|
||||||
|
|
||||||
<WebView
|
<org.lsposed.manager.ui.widget.ScrollWebView
|
||||||
android:id="@+id/readme"
|
android:id="@+id/readme"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
tools:text="@tools:sample/lorem" />
|
tools:text="@tools:sample/lorem" />
|
||||||
|
|
||||||
<WebView
|
<org.lsposed.manager.ui.widget.ScrollWebView
|
||||||
android:id="@+id/description"
|
android:id="@+id/description"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue