Skip to content

Commit

Permalink
Merge pull request #27 from iamport/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kjh5833 authored Apr 19, 2021
2 parents 09c90b4 + fa0eb4b commit a8e5d37
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 27 deletions.
4 changes: 2 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 30
versionCode 210408001 // yymmdd000
versionName "0.0.6-dev24" // prod(x.y.z), dev(x.y.z-dev00), poc(x.y.z-poc00)
versionCode 210419001 // yymmdd000
versionName "0.0.6" // prod(x.y.z), dev(x.y.z-dev00), poc(x.y.z-poc00)
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/java/com/iamport/sdk/domain/core/Iamport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.iamport.sdk.domain.di.IamportKoinContext.koinApp
import com.iamport.sdk.domain.di.apiModule
import com.iamport.sdk.domain.di.appModule
import com.iamport.sdk.domain.di.httpClientModule
//import com.iamport.sdk.domain.di.httpClientModule
import com.iamport.sdk.domain.service.ChaiService
import com.iamport.sdk.domain.utils.CONST
import com.iamport.sdk.domain.utils.Event
Expand Down
15 changes: 8 additions & 7 deletions sdk/src/main/java/com/iamport/sdk/domain/di/apiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.iamport.sdk.domain.utils.CONST
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.core.component.KoinApiExtension
import org.koin.core.qualifier.named
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
Expand All @@ -32,7 +33,7 @@ fun provideOkHttpClient(context: Context?): OkHttpClient? {
} ?: run { null }
}

fun provideIamportApi(gson: Gson, client: OkHttpClient?): IamportApi {
fun provideIamportApi(gson : Gson, client: OkHttpClient?): IamportApi {

return Retrofit.Builder()
.baseUrl(CONST.IAMPORT_PROD_URL)
Expand All @@ -43,7 +44,7 @@ fun provideIamportApi(gson: Gson, client: OkHttpClient?): IamportApi {
.create(IamportApi::class.java)
}

fun provideNiceApi(gson: Gson, client: OkHttpClient?): NiceApi {
fun provideNiceApi(gson : Gson, client: OkHttpClient?): NiceApi {
return Retrofit.Builder()
.baseUrl("${CONST.IAMPORT_DETECT_URL}/")
.addConverterFactory(GsonConverterFactory.create(gson)).apply {
Expand All @@ -53,7 +54,7 @@ fun provideNiceApi(gson: Gson, client: OkHttpClient?): NiceApi {
.create(NiceApi::class.java)
}

fun provideChaiApi(isStaging: Boolean, gson: Gson, client: OkHttpClient?): ChaiApi {
fun provideChaiApi(isStaging: Boolean, gson : Gson, client: OkHttpClient?): ChaiApi {
return Retrofit.Builder()
.baseUrl(if (isStaging) CONST.CHAI_SERVICE_STAGING_URL else CONST.CHAI_SERVICE_URL)
.addConverterFactory(GsonConverterFactory.create(gson)).apply {
Expand All @@ -64,13 +65,13 @@ fun provideChaiApi(isStaging: Boolean, gson: Gson, client: OkHttpClient?): ChaiA
}

@OptIn(KoinApiExtension::class)
val httpClientModule = module {
single { provideOkHttpClient(get()) }
val httpClientModule = module(override = true) {
single(named("${CONST.KOIN_KEY}provideOkHttpClient")) { provideOkHttpClient(get()) }
}

@OptIn(KoinApiExtension::class)
val apiModule = module {
single { provideIamportApi(get(), get()) }
single { provideIamportApi(get(named("${CONST.KOIN_KEY}Gson")), get(named("${CONST.KOIN_KEY}provideOkHttpClient")),) }
// single { provideChaiApi(false, get(), get()) }
single { provideNiceApi(get(), get()) }
single { provideNiceApi(get(named("${CONST.KOIN_KEY}Gson")), get(named("${CONST.KOIN_KEY}provideOkHttpClient")),) }
}
4 changes: 3 additions & 1 deletion sdk/src/main/java/com/iamport/sdk/domain/di/appModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import com.iamport.sdk.domain.strategy.chai.ChaiStrategy
import com.iamport.sdk.domain.strategy.webview.CertificationWebViewStrategy
import com.iamport.sdk.domain.strategy.webview.NiceTransWebViewStrategy
import com.iamport.sdk.domain.strategy.webview.WebViewStrategy
import com.iamport.sdk.domain.utils.CONST
import com.iamport.sdk.domain.utils.NativeLiveDataEventBus
import com.iamport.sdk.domain.utils.WebViewLiveDataEventBus
import com.iamport.sdk.presentation.viewmodel.MainViewModel
import com.iamport.sdk.presentation.viewmodel.WebViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.component.KoinApiExtension
import org.koin.core.qualifier.named
import org.koin.dsl.module


Expand All @@ -22,7 +24,7 @@ val appModule = module {
viewModel { MainViewModel(get(), get()) }
viewModel { WebViewModel(get(), get()) }
single { IamportReceiver() }
single { Gson() }
single(named("${CONST.KOIN_KEY}Gson")) { Gson() }

single { StrategyRepository() }
single { WebViewLiveDataEventBus() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import com.google.gson.Gson
import com.iamport.sdk.data.sdk.IamPortResponse
import com.iamport.sdk.data.sdk.Payment
import com.iamport.sdk.domain.di.IamportKoinComponent
import com.iamport.sdk.domain.utils.CONST
import com.iamport.sdk.domain.utils.Event
import com.iamport.sdk.domain.utils.NativeLiveDataEventBus
import kotlinx.coroutines.CancellationException
import org.koin.core.component.KoinApiExtension
import org.koin.core.component.inject
import org.koin.core.qualifier.named

@KoinApiExtension
abstract class BaseStrategy : IStrategy, IamportKoinComponent {

protected val gson: Gson by inject()
protected val gson: Gson by inject(named("${CONST.KOIN_KEY}Gson"))
protected val bus: NativeLiveDataEventBus by inject()
lateinit var payment: Payment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import com.orhanobut.logger.Logger
import com.orhanobut.logger.Logger.d
import org.koin.core.component.KoinApiExtension
import org.koin.core.component.inject
import org.koin.core.qualifier.named

@KoinApiExtension
open class BaseWebViewStrategy : WebViewClient(), IStrategy, IamportKoinComponent {

protected val gson: Gson by inject()
protected val gson: Gson by inject(named("${CONST.KOIN_KEY}Gson"))
protected val bus: WebViewLiveDataEventBus by inject()

lateinit var payment: Payment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import kotlinx.coroutines.withContext
import org.koin.core.component.KoinApiExtension
import org.koin.core.component.get
import org.koin.core.component.inject
import org.koin.core.qualifier.named
import java.util.concurrent.atomic.AtomicInteger

// TODO: 12/1/20 구조 좀 정리하기 ㅠㅠ 너무 복잡 ㅠㅠ
Expand Down Expand Up @@ -385,7 +386,7 @@ open class ChaiStrategy : BaseStrategy() {
if (code == 0) {
data.run {
prepareData = this
chaiApi = provideChaiApi(mode == CHAI.MODE, get(), get()) // mode 에 따라 chaiApi 생성
chaiApi = provideChaiApi(mode == CHAI.MODE, get(named("${CONST.KOIN_KEY}Gson")), get(named("${CONST.KOIN_KEY}provideOkHttpClient"))) // mode 에 따라 chaiApi 생성
returnUrl?.let { bus.chaiUri.value = Event(it) }
}
} else {
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/java/com/iamport/sdk/domain/utils/CONST.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.iamport.sdk.domain.utils

object CONST {
const val KOIN_KEY = "iamport-koin-key"
const val APP_SCHME = "iamport_android"
const val HTTP_SCHEME = "http"
const val HTTPS_SCHEME = "https"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import com.orhanobut.logger.Logger.*
import kotlinx.coroutines.*
import org.koin.core.component.KoinApiExtension
import org.koin.core.component.get
import org.koin.core.qualifier.named


@KoinApiExtension
class IamPortWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICoroutineScope()) :
class IamPortWebViewMode @JvmOverloads constructor(scope: BaseCoroutineScope = UICoroutineScope()) :
IamportKoinComponent, BaseCoroutineScope by scope {

// override val viewModel: WebViewModel by viewModel()
Expand Down Expand Up @@ -100,16 +101,16 @@ class IamPortWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor
payment?.let { pay: Payment ->
activity?.run {

i("등록하니?")
d("등록하니?")

viewModel.payment().observe(this, EventObserver(this@IamPortWebView::requestPayment))
viewModel.loading().observe(this, EventObserver(this@IamPortWebView::loadingVisible))
viewModel.payment().observe(this, EventObserver(this@IamPortWebViewMode::requestPayment))
viewModel.loading().observe(this, EventObserver(this@IamPortWebViewMode::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.openWebView().observe(this, EventObserver(this@IamPortWebViewMode::openWebView))
viewModel.niceTransRequestParam().observe(this, EventObserver(this@IamPortWebViewMode::openNiceTransApp))
viewModel.thirdPartyUri().observe(this, EventObserver(this@IamPortWebViewMode::openThirdPartyApp))

viewModel.impResponse().observe(this, EventObserver(this@IamPortWebView::sdkFinish))
viewModel.impResponse().observe(this, EventObserver(this@IamPortWebViewMode::sdkFinish))

viewModel.startPayment(pay)
}
Expand All @@ -127,7 +128,7 @@ class IamPortWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor
* 결제 요청 실행
*/
private fun requestPayment(it: Payment) {
i("나왔니??")
d("나왔니??")
loadingVisible(true)
activity?.run {
if (!Util.isInternetAvailable(this)) {
Expand Down Expand Up @@ -167,7 +168,7 @@ class IamPortWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor
// activity?.setResult(Activity.RESULT_OK,
// Intent().apply { putExtra(CONST.CONTRACT_OUTPUT, iamPortResponse) })
// activity?.finish()
Iamport.callback(iamPortResponse)
Iamport.callback.invoke(iamPortResponse)
}

/**
Expand Down Expand Up @@ -249,7 +250,7 @@ class IamPortWebView @JvmOverloads constructor(scope: BaseCoroutineScope = UICor
setLayerType(View.LAYER_TYPE_HARDWARE, null)
clearCache(true)
addJavascriptInterface(
JsNativeInterface(payment, get(), get(), evaluateJS),
JsNativeInterface(payment, get(named("${CONST.KOIN_KEY}Gson")), get(), evaluateJS),
CONST.PAYMENT_WEBVIEW_JS_INTERFACE_NAME
)
webViewClient = viewModel.getWebViewClient(payment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ internal class IamportSdk(
clearData()
webview?.let { webView ->
hostHelper.activity?.let { activity ->
IamPortWebView().initStart(activity, webView, it) // webview only 모드
IamPortWebViewMode().initStart(activity, webView, it) // webview only 모드
} ?: run {
w("Cannot found activity, So running activity mode")
webViewLauncher?.launch(it) // new activity 모드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import android.view.View
import android.widget.ProgressBar
import androidx.lifecycle.viewModelScope
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.iamport.sdk.R
import com.iamport.sdk.data.sdk.IamPortResponse
Expand All @@ -23,6 +24,7 @@ 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.qualifier.named


@KoinApiExtension
Expand Down Expand Up @@ -225,7 +227,7 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding, WebViewModel>(), Ia
setLayerType(View.LAYER_TYPE_HARDWARE, null)
clearCache(true)
addJavascriptInterface(
JsNativeInterface(payment, get(), get(), evaluateJS),
JsNativeInterface(payment, get(named("${CONST.KOIN_KEY}Gson")), get(), evaluateJS),
CONST.PAYMENT_WEBVIEW_JS_INTERFACE_NAME
)
webViewClient = viewModel.getWebViewClient(payment)
Expand Down
16 changes: 16 additions & 0 deletions sdk/src/main/res/values-v26/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<resources>
<!-- 투명 액티비티 (웹뷰용) -->
<style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">false</item>

<item name="android:windowBackground">@android:color/transparent</item>

<item name="android:windowContentOverlay">@null</item>

<item name="android:windowNoTitle">true</item>

<item name="android:windowIsFloating">false</item>

<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
16 changes: 16 additions & 0 deletions sdk/src/main/res/values-v27/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<resources>
<!-- 투명 액티비티 (웹뷰용) -->
<style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>

<item name="android:windowBackground">@android:color/transparent</item>

<item name="android:windowContentOverlay">@null</item>

<item name="android:windowNoTitle">true</item>

<item name="android:windowIsFloating">false</item>

<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion sdk/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<!-- 투명 액티비티 (웹뷰용) -->
<!-- 투명 액티비티 (웹뷰용) -->
<style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>

Expand Down

0 comments on commit a8e5d37

Please sign in to comment.