diff --git a/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java b/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java index 789c5d42..1e5974d2 100644 --- a/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java +++ b/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java @@ -5,9 +5,11 @@ import android.net.Uri; import android.support.customtabs.CustomTabsIntent; import android.view.View; +import android.view.ViewGroup; import android.webkit.WebView; import de.robv.android.xposed.XC_MethodHook; +import de.robv.android.xposed.XposedBridge; import de.robv.android.xposed.XposedHelpers; import de.robv.android.xposed.callbacks.XC_LoadPackage; import io.github.chipppppppppp.lime.LimeOptions; @@ -24,24 +26,47 @@ public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPa @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Activity activity = (Activity) param.thisObject; - int webViewResId = activity.getResources().getIdentifier("iab_webview", "id", activity.getPackageName()); - WebView webView = (WebView) activity.findViewById(webViewResId); - webView.setVisibility(View.GONE); - webView.stopLoading(); - Uri uri = Uri.parse(webView.getUrl()); - if (limeOptions.openInBrowser.checked) { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(uri); - activity.startActivity(intent); - } else { - CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder() - .setShowTitle(true) - .build(); - tabsIntent.launchUrl(activity, uri); + View rootView = activity.getWindow().getDecorView().getRootView(); + WebView webView = findWebView(rootView); + + if (webView != null) { + webView.setVisibility(View.GONE); + webView.stopLoading(); + + Uri uri = Uri.parse(webView.getUrl()); + + if (limeOptions.openInBrowser.checked) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(uri); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.startActivity(intent); + } else { + CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder() + .setShowTitle(true) + .build(); + tabsIntent.launchUrl(activity, uri); + } + + activity.finish(); + } - activity.finish(); } } ); } + + private WebView findWebView(View view) { + if (view instanceof WebView) { + return (WebView) view; + } else if (view instanceof ViewGroup) { + ViewGroup group = (ViewGroup) view; + for (int i = 0; i < group.getChildCount(); i++) { + WebView result = findWebView(group.getChildAt(i)); + if (result != null) { + return result; + } + } + } + return null; + } }