Skip to content

Commit

Permalink
Back gesture to scroll up
Browse files Browse the repository at this point in the history
  • Loading branch information
wanam authored Jan 23, 2023
1 parent 2fd9a0d commit 93ecaa3
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions app/src/main/java/ma/wanam/youtubeadaway/BFAsync.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ma.wanam.youtubeadaway;

import android.os.AsyncTask;
import android.os.Handler;
import android.text.TextUtils;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -28,6 +29,15 @@ public class BFAsync extends AsyncTask<XC_LoadPackage.LoadPackageParam, Void, Bo
private volatile Method fingerprintMethod = null;
private volatile Optional<Field> pathBuilderField = Optional.empty();
private XC_MethodHook.Unhook unhookFilterMethod;
private volatile boolean isAtTopOfView = true;
private Handler handler;

public Handler getHandler() {
if (handler == null) {
handler = new Handler();
}
return handler;
}

private static final String filterAds = new StringBuffer().append(".*(").append(String.join("|", new String[]{
"ads_video_with_context",
Expand Down Expand Up @@ -82,10 +92,27 @@ protected Boolean doInBackground(XC_LoadPackage.LoadPackageParam... params) {
XposedHelpers.findAndHookMethod("com.google.android.apps.youtube.app.watchwhile.WatchWhileActivity", cl, "onBackPressed", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.callMethod(param.thisObject, "finish");
if (isAtTopOfView) {
XposedHelpers.callMethod(param.thisObject, "finish");
} else {
getHandler().removeCallbacksAndMessages(null);
getHandler().postDelayed(() -> isAtTopOfView = true, 1000);
}
}
});

XposedHelpers.findAndHookMethod("android.support.v7.widget.RecyclerView", cl, "stopNestedScroll",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
getHandler().removeCallbacksAndMessages(null);
isAtTopOfView = false;
getHandler().postDelayed(
() -> isAtTopOfView = !(boolean) XposedHelpers.callMethod(param.thisObject, "canScrollVertically", -1)
, 1000);
}
});

return bruteForceAds(cl);
}

Expand Down Expand Up @@ -269,7 +296,7 @@ private void hookAdCardsMethods(Method fingerprintMethod, final Method emptyComp
try {
unhookFilterMethod = XposedBridge.hookMethod(fingerprintMethod, new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
if (!pathBuilderField.isPresent()) {
pathBuilderField = Arrays.stream(param.args[1].getClass().getDeclaredFields()).parallel().filter(field ->
field.getType().equals(StringBuilder.class)
Expand Down Expand Up @@ -307,4 +334,4 @@ protected void onPostExecute(Boolean found) {
}
}

}
}

0 comments on commit 93ecaa3

Please sign in to comment.