3838import android .webkit .WebBackForwardList ;
3939import android .webkit .WebChromeClient ;
4040import android .webkit .WebHistoryItem ;
41+ import android .webkit .WebResourceRequest ;
4142import android .webkit .WebView ;
4243import android .webkit .WebViewClient ;
4344import android .widget .FrameLayout ;
7273import com .alphawallet .app .entity .TransactionReturn ;
7374import com .alphawallet .app .entity .URLLoadInterface ;
7475import com .alphawallet .app .entity .Wallet ;
75- import com .alphawallet .app .entity .WalletConnectActions ;
7676import com .alphawallet .app .entity .WalletType ;
7777import com .alphawallet .app .entity .analytics .ActionSheetSource ;
7878import com .alphawallet .app .entity .analytics .QrScanResultType ;
@@ -218,7 +218,7 @@ public void onActivityResult(Uri uri)
218218 // Need to handle the inverse event where the keyboard is hidden, and we size the page back
219219 // (Remembering to allow for the navigation bar).
220220 private final View .OnApplyWindowInsetsListener resizeListener = (v , insets ) -> {
221- if (v == null || getActivity () == null )
221+ if (getActivity () == null )
222222 {
223223 return insets ;
224224 }
@@ -896,66 +896,11 @@ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathC
896896 web3 .setWebViewClient (new WebViewClient ()
897897 {
898898 @ Override
899- public boolean shouldOverrideUrlLoading (WebView view , String url )
899+ public boolean shouldOverrideUrlLoading (WebView view , WebResourceRequest request )
900900 {
901- String [] prefixCheck = url .split (":" );
902- if (prefixCheck .length > 1 )
903- {
904- Intent intent ;
905- switch (prefixCheck [0 ])
906- {
907- case C .DAPP_PREFIX_TELEPHONE :
908- intent = new Intent (Intent .ACTION_DIAL );
909- intent .setData (Uri .parse (url ));
910- startActivity (Intent .createChooser (intent , "Call " + prefixCheck [1 ]));
911- return true ;
912- case C .DAPP_PREFIX_MAILTO :
913- intent = new Intent (Intent .ACTION_SENDTO );
914- intent .setData (Uri .parse (url ));
915- startActivity (Intent .createChooser (intent , "Email: " + prefixCheck [1 ]));
916- return true ;
917- case C .DAPP_PREFIX_ALPHAWALLET :
918- if (prefixCheck [1 ].equals (C .DAPP_SUFFIX_RECEIVE ))
919- {
920- viewModel .showMyAddress (getContext ());
921- return true ;
922- }
923- break ;
924- case C .DAPP_PREFIX_WALLETCONNECT :
925- //start walletconnect
926- if (wallet .type == WalletType .WATCH )
927- {
928- showWalletWatch ();
929- }
930- else
931- {
932- walletConnectSession = url ;
933- if (getContext () != null )
934- viewModel .handleWalletConnect (getContext (), url , activeNetwork );
935- }
936- return true ;
937- default :
938- break ;
939- }
940- }
941-
942- if (fromWalletConnectModal (url ))
943- {
944- String encodedURL = url .split ("=" )[1 ];
945- try
946- {
947- String decodedURL = URLDecoder .decode (encodedURL , Charset .defaultCharset ().name ());
948- viewModel .handleWalletConnect (getContext (), decodedURL , activeNetwork );
949- return true ;
950- }
951- catch (UnsupportedEncodingException e )
952- {
953- Timber .d ("Decode URL failed: " + e );
954- }
955- }
956-
957- setUrlText (url );
958- return false ;
901+ final Uri uri = request .getUrl ();
902+ final String url = uri .toString ();
903+ return handlePrefix (url );
959904 }
960905 });
961906
@@ -978,6 +923,77 @@ public boolean shouldOverrideUrlLoading(WebView view, String url)
978923 }
979924 }
980925
926+ private boolean handlePrefix (String url )
927+ {
928+ String [] prefixCheck = url .split (":" );
929+ if (prefixCheck .length > 1 )
930+ {
931+ Intent intent ;
932+ switch (prefixCheck [0 ])
933+ {
934+ case C .DAPP_PREFIX_TELEPHONE :
935+ intent = new Intent (Intent .ACTION_DIAL );
936+ intent .setData (Uri .parse (url ));
937+ startActivity (Intent .createChooser (intent , "Call " + prefixCheck [1 ]));
938+ return true ;
939+ case C .DAPP_PREFIX_MAILTO :
940+ intent = new Intent (Intent .ACTION_SENDTO );
941+ intent .setData (Uri .parse (url ));
942+ startActivity (Intent .createChooser (intent , "Email: " + prefixCheck [1 ]));
943+ return true ;
944+ case C .DAPP_PREFIX_ALPHAWALLET :
945+ if (prefixCheck [1 ].equals (C .DAPP_SUFFIX_RECEIVE ))
946+ {
947+ viewModel .showMyAddress (getContext ());
948+ return true ;
949+ }
950+ break ;
951+ case C .DAPP_PREFIX_AWALLET :
952+ handleAWCode (url );
953+ return true ;
954+ case C .DAPP_PREFIX_WALLETCONNECT :
955+ //start walletconnect
956+ if (wallet .type == WalletType .WATCH )
957+ {
958+ showWalletWatch ();
959+ }
960+ else
961+ {
962+ walletConnectSession = url ;
963+ if (getContext () != null )
964+ viewModel .handleWalletConnect (getContext (), url , activeNetwork );
965+ }
966+ return true ;
967+ default :
968+ break ;
969+ }
970+ }
971+
972+ if (fromWalletConnectModal (url ))
973+ {
974+ String encodedURL = url .split ("=" )[1 ];
975+ try
976+ {
977+ String decodedURL = URLDecoder .decode (encodedURL , Charset .defaultCharset ().name ());
978+ viewModel .handleWalletConnect (getContext (), decodedURL , activeNetwork );
979+ return true ;
980+ }
981+ catch (UnsupportedEncodingException e )
982+ {
983+ Timber .d ("Decode URL failed: %s" , e .getMessage ());
984+ }
985+ }
986+
987+ return false ;
988+ }
989+
990+ private void handleAWCode (String awCode )
991+ {
992+ Bundle codeBundle = new Bundle ();
993+ codeBundle .putString (C .AWALLET_CODE , awCode );
994+ getParentFragmentManager ().setFragmentResult (C .AWALLET_CODE , codeBundle );
995+ }
996+
981997 private boolean fromWalletConnectModal (String url )
982998 {
983999 return url .startsWith ("https://" + mainnetMagicLinkDomain + "/wc?uri=" );
@@ -1477,7 +1493,14 @@ private boolean loadUrl(String urlText)
14771493 detachFragments ();
14781494 addToBackStack (DAPP_BROWSER );
14791495 cancelSearchSession ();
1480- if (checkForMagicLink (urlText )) return true ;
1496+ if (checkForMagicLink (urlText ))
1497+ {
1498+ return true ;
1499+ }
1500+ else if (handlePrefix (urlText ))
1501+ {
1502+ return true ;
1503+ }
14811504 web3 .resetView ();
14821505 web3 .loadUrl (Utils .formatUrl (urlText ));
14831506 setUrlText (Utils .formatUrl (urlText ));
0 commit comments