Skip to content

Commit

Permalink
Adds activityRetainedScope
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmuvi-stripe committed Jan 10, 2025
1 parent 580f744 commit 6405e3c
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.stripe.android.financialconnections.analytics.logError
import com.stripe.android.financialconnections.browser.BrowserManager
import com.stripe.android.financialconnections.di.APPLICATION_ID
import com.stripe.android.financialconnections.di.DaggerFinancialConnectionsSheetComponent
import com.stripe.android.financialconnections.di.FinancialConnectionsSingletonSharedComponentHolder
import com.stripe.android.financialconnections.domain.FetchFinancialConnectionsSession
import com.stripe.android.financialconnections.domain.FetchFinancialConnectionsSessionForToken
import com.stripe.android.financialconnections.domain.GetOrFetchSync
Expand Down Expand Up @@ -529,6 +530,7 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
.builder()
.application(app)
.savedStateHandle(savedStateHandle)
.sharedComponent(FinancialConnectionsSingletonSharedComponentHolder.getComponent(app))
.initialState(state)
.configuration(state.initialArgs.configuration)
.build().viewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.stripe.android.financialconnections.di

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)
internal annotation class ActivityRetainedScope
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +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 All @@ -37,6 +33,8 @@ internal interface FinancialConnectionsSheetComponent {
@BindsInstance
fun configuration(configuration: FinancialConnectionsSheet.Configuration): Builder

fun sharedComponent(component: FinancialConnectionsSingletonSharedComponent): Builder

fun build(): FinancialConnectionsSheetComponent
}
}
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,15 +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 Expand Up @@ -91,6 +87,8 @@ internal interface FinancialConnectionsSheetNativeComponent {
@BindsInstance
fun configuration(configuration: FinancialConnectionsSheet.Configuration): Builder

fun sharedComponent(component: FinancialConnectionsSingletonSharedComponent): Builder

fun build(): FinancialConnectionsSheetNativeComponent
}
}
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
Loading

0 comments on commit 6405e3c

Please sign in to comment.