Skip to content

Commit

Permalink
Adds activityRetainedScope
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmuvi-stripe committed Dec 23, 2024
1 parent 479f2eb commit 04b27ef
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
package com.stripe.android.financialconnections.di

class ActivityRetainedScope {
}
import javax.inject.Scope

/**
* Scope annotation for bindings that should exist for the life of an activity, surviving configuration.
*
* Note: Dependencies scoped to this won't be shared across activities.
*/
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ActivityRetainedScope
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ package com.stripe.android.financialconnections.di

import android.app.Application
import androidx.lifecycle.SavedStateHandle
import com.stripe.android.core.injection.CoreCommonModule
import com.stripe.android.core.injection.CoroutineContextModule
import com.stripe.android.financialconnections.FinancialConnectionsSheet
import com.stripe.android.financialconnections.FinancialConnectionsSheetState
import com.stripe.android.financialconnections.FinancialConnectionsSheetViewModel
import dagger.BindsInstance
import dagger.Component
import javax.inject.Singleton

@Singleton
@ActivityRetainedScope
@Component(
dependencies = [FinancialConnectionsSingletonSharedComponent::class],
modules = [
FinancialConnectionsSheetModule::class,
FinancialConnectionsSheetSharedModule::class,
CoroutineContextModule::class,
CoreCommonModule::class
]
)
internal interface FinancialConnectionsSheetComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,38 @@ import com.stripe.android.financialconnections.FinancialConnectionsSheet
import dagger.Module
import dagger.Provides
import javax.inject.Named
import javax.inject.Singleton

@Module
internal object FinancialConnectionsSheetConfigurationModule {

@Provides
@Named(PUBLISHABLE_KEY)
@Singleton
@ActivityRetainedScope
fun providesPublishableKey(
configuration: FinancialConnectionsSheet.Configuration
): String = configuration.publishableKey

@Provides
@Named(STRIPE_ACCOUNT_ID)
@Singleton
@ActivityRetainedScope
fun providesStripeAccountId(
configuration: FinancialConnectionsSheet.Configuration
): String? = configuration.stripeAccountId

@Provides
@Named(ENABLE_LOGGING)
@Singleton
@ActivityRetainedScope
fun providesEnableLogging(): Boolean = BuildConfig.DEBUG

@Provides
@Singleton
@ActivityRetainedScope
@Named(APPLICATION_ID)
fun providesApplicationId(
application: Application
): String = application.packageName

@Provides
@Singleton
@ActivityRetainedScope
fun providesApiVersion(): ApiVersion = ApiVersion(
betas = setOf("financial_connections_client_api_beta=v1")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import com.stripe.android.financialconnections.repository.api.ProvideApiRequestO
import dagger.Module
import dagger.Provides
import java.util.Locale
import javax.inject.Singleton

@Module
internal object FinancialConnectionsSheetModule {

@Singleton
@ActivityRetainedScope
@Provides
internal fun providesProvideApiRequestOptions(
apiRequestOptions: ApiRequest.Options,
Expand All @@ -22,7 +21,7 @@ internal object FinancialConnectionsSheetModule {
return ProvideApiRequestOptions { apiRequestOptions }
}

@Singleton
@ActivityRetainedScope
@Provides
fun providesFinancialConnectionsManifestRepository(
requestExecutor: FinancialConnectionsRequestExecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.stripe.android.financialconnections.di

import android.app.Application
import androidx.lifecycle.SavedStateHandle
import com.stripe.android.core.injection.CoreCommonModule
import com.stripe.android.core.injection.CoroutineContextModule
import com.stripe.android.financialconnections.FinancialConnectionsSheet
import com.stripe.android.financialconnections.features.accountpicker.AccountPickerViewModel
import com.stripe.android.financialconnections.features.accountupdate.AccountUpdateRequiredViewModel
Expand Down Expand Up @@ -32,16 +30,13 @@ import com.stripe.android.financialconnections.ui.FinancialConnectionsSheetNativ
import dagger.BindsInstance
import dagger.Component
import javax.inject.Named
import javax.inject.Singleton

@Singleton
@ActivityRetainedScope
@Component(
dependencies = [FinancialConnectionsSingletonSharedComponent::class],
modules = [
FinancialConnectionsSheetNativeModule::class,
FinancialConnectionsSheetSharedModule::class,
CoreCommonModule::class,
CoroutineContextModule::class
FinancialConnectionsSheetSharedModule::class
]
)
internal interface FinancialConnectionsSheetNativeComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ import dagger.Provides
import java.util.Locale
import javax.inject.Named
import javax.inject.Provider
import javax.inject.Singleton

@Module
internal interface FinancialConnectionsSheetNativeModule {

@Binds
fun bindsPresentNoticeSheet(impl: RealPresentSheet): PresentSheet

@Singleton
@ActivityRetainedScope
@Binds
fun bindsNavigationManager(
impl: NavigationManagerImpl
Expand All @@ -63,7 +62,7 @@ internal interface FinancialConnectionsSheetNativeModule {
): HandleError

@Binds
@Singleton
@ActivityRetainedScope
fun bindsProvideApiRequestOptions(impl: RealProvideApiRequestOptions): ProvideApiRequestOptions

@Binds
Expand All @@ -78,7 +77,7 @@ internal interface FinancialConnectionsSheetNativeModule {

companion object {
@Provides
@Singleton
@ActivityRetainedScope
fun provideConsumersApiService(
apiVersion: ApiVersion,
stripeNetworkClient: StripeNetworkClient,
Expand All @@ -89,7 +88,7 @@ internal interface FinancialConnectionsSheetNativeModule {
stripeNetworkClient = stripeNetworkClient
)

@Singleton
@ActivityRetainedScope
@Provides
fun providesImageLoader(
context: Application
Expand All @@ -98,7 +97,7 @@ internal interface FinancialConnectionsSheetNativeModule {
diskCache = null,
)

@Singleton
@ActivityRetainedScope
@Provides
fun providesFinancialConnectionsManifestRepository(
requestExecutor: FinancialConnectionsRequestExecutor,
Expand All @@ -116,7 +115,7 @@ internal interface FinancialConnectionsSheetNativeModule {
initialSync = initialSynchronizeSessionResponse
)

@Singleton
@ActivityRetainedScope
@Provides
fun providesFinancialConnectionsConsumerSessionRepository(
consumersApiService: ConsumersApiService,
Expand All @@ -140,7 +139,7 @@ internal interface FinancialConnectionsSheetNativeModule {
elementsSessionContext = elementsSessionContext,
)

@Singleton
@ActivityRetainedScope
@Provides
fun providesFinancialConnectionsAccountsRepository(
requestExecutor: FinancialConnectionsRequestExecutor,
Expand All @@ -156,7 +155,7 @@ internal interface FinancialConnectionsSheetNativeModule {
savedStateHandle = savedStateHandle,
)

@Singleton
@ActivityRetainedScope
@Provides
fun providesFinancialConnectionsInstitutionsRepository(
requestExecutor: FinancialConnectionsRequestExecutor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.stripe.android.financialconnections.di

import android.app.Application
import androidx.core.os.LocaleListCompat
import com.stripe.android.core.ApiVersion
import com.stripe.android.core.Logger
import com.stripe.android.core.frauddetection.FraudDetectionDataRepository
import com.stripe.android.core.injection.ENABLE_LOGGING
import com.stripe.android.core.injection.IOContext
import com.stripe.android.core.injection.STRIPE_ACCOUNT_ID
import com.stripe.android.core.injection.UIContext
import com.stripe.android.core.networking.AnalyticsRequestExecutor
import com.stripe.android.core.networking.AnalyticsRequestFactory
import com.stripe.android.core.networking.AnalyticsRequestV2Executor
Expand Down Expand Up @@ -43,7 +46,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.serialization.json.Json
import java.util.Locale
import javax.inject.Named
import javax.inject.Singleton
import kotlin.coroutines.CoroutineContext

/**
Expand All @@ -66,19 +68,19 @@ import kotlin.coroutines.CoroutineContext
internal interface FinancialConnectionsSheetSharedModule {

@Binds
@Singleton
@ActivityRetainedScope
fun bindsAnalyticsRequestV2Storage(impl: RealAnalyticsRequestV2Storage): AnalyticsRequestV2Storage

@Binds
@Singleton
@ActivityRetainedScope
fun bindsAnalyticsRequestV2Executor(impl: DefaultAnalyticsRequestV2Executor): AnalyticsRequestV2Executor

@Binds
@Singleton
@ActivityRetainedScope
fun bindsConsumerSessionRepository(impl: RealConsumerSessionRepository): ConsumerSessionRepository

@Binds
@Singleton
@ActivityRetainedScope
fun bindsConsumerSessionProvider(impl: RealConsumerSessionRepository): ConsumerSessionProvider

@Binds
Expand All @@ -87,7 +89,27 @@ internal interface FinancialConnectionsSheetSharedModule {
companion object {

@Provides
@Singleton
@ActivityRetainedScope
@IOContext
fun provideWorkContext(): CoroutineContext = Dispatchers.IO

@Provides
@ActivityRetainedScope
@UIContext
fun provideUIContext(): CoroutineContext = Dispatchers.Main

@Provides
@ActivityRetainedScope
internal fun provideLogger(@Named(ENABLE_LOGGING) enableLogging: Boolean) =
Logger.getInstance(enableLogging)

@Provides
@ActivityRetainedScope
internal fun provideLocale() =
LocaleListCompat.getAdjustedDefault().takeUnless { it.isEmpty }?.get(0)

@Provides
@ActivityRetainedScope
internal fun providesApiOptions(
@Named(PUBLISHABLE_KEY) publishableKey: String,
@Named(STRIPE_ACCOUNT_ID) stripeAccountId: String?
Expand All @@ -97,7 +119,7 @@ internal interface FinancialConnectionsSheetSharedModule {
)

@Provides
@Singleton
@ActivityRetainedScope
internal fun providesJson(): Json = Json {
coerceInputValues = true
ignoreUnknownKeys = true
Expand All @@ -106,7 +128,7 @@ internal interface FinancialConnectionsSheetSharedModule {
}

@Provides
@Singleton
@ActivityRetainedScope
fun provideStripeNetworkClient(
@IOContext context: CoroutineContext,
logger: Logger
Expand All @@ -115,8 +137,8 @@ internal interface FinancialConnectionsSheetSharedModule {
logger = logger
)

@Singleton
@Provides
@ActivityRetainedScope
fun providesAnalyticsTracker(
context: Application,
getOrFetchSync: GetOrFetchSync,
Expand All @@ -132,33 +154,33 @@ internal interface FinancialConnectionsSheetSharedModule {
)

@Provides
@Singleton
@ActivityRetainedScope
fun providesApiRequestFactory(
apiVersion: ApiVersion
): ApiRequest.Factory = ApiRequest.Factory(
apiVersion = apiVersion.code
)

@Provides
@Singleton
@ActivityRetainedScope
fun provideConnectionsRepository(
repository: FinancialConnectionsRepositoryImpl
): FinancialConnectionsRepository = repository

@Provides
@Singleton
@ActivityRetainedScope
fun provideEventReporter(
defaultFinancialConnectionsEventReporter: DefaultFinancialConnectionsEventReporter
): FinancialConnectionsEventReporter = defaultFinancialConnectionsEventReporter

@Provides
@Singleton
@ActivityRetainedScope
internal fun providesAnalyticsRequestExecutor(
executor: DefaultAnalyticsRequestExecutor
): AnalyticsRequestExecutor = executor

@Provides
@Singleton
@ActivityRetainedScope
internal fun provideAnalyticsRequestFactory(
application: Application,
@Named(PUBLISHABLE_KEY) publishableKey: String
Expand All @@ -171,7 +193,7 @@ internal interface FinancialConnectionsSheetSharedModule {
)

@Provides
@Singleton
@ActivityRetainedScope
internal fun providesIsWorkManagerAvailable(
getOrFetchSync: GetOrFetchSync,
): IsWorkManagerAvailable {
Expand All @@ -181,7 +203,7 @@ internal interface FinancialConnectionsSheetSharedModule {
}

@Provides
@Singleton
@ActivityRetainedScope
internal fun providesIoDispatcher(): CoroutineDispatcher {
return Dispatchers.IO
}
Expand Down
Loading

0 comments on commit 04b27ef

Please sign in to comment.