From d8f5ef733a1320996ff87c1aa3f659acf93d424c Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 2 Jun 2023 23:21:04 +0800 Subject: [PATCH 1/2] feat: support web sdk social login --- .../com/portto/sdk/core/WebSDKActivity.kt | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/portto/sdk/core/WebSDKActivity.kt b/core/src/main/java/com/portto/sdk/core/WebSDKActivity.kt index 645a2cc..1c561df 100644 --- a/core/src/main/java/com/portto/sdk/core/WebSDKActivity.kt +++ b/core/src/main/java/com/portto/sdk/core/WebSDKActivity.kt @@ -3,10 +3,13 @@ package com.portto.sdk.core import android.annotation.SuppressLint import android.content.Context import android.content.Intent +import android.graphics.Rect import android.net.Uri import android.os.Bundle +import android.os.Message import android.webkit.WebChromeClient import android.webkit.WebResourceRequest +import android.webkit.WebSettings import android.webkit.WebView import android.webkit.WebViewClient import androidx.activity.addCallback @@ -17,6 +20,7 @@ import com.portto.sdk.core.databinding.ActivityWebSdkBinding import com.portto.sdk.wallet.BloctoSDKError import com.portto.sdk.wallet.Const +@SuppressLint("SetJavaScriptEnabled") class WebSDKActivity : AppCompatActivity() { companion object { @@ -37,7 +41,6 @@ class WebSDKActivity : AppCompatActivity() { private lateinit var binding: ActivityWebSdkBinding private val requestId by lazy { intent.getStringExtra(Const.KEY_REQUEST_ID) } - @SuppressLint("SetJavaScriptEnabled") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityWebSdkBinding.inflate(layoutInflater) @@ -60,9 +63,10 @@ class WebSDKActivity : AppCompatActivity() { } val url = intent.getStringExtra(KEY_URL) ?: return + with(binding.webView) { - settings.javaScriptEnabled = true - settings.domStorageEnabled = true + settings.setup() + webViewClient = object : WebViewClient() { override fun shouldOverrideUrlLoading( view: WebView?, @@ -82,14 +86,60 @@ class WebSDKActivity : AppCompatActivity() { binding.toolbar.title = view?.title } } + webChromeClient = object : WebChromeClient() { override fun onProgressChanged(view: WebView?, newProgress: Int) { super.onProgressChanged(view, newProgress) binding.progressBar.progress = newProgress binding.progressBar.isGone = newProgress == 100 } + + override fun onCreateWindow( + view: WebView?, + isDialog: Boolean, + isUserGesture: Boolean, + resultMsg: Message? + ): Boolean = onCreateWebWindow(resultMsg) } loadUrl(url) } } + + private fun onCreateWebWindow(resultMsg: Message?): Boolean { + val webView = WebView(this@WebSDKActivity) + webView.settings.setup() + + webView.webViewClient = object : WebViewClient() { + override fun onPageFinished(view: WebView?, url: String?) { + super.onPageFinished(view, url) + // Make WebView height match parent + val displayRectangle = Rect() + window.decorView.getWindowVisibleDisplayFrame(displayRectangle) + view?.layoutParams = view?.layoutParams?.apply { + height = displayRectangle.height() + } + } + } + + webView.webChromeClient = object : WebChromeClient() { + override fun onCloseWindow(window: WebView?) { + super.onCloseWindow(window) + binding.webView.removeView(window) + } + } + + binding.webView.addView(webView) + val transport = resultMsg?.obj as WebView.WebViewTransport + transport.webView = webView + resultMsg.sendToTarget() + return true + } + + private fun WebSettings.setup() { + javaScriptEnabled = true + domStorageEnabled = true + setSupportMultipleWindows(true) + // Remove "wv" from user agent to make Google login work + userAgentString = userAgentString.replace(oldValue = "; wv", newValue = "") + } } From 93a737e1e1f46e99860def55acbf09d9172fe5e6 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 5 Jun 2023 16:19:00 +0800 Subject: [PATCH 2/2] Bump version to 0.5.1 --- dependencies.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 95e90d4..3163d0a 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,8 +1,8 @@ ext.versions = [ minSdk : 21, compileSdk : 33, - versionCode : 6, - versionName : '0.5.0', + versionCode : 7, + versionName : '0.5.1', androidx_activity : '1.7.1', androidx_appcompat : '1.6.1',