From db03f4c47e97b1344711b37ead6d6e165663f3a6 Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 13 Oct 2023 12:22:55 +1100 Subject: [PATCH] Fix for JS popup --- .../app/ui/WalletConnectSessionActivity.java | 41 ++++++++------- .../alphawallet/app/web3/Web3TokenView.java | 50 +++++++++++-------- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/alphawallet/app/ui/WalletConnectSessionActivity.java b/app/src/main/java/com/alphawallet/app/ui/WalletConnectSessionActivity.java index 12074e3da2..f1bb6af005 100644 --- a/app/src/main/java/com/alphawallet/app/ui/WalletConnectSessionActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/WalletConnectSessionActivity.java @@ -2,6 +2,8 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static androidx.core.content.ContentProviderCompat.requireContext; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -40,6 +42,7 @@ import com.alphawallet.app.ui.widget.divider.ListDivider; import com.alphawallet.app.viewmodel.WalletConnectViewModel; import com.alphawallet.app.walletconnect.AWWalletConnectClient; +import com.alphawallet.app.widget.AWalletAlertDialog; import com.bumptech.glide.Glide; import java.util.List; @@ -231,27 +234,23 @@ private void setStatusIconActive(final CustomAdapter.CustomViewHolder holder, bo private void dialogConfirmDelete(WalletConnectSessionItem session) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - AlertDialog dialog = builder.setTitle(R.string.title_delete_session) - .setMessage(getString(R.string.delete_session, session.name)) - .setPositiveButton(R.string.delete, (d, w) -> { - viewModel.deleteSession(session, new AWWalletConnectClient.WalletConnectV2Callback() - { - @Override - public void onSessionDisconnected() - { - runOnUiThread(() -> { - awWalletConnectClient.updateNotification(); - }); - } - }); - }) - .setNegativeButton(R.string.action_cancel, (d, w) -> { - d.dismiss(); - }) - .setCancelable(false) - .create(); - dialog.show(); + AWalletAlertDialog cDialog = new AWalletAlertDialog(this); + cDialog.setCancelable(true); + cDialog.setTitle(R.string.title_delete_session); + cDialog.setMessage(getString(R.string.delete_session, session.name)); + cDialog.setButtonText(R.string.delete); + cDialog.setButtonListener(v -> viewModel.deleteSession(session, new AWWalletConnectClient.WalletConnectV2Callback() + { + @Override + public void onSessionDisconnected() + { + runOnUiThread(() -> awWalletConnectClient.updateNotification()); + } + })); + cDialog.setSecondaryButtonText(R.string.action_cancel); + cDialog.setSecondaryButtonListener(view -> cDialog.dismiss()); + cDialog.setCancelable(false); + cDialog.show(); } private void startConnectionCheck() diff --git a/app/src/main/java/com/alphawallet/app/web3/Web3TokenView.java b/app/src/main/java/com/alphawallet/app/web3/Web3TokenView.java index 62d0b5b966..bb2d9a56e9 100644 --- a/app/src/main/java/com/alphawallet/app/web3/Web3TokenView.java +++ b/app/src/main/java/com/alphawallet/app/web3/Web3TokenView.java @@ -2,6 +2,7 @@ import static androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF; import static androidx.webkit.WebSettingsCompat.FORCE_DARK_ON; +import static androidx.webkit.WebSettingsCompat.setAlgorithmicDarkeningAllowed; import static com.alphawallet.app.service.AssetDefinitionService.ASSET_DETAIL_VIEW_NAME; import static com.alphawallet.app.service.AssetDefinitionService.ASSET_SUMMARY_VIEW_NAME; import static com.alphawallet.token.tools.TokenDefinition.TOKENSCRIPT_ERROR; @@ -16,6 +17,8 @@ import android.view.View; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; +import android.webkit.JsPromptResult; +import android.webkit.JsResult; import android.webkit.WebChromeClient; import android.webkit.WebResourceError; import android.webkit.WebResourceRequest; @@ -125,18 +128,9 @@ private void init() { + "AlphaWallet(Platform=Android&AppVersion=" + BuildConfig.VERSION_NAME + ")"); WebView.setWebContentsDebuggingEnabled(true); - if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) + if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) { - switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) - { - case Configuration.UI_MODE_NIGHT_YES: - WebSettingsCompat.setForceDark(getSettings(), FORCE_DARK_ON); - break; - case Configuration.UI_MODE_NIGHT_NO: - case Configuration.UI_MODE_NIGHT_UNDEFINED: - WebSettingsCompat.setForceDark(getSettings(), FORCE_DARK_OFF); - break; - } + WebSettingsCompat.setAlgorithmicDarkeningAllowed(getSettings(), true); } setScrollBarSize(0); @@ -153,8 +147,6 @@ private void init() { innerOnSignPersonalMessageListener, innerOnSetValuesListener), "alpha"); - super.setWebViewClient(tokenScriptClient); - setWebChromeClient(new WebChromeClient() { @Override @@ -191,7 +183,16 @@ public boolean onConsoleMessage(ConsoleMessage msg) } return true; } + + @Override + public boolean onJsAlert(WebView view, String url, String message, JsResult result) + { + result.cancel(); + return true; + } }); + + setWebViewClient(tokenScriptClient); } public void showError(String error) @@ -201,12 +202,6 @@ public void showError(String error) loadData(error, "text/html", "utf-8"); } - @Override - public void setWebChromeClient(WebChromeClient client) - { - super.setWebChromeClient(client); - } - @JavascriptInterface public void onValue(String data) { @@ -228,6 +223,19 @@ public void onCloseWindow(WebView window) { callback.functionSuccess(); } + + @Override + public boolean onConsoleMessage(ConsoleMessage msg) + { + return true; + } + + @Override + public boolean onJsAlert(WebView view, String url, String message, JsResult result) + { + result.cancel(); + return true; + } } ); } @@ -385,11 +393,11 @@ public void onUnhandledKeyEvent(WebView view, KeyEvent event) } @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { if (assetHolder != null) { - return assetHolder.overridePageLoad(view, url); + return assetHolder.overridePageLoad(view, request.getUrl().toString()); } else {