From 06ebe45f7c132cc94a1ff072a6dd002916348926 Mon Sep 17 00:00:00 2001 From: bingbong Date: Mon, 5 Apr 2021 14:57:46 +0900 Subject: [PATCH] feat : divide new activity mode, webview mode --- .../{FlutterWebView.kt => IamPortWebView.kt} | 40 +++++++++---------- .../sdk/presentation/activity/IamportSdk.kt | 21 ++++++++-- .../presentation/activity/WebViewActivity.kt | 5 ++- 3 files changed, 39 insertions(+), 27 deletions(-) rename sdk/src/main/java/com/iamport/sdk/presentation/activity/{FlutterWebView.kt => IamPortWebView.kt} (89%) diff --git a/sdk/src/main/java/com/iamport/sdk/presentation/activity/FlutterWebView.kt b/sdk/src/main/java/com/iamport/sdk/presentation/activity/IamPortWebView.kt similarity index 89% rename from sdk/src/main/java/com/iamport/sdk/presentation/activity/FlutterWebView.kt rename to sdk/src/main/java/com/iamport/sdk/presentation/activity/IamPortWebView.kt index a3fd7597..3601bb26 100644 --- a/sdk/src/main/java/com/iamport/sdk/presentation/activity/FlutterWebView.kt +++ b/sdk/src/main/java/com/iamport/sdk/presentation/activity/IamPortWebView.kt @@ -1,26 +1,19 @@ package com.iamport.sdk.presentation.activity -import android.app.Activity -import android.app.AlertDialog import android.content.Intent import android.net.Uri import android.os.Build -import android.util.Log import android.view.View import android.webkit.CookieManager import android.webkit.WebSettings import android.webkit.WebView -import android.widget.ProgressBar import androidx.activity.ComponentActivity import androidx.activity.OnBackPressedCallback -import androidx.lifecycle.viewModelScope import com.google.gson.GsonBuilder import com.iamport.sdk.BuildConfig -import com.iamport.sdk.R import com.iamport.sdk.data.sdk.IamPortResponse import com.iamport.sdk.data.sdk.Payment import com.iamport.sdk.data.sdk.ProvidePgPkg -import com.iamport.sdk.databinding.WebviewActivityBinding import com.iamport.sdk.domain.IamportWebChromeClient import com.iamport.sdk.domain.JsNativeInterface import com.iamport.sdk.domain.core.Iamport @@ -30,21 +23,17 @@ import com.iamport.sdk.presentation.contract.BankPayContract import com.iamport.sdk.presentation.viewmodel.WebViewModel import com.orhanobut.logger.Logger.* import kotlinx.coroutines.* -import org.koin.android.ext.android.get -import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.component.KoinApiExtension import org.koin.core.component.get @KoinApiExtension -class FlutterWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICoroutineScope()) : +class IamPortWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICoroutineScope()) : IamportKoinComponent, BaseCoroutineScope by scope { - // override val layoutResourceId: Int = R.layout.webview_activity // override val viewModel: WebViewModel by viewModel() private val viewModel: WebViewModel = WebViewModel(get(), get()) - // private lateinit var loading: ProgressBar private var payment: Payment? = null private var activity: ComponentActivity? = null private var webview: WebView? = null @@ -71,6 +60,7 @@ class FlutterWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor // val bundle = intent.getBundleExtra(CONST.CONTRACT_INPUT) // payment = bundle?.getParcelable(CONST.BUNDLE_PAYMENT) + this.activity = activity this.payment = payment this.webview = webview @@ -109,14 +99,17 @@ class FlutterWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor d(GsonBuilder().setPrettyPrinting().create().toJson(payment)) payment?.let { pay: Payment -> activity?.run { - viewModel.payment().observe(this, EventObserver(this@FlutterWebView::requestPayment)) - viewModel.loading().observe(this, EventObserver(this@FlutterWebView::loadingVisible)) - viewModel.openWebView().observe(this, EventObserver(this@FlutterWebView::openWebView)) - viewModel.niceTransRequestParam().observe(this, EventObserver(this@FlutterWebView::openNiceTransApp)) - viewModel.thirdPartyUri().observe(this, EventObserver(this@FlutterWebView::openThirdPartyApp)) + i("등록하니?") - viewModel.impResponse().observe(this, EventObserver(this@FlutterWebView::sdkFinish)) + viewModel.payment().observe(this, EventObserver(this@IamPortWebView::requestPayment)) + viewModel.loading().observe(this, EventObserver(this@IamPortWebView::loadingVisible)) + + viewModel.openWebView().observe(this, EventObserver(this@IamPortWebView::openWebView)) + viewModel.niceTransRequestParam().observe(this, EventObserver(this@IamPortWebView::openNiceTransApp)) + viewModel.thirdPartyUri().observe(this, EventObserver(this@IamPortWebView::openThirdPartyApp)) + + viewModel.impResponse().observe(this, EventObserver(this@IamPortWebView::sdkFinish)) viewModel.startPayment(pay) } @@ -134,6 +127,7 @@ class FlutterWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor * 결제 요청 실행 */ private fun requestPayment(it: Payment) { + i("나왔니??") loadingVisible(true) activity?.run { if (!Util.isInternetAvailable(this)) { @@ -167,11 +161,13 @@ class FlutterWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor * 모든 결과 처리 및 SDK 종료 */ fun sdkFinish(iamPortResponse: IamPortResponse?) { - w("명시적 sdkFinish ${iamPortResponse.toString()}") + i("call sdkFinish") + d("sdkFinish => ${iamPortResponse.toString()}") loadingVisible(false) - activity?.setResult(Activity.RESULT_OK, - Intent().apply { putExtra(CONST.CONTRACT_OUTPUT, iamPortResponse) }) - activity?.finish() +// activity?.setResult(Activity.RESULT_OK, +// Intent().apply { putExtra(CONST.CONTRACT_OUTPUT, iamPortResponse) }) +// activity?.finish() + Iamport.callback(iamPortResponse) } /** diff --git a/sdk/src/main/java/com/iamport/sdk/presentation/activity/IamportSdk.kt b/sdk/src/main/java/com/iamport/sdk/presentation/activity/IamportSdk.kt index 345484a4..d7cb330e 100644 --- a/sdk/src/main/java/com/iamport/sdk/presentation/activity/IamportSdk.kt +++ b/sdk/src/main/java/com/iamport/sdk/presentation/activity/IamportSdk.kt @@ -35,7 +35,6 @@ internal class IamportSdk( val activity: ComponentActivity? = null, val fragment: Fragment? = null, val webViewLauncher: ActivityResultLauncher?, - val webView: WebView? = null, val close: LiveData>, val finish: LiveData>, ) : IamportKoinComponent { @@ -72,6 +71,8 @@ internal class IamportSdk( addAction(Intent.ACTION_SCREEN_ON) } + private var webview: WebView? = null + init { // viewModel = ViewModelProvider(hostHelper.viewModelStoreOwner, MainViewModelFactory(get(), get())).get(MainViewModel::class.java) @@ -84,6 +85,11 @@ internal class IamportSdk( clearData() } + // webview 모드임 + fun setWebView(webview: WebView) { + this.webview = webview + } + private val lifecycleObserver = object : LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_START) @@ -264,6 +270,7 @@ internal class IamportSdk( viewModel.checkChaiStatusForResultCallback() } + /** * 결제 요청 실행 */ @@ -302,9 +309,17 @@ internal class IamportSdk( * 웹뷰 결제 요청 실행 */ private fun requestWebViewPayment(it: Payment) { + d("requestWebViewPayment $it") clearData() -// webViewLauncher?.launch(it) - FlutterWebView().initStart(activity!!, webView!!, it) + activity?.let { activity -> + webview?.let { webView -> + IamPortWebView().initStart(activity, webView, it) // webview only 모드 + } ?: run { + webViewLauncher?.launch(it) // new activity 모드 + } + } ?: run { + e("Cannot found activity") + } } diff --git a/sdk/src/main/java/com/iamport/sdk/presentation/activity/WebViewActivity.kt b/sdk/src/main/java/com/iamport/sdk/presentation/activity/WebViewActivity.kt index 12ad56b7..efc9fb68 100644 --- a/sdk/src/main/java/com/iamport/sdk/presentation/activity/WebViewActivity.kt +++ b/sdk/src/main/java/com/iamport/sdk/presentation/activity/WebViewActivity.kt @@ -138,7 +138,8 @@ class WebViewActivity : BaseActivity(), Ia * 모든 결과 처리 및 SDK 종료 */ override fun sdkFinish(iamPortResponse: IamPortResponse?) { - w("명시적 sdkFinish ${iamPortResponse.toString()}") + i("call sdkFinish") + d("sdkFinish => ${iamPortResponse.toString()}") loadingVisible(false) setResult(Activity.RESULT_OK, Intent().apply { putExtra(CONST.CONTRACT_OUTPUT, iamPortResponse) }) @@ -214,7 +215,7 @@ class WebViewActivity : BaseActivity(), Ia } } -// setTheme(R.style.Theme_AppCompat_Transparent_NoActionBar) + setTheme(R.style.Theme_AppCompat_Transparent_NoActionBar) updateAlpha(true) loadingVisible(true)