fix(payverse-webview): webView 세팅 조정을 통해 네이버페이가 동작하지 않던 버그 수정
- 참고: line 315 ~ 325
This commit is contained in:
@@ -2,11 +2,16 @@ package kr.co.vividnext.sodalive.mypage.can.payment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.webkit.WebChromeClient
|
||||
import android.webkit.WebResourceError
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebSettings
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.TextView
|
||||
@@ -26,6 +31,7 @@ import kr.co.vividnext.sodalive.BuildConfig
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||
import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.databinding.ActivityCanPaymentBinding
|
||||
import kr.co.vividnext.sodalive.extensions.formatMoney
|
||||
@@ -53,8 +59,16 @@ class CanPaymentActivity : BaseActivity<ActivityCanPaymentBinding>(
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
|
||||
override fun onDestroy() {
|
||||
loadingDialog.dismiss()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun setupView() {
|
||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||
canResponse = IntentCompat.getParcelableExtra(
|
||||
intent,
|
||||
Constants.EXTRA_CAN,
|
||||
@@ -298,12 +312,52 @@ class CanPaymentActivity : BaseActivity<ActivityCanPaymentBinding>(
|
||||
|
||||
val webView: WebView = binding.webviewPayverse
|
||||
webView.visibility = View.VISIBLE
|
||||
webView.settings.allowFileAccess = false
|
||||
webView.settings.allowContentAccess = false
|
||||
webView.settings.displayZoomControls = false
|
||||
webView.settings.cacheMode = WebSettings.LOAD_NO_CACHE
|
||||
webView.settings.domStorageEnabled = true
|
||||
webView.settings.javaScriptEnabled = true
|
||||
webView.settings.javaScriptCanOpenWindowsAutomatically = true
|
||||
webView.settings.loadsImagesAutomatically = true
|
||||
webView.settings.loadWithOverviewMode = true
|
||||
webView.settings.useWideViewPort = true
|
||||
webView.settings.setSupportMultipleWindows(true)
|
||||
|
||||
webView.webViewClient = object : WebViewClient() {
|
||||
override fun onReceivedError(
|
||||
view: WebView?,
|
||||
request: WebResourceRequest?,
|
||||
error: WebResourceError?
|
||||
) {
|
||||
loadingDialog.dismiss()
|
||||
}
|
||||
|
||||
override fun onReceivedError(
|
||||
view: WebView?,
|
||||
errorCode: Int,
|
||||
description: String?,
|
||||
failingUrl: String?
|
||||
) {
|
||||
loadingDialog.dismiss()
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
super.onPageFinished(view, url)
|
||||
val escaped = JSONObject.quote(jsonForJs)
|
||||
view.evaluateJavascript("startPay($escaped)", null)
|
||||
loadingDialog.dismiss()
|
||||
|
||||
if (
|
||||
url == "file:///android_asset/payverse_starter_debug.html" ||
|
||||
url == "file:///android_asset/payverse_starter.html"
|
||||
) {
|
||||
val escaped = JSONObject.quote(jsonForJs)
|
||||
view.evaluateJavascript("startPay($escaped)", null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||
super.onPageStarted(view, url, favicon)
|
||||
loadingDialog.show(screenWidth)
|
||||
}
|
||||
|
||||
override fun shouldOverrideUrlLoading(
|
||||
@@ -311,19 +365,24 @@ class CanPaymentActivity : BaseActivity<ActivityCanPaymentBinding>(
|
||||
request: WebResourceRequest
|
||||
): Boolean {
|
||||
val url = request.url.toString()
|
||||
if (url.startsWith("$appScheme://")) {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, url.toUri()))
|
||||
return true
|
||||
}
|
||||
return handleUrl(view, url)
|
||||
}
|
||||
|
||||
if (url.startsWith("payverse://")) {
|
||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
startActivity(intent)
|
||||
}
|
||||
return true
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("DEPRECATION")
|
||||
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||
return handleUrl(view, url)
|
||||
}
|
||||
return super.shouldOverrideUrlLoading(view, url)
|
||||
}
|
||||
}
|
||||
|
||||
webView.webChromeClient = object : WebChromeClient() {
|
||||
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
||||
if (newProgress >= 100) {
|
||||
loadingDialog.dismiss()
|
||||
}
|
||||
return BootpayUrlHelper.shouldOverrideUrlLoading(view, url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +393,12 @@ class CanPaymentActivity : BaseActivity<ActivityCanPaymentBinding>(
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.e(e.message ?: "payverse start error")
|
||||
Toast.makeText(applicationContext, "결제 초기화에 실패했습니다.", Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(
|
||||
applicationContext,
|
||||
"결제 초기화에 실패했습니다.",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
binding.webviewPayverse.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,6 +407,23 @@ class CanPaymentActivity : BaseActivity<ActivityCanPaymentBinding>(
|
||||
intent?.data?.let { handlePayverseDeeplink(it) }
|
||||
}
|
||||
|
||||
private fun handleUrl(view: WebView, url: String): Boolean {
|
||||
val appScheme = BuildConfig.APPSCHEME
|
||||
if (url.startsWith("$appScheme://")) {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, url.toUri()))
|
||||
return true
|
||||
}
|
||||
|
||||
if (url.startsWith("payverse://")) {
|
||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
startActivity(intent)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return BootpayUrlHelper.shouldOverrideUrlLoading(view, url)
|
||||
}
|
||||
|
||||
private fun handlePayverseDeeplink(uri: Uri) {
|
||||
val resultStatus = uri.getQueryParameter("resultStatus")
|
||||
val transactionId = uri.getQueryParameter("tid")
|
||||
@@ -372,6 +453,7 @@ class CanPaymentActivity : BaseActivity<ActivityCanPaymentBinding>(
|
||||
},
|
||||
onFailure = {
|
||||
Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show()
|
||||
binding.webviewPayverse.visibility = View.GONE
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user