@@ -4,8 +4,8 @@ import android.net.Uri
44import android.os.Build
55import com.pandulapeter.beagle.logOkHttp.BeagleOkHttpLogger
66import com.squareup.moshi.Moshi
7+ import com.tinder.scarlet.Lifecycle
78import com.tinder.scarlet.Scarlet
8- import com.tinder.scarlet.lifecycle.LifecycleRegistry
99import com.tinder.scarlet.lifecycle.android.AndroidLifecycle
1010import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter
1111import com.tinder.scarlet.retry.ExponentialBackoffStrategy
@@ -16,7 +16,6 @@ import com.walletconnect.android.internal.common.connection.ManualConnectionLife
1616import com.walletconnect.android.internal.common.jwt.clientid.GenerateJwtStoreClientIdUseCase
1717import com.walletconnect.android.relay.ConnectionType
1818import com.walletconnect.android.relay.NetworkClientTimeout
19- import com.walletconnect.foundation.network.data.ConnectionController
2019import com.walletconnect.foundation.network.data.adapter.FlowStreamAdapter
2120import com.walletconnect.foundation.network.data.service.RelayService
2221import okhttp3.Authenticator
@@ -25,6 +24,7 @@ import okhttp3.OkHttpClient
2524import okhttp3.logging.HttpLoggingInterceptor
2625import org.koin.android.ext.koin.androidApplication
2726import org.koin.core.qualifier.named
27+ import org.koin.core.scope.Scope
2828import org.koin.dsl.module
2929import java.util.concurrent.TimeUnit
3030
@@ -104,20 +104,12 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType,
104104
105105 single(named(AndroidCommonDITags .MSG_ADAPTER )) { MoshiMessageAdapter .Factory (get<Moshi .Builder >(named(AndroidCommonDITags .MOSHI )).build()) }
106106
107- single(named(AndroidCommonDITags .CONNECTION_CONTROLLER )) {
108- if (connectionType == ConnectionType .MANUAL ) {
109- ConnectionController .Manual ()
110- } else {
111- ConnectionController .Automatic
112- }
107+ single<ManualConnectionLifecycle >(named(AndroidCommonDITags .MANUAL_CONNECTION_LIFECYCLE )) {
108+ ManualConnectionLifecycle ()
113109 }
114110
115- single(named(AndroidCommonDITags .LIFECYCLE )) {
116- if (connectionType == ConnectionType .MANUAL ) {
117- ManualConnectionLifecycle (get(named(AndroidCommonDITags .CONNECTION_CONTROLLER )), LifecycleRegistry ())
118- } else {
119- AndroidLifecycle .ofApplicationForeground(androidApplication())
120- }
111+ single<Lifecycle >(named(AndroidCommonDITags .AUTOMATIC_CONNECTION_LIFECYCLE )) {
112+ AndroidLifecycle .ofApplicationForeground(androidApplication())
121113 }
122114
123115 single { ExponentialBackoffStrategy (INIT_BACKOFF_MILLIS , TimeUnit .SECONDS .toMillis(MAX_BACKOFF_SEC )) }
@@ -128,7 +120,7 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType,
128120 Scarlet .Builder ()
129121 .backoffStrategy(get<ExponentialBackoffStrategy >())
130122 .webSocketFactory(get<OkHttpClient >(named(AndroidCommonDITags .OK_HTTP )).newWebSocketFactory(get<String >(named(AndroidCommonDITags .RELAY_URL ))))
131- .lifecycle(get(named( AndroidCommonDITags . LIFECYCLE ) ))
123+ .lifecycle(getLifecycle(connectionType ))
132124 .addMessageAdapterFactory(get<MoshiMessageAdapter .Factory >(named(AndroidCommonDITags .MSG_ADAPTER )))
133125 .addStreamAdapterFactory(get<FlowStreamAdapter .Factory >())
134126 .build()
@@ -141,4 +133,11 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType,
141133 single(named(AndroidCommonDITags .CONNECTIVITY_STATE )) {
142134 ConnectivityState (androidApplication())
143135 }
144- }
136+ }
137+
138+ private fun Scope.getLifecycle (connectionType : ConnectionType ) =
139+ if (connectionType == ConnectionType .MANUAL ) {
140+ get<ManualConnectionLifecycle >(named(AndroidCommonDITags .MANUAL_CONNECTION_LIFECYCLE ))
141+ } else {
142+ get<Lifecycle >(named(AndroidCommonDITags .AUTOMATIC_CONNECTION_LIFECYCLE ))
143+ }
0 commit comments