From 3dc506570c0152298034a00f858c5c8a86d71135 Mon Sep 17 00:00:00 2001 From: xscreach Date: Thu, 22 Feb 2024 10:10:55 +0100 Subject: [PATCH 1/3] popup cleanup --- .../iitc_mobile/IITC_WebViewPopup.java | 77 +++++++++---------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java index e790ff4d3..68c3367a3 100644 --- a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java +++ b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java @@ -61,31 +61,6 @@ private boolean reloadWithUserAgent(final WebView view, final String url) { return true; } - private String categorizeUriHostAndPath(String uriHost, String uriPath) { - if (uriHost.endsWith("facebook.com") - && (uriPath.contains("oauth") || uriPath.startsWith("/login") || uriPath.equals("/checkpoint/") - || uriPath.equals("/cookie/consent_prompt/"))) { - return "Facebook"; - } - if (uriHost.startsWith("accounts.google.") || - uriHost.startsWith("appengine.google.") || - uriHost.startsWith("accounts.youtube.") || - uriHost.startsWith("myaccount.google.") || - uriHost.startsWith("gds.google.")) { - return "Google"; - } - if (uriHost.equals("appleid.apple.com")) { - return "AppleID"; - } - if (uriHost.startsWith("signin.nianticlabs.")) { - return "Niantic"; - } - if (mIitc.isInternalHostname(uriHost)) { - return "InternalHost"; - } - return "Unknown"; - } - @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { final Uri uri = Uri.parse(url); @@ -115,9 +90,13 @@ public boolean shouldOverrideUrlLoading(final WebView view, final String url) { return shouldOverrideUrlLoading(view, uriQuery); } - String authCategory = categorizeUriHostAndPath(uriHost, uriPath); - if (!authCategory.equals("Unknown")) { - Log.d("popup: " + authCategory + " login"); + if (isFacebookAuth(uriHost, uriPath) + || isGoogleAuth(uriHost) + || isAppleAuth(uriHost) + || isNianticAuth(uriHost) + || isInternalHostname(uriHost) + ) { + Log.d("Opening popup: " + uri); openDialogPopup(); return false; } @@ -151,6 +130,32 @@ public void onDismiss(DialogInterface dialog) { }); } + private boolean isInternalHostname(String uriHost) { + return mIitc.isInternalHostname(uriHost); + } + + private boolean isNianticAuth(String uriHost) { + return uriHost.startsWith("signin.nianticlabs."); + } + + private boolean isAppleAuth(String uriHost) { + return uriHost.equals("appleid.apple.com"); + } + + private boolean isGoogleAuth(String uriHost) { + return uriHost.startsWith("accounts.google.") || + uriHost.startsWith("appengine.google.") || + uriHost.startsWith("accounts.youtube.") || + uriHost.startsWith("myaccount.google.") || + uriHost.startsWith("gds.google."); + } + + private boolean isFacebookAuth(String uriHost, String uriPath) { + return uriHost.endsWith("facebook.com") + && (uriPath.contains("oauth") || uriPath.startsWith("/login") || uriPath.equals("/checkpoint/") + || uriPath.equals("/cookie/consent_prompt/")); + } + private void openDialogPopup() { if (mDialog.isShowing()) return; @@ -168,20 +173,8 @@ private void openDialogPopup() { // Set width and height to match_parent layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; - - // Calculate the margin size - DisplayMetrics displayMetrics = new DisplayMetrics(); - ((WindowManager) mIitc.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics); - float widthMargin = displayMetrics.widthPixels * 0.05f; - float heightMargin = displayMetrics.heightPixels * 0.05f; - - // Convert pixels to dp to use as margin - float density = displayMetrics.density; - int marginWidthDp = (int) (widthMargin / density); - int marginHeightDp = (int) (heightMargin / density); - - layoutParams.horizontalMargin = marginWidthDp; - layoutParams.verticalMargin = marginHeightDp; + layoutParams.horizontalMargin = 0.1f; + layoutParams.verticalMargin = 0.2f; mDialog.show(); From 4825e052658050065a5bd6b0590321489e9b987e Mon Sep 17 00:00:00 2001 From: xscreach Date: Fri, 23 Feb 2024 09:13:39 +0100 Subject: [PATCH 2/3] extracted LoginUrlChecker --- .../iitc_mobile/IITC_WebViewPopup.java | 51 ++++++------------- .../iitc_mobile/LoginUrlChecker.java | 42 +++++++++++++++ 2 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 mobile/app/src/main/java/org/exarhteam/iitc_mobile/LoginUrlChecker.java diff --git a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java index 68c3367a3..8abb612e3 100644 --- a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java +++ b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java @@ -90,12 +90,7 @@ public boolean shouldOverrideUrlLoading(final WebView view, final String url) { return shouldOverrideUrlLoading(view, uriQuery); } - if (isFacebookAuth(uriHost, uriPath) - || isGoogleAuth(uriHost) - || isAppleAuth(uriHost) - || isNianticAuth(uriHost) - || isInternalHostname(uriHost) - ) { + if (mIitc.isInternalHostname(uriHost) || LoginUrlChecker.isLoginUrl(uri)) { Log.d("Opening popup: " + uri); openDialogPopup(); return false; @@ -130,32 +125,6 @@ public void onDismiss(DialogInterface dialog) { }); } - private boolean isInternalHostname(String uriHost) { - return mIitc.isInternalHostname(uriHost); - } - - private boolean isNianticAuth(String uriHost) { - return uriHost.startsWith("signin.nianticlabs."); - } - - private boolean isAppleAuth(String uriHost) { - return uriHost.equals("appleid.apple.com"); - } - - private boolean isGoogleAuth(String uriHost) { - return uriHost.startsWith("accounts.google.") || - uriHost.startsWith("appengine.google.") || - uriHost.startsWith("accounts.youtube.") || - uriHost.startsWith("myaccount.google.") || - uriHost.startsWith("gds.google."); - } - - private boolean isFacebookAuth(String uriHost, String uriPath) { - return uriHost.endsWith("facebook.com") - && (uriPath.contains("oauth") || uriPath.startsWith("/login") || uriPath.equals("/checkpoint/") - || uriPath.equals("/cookie/consent_prompt/")); - } - private void openDialogPopup() { if (mDialog.isShowing()) return; @@ -173,13 +142,25 @@ private void openDialogPopup() { // Set width and height to match_parent layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; - layoutParams.horizontalMargin = 0.1f; - layoutParams.verticalMargin = 0.2f; - mDialog.show(); + // Calculate the margin size + DisplayMetrics displayMetrics = new DisplayMetrics(); + ((WindowManager) mIitc.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics); + float widthMargin = displayMetrics.widthPixels * 5f; + float heightMargin = displayMetrics.heightPixels * 0.01f; + + // Convert pixels to dp to use as margin + float density = displayMetrics.density; + int marginWidthDp = (int) (widthMargin / density); + int marginHeightDp = (int) (heightMargin / density); + + layoutParams.horizontalMargin = marginWidthDp; + layoutParams.verticalMargin = marginHeightDp; mDialog.getWindow().setAttributes(layoutParams); mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); + + mDialog.show(); } // constructors ------------------------------------------------- diff --git a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/LoginUrlChecker.java b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/LoginUrlChecker.java new file mode 100644 index 000000000..56110eaca --- /dev/null +++ b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/LoginUrlChecker.java @@ -0,0 +1,42 @@ +package org.exarhteam.iitc_mobile; + +import android.net.Uri; + +public class LoginUrlChecker { + + private LoginUrlChecker() { + //hiding default constructor - only static methods + } + + public static boolean isLoginUrl(Uri uri) { + String uriHost = uri.getHost(); + String uriPath = uri.getPath(); + + return isFacebookAuth(uriHost, uriPath) + || isGoogleAuth(uriHost) + || isAppleAuth(uriHost) + || isNianticAuth(uriHost); + } + + private static boolean isFacebookAuth(String uriHost, String uriPath) { + return uriHost.endsWith("facebook.com") + && (uriPath.contains("oauth") || uriPath.startsWith("/login") || uriPath.equals("/checkpoint/") + || uriPath.equals("/cookie/consent_prompt/")); + } + + private static boolean isGoogleAuth(String uriHost) { + return uriHost.startsWith("accounts.google.") || + uriHost.startsWith("appengine.google.") || + uriHost.startsWith("accounts.youtube.") || + uriHost.startsWith("myaccount.google.") || + uriHost.startsWith("gds.google."); + } + + private static boolean isAppleAuth(String uriHost) { + return uriHost.equals("appleid.apple.com"); + } + + private static boolean isNianticAuth(String uriHost) { + return uriHost.startsWith("signin.nianticlabs."); + } +} From bba535232701d3ea41ab090a8f913452700a0fc6 Mon Sep 17 00:00:00 2001 From: xscreach Date: Fri, 23 Feb 2024 09:27:21 +0100 Subject: [PATCH 3/3] simpler popup handling --- .../iitc_mobile/IITC_WebViewPopup.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java index 8abb612e3..12f67e5bb 100644 --- a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java +++ b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_WebViewPopup.java @@ -129,36 +129,36 @@ private void openDialogPopup() { if (mDialog.isShowing()) return; // Set the dialog content view to match parent's height and width - ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT - ); - mDialog.getWindow().setContentView(this, params); - - // Set horizontal and vertical margins +// ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( +// ViewGroup.LayoutParams.MATCH_PARENT, +// ViewGroup.LayoutParams.MATCH_PARENT +// ); +// mDialog.getWindow().setContentView(this, params); +// +// // Set horizontal and vertical margins WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); layoutParams.copyFrom(mDialog.getWindow().getAttributes()); - - // Set width and height to match_parent +// +// // Set width and height to match_parent layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; - - // Calculate the margin size - DisplayMetrics displayMetrics = new DisplayMetrics(); - ((WindowManager) mIitc.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics); - float widthMargin = displayMetrics.widthPixels * 5f; - float heightMargin = displayMetrics.heightPixels * 0.01f; - - // Convert pixels to dp to use as margin - float density = displayMetrics.density; - int marginWidthDp = (int) (widthMargin / density); - int marginHeightDp = (int) (heightMargin / density); - - layoutParams.horizontalMargin = marginWidthDp; - layoutParams.verticalMargin = marginHeightDp; - +// +// // Calculate the margin size +// DisplayMetrics displayMetrics = new DisplayMetrics(); +// ((WindowManager) mIitc.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics); +// float widthMargin = displayMetrics.widthPixels * 5f; +// float heightMargin = displayMetrics.heightPixels * 0.01f; +// +// // Convert pixels to dp to use as margin +// float density = displayMetrics.density; +// int marginWidthDp = (int) (widthMargin / density); +// int marginHeightDp = (int) (heightMargin / density); +// +// layoutParams.horizontalMargin = -0.3f; +// layoutParams.verticalMargin = 0.3f; +// mDialog.getWindow().setAttributes(layoutParams); - mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); +// mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); mDialog.show(); }