Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FC] Moves Activities and some Panes out of Mavericks #8125

Merged
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8669051
Removes mackericks references on Consent screen.
carlosmuvi-stripe Mar 19, 2024
be1f31f
Updates files.
carlosmuvi-stripe Mar 19, 2024
897109c
Uses viewmodel factory builder.
carlosmuvi-stripe Mar 19, 2024
2f309d6
Updates functions.
carlosmuvi-stripe Mar 19, 2024
deecbdb
Updates execute.
carlosmuvi-stripe Mar 19, 2024
d2f6bf4
Updates compose util.
carlosmuvi-stripe Mar 19, 2024
a825667
Adds missing side effects.
carlosmuvi-stripe Mar 19, 2024
7bd7df5
Simplifies code.
carlosmuvi-stripe Mar 19, 2024
01dff60
Renames viewmodel.
carlosmuvi-stripe Mar 19, 2024
a10a111
Updates async.
carlosmuvi-stripe Mar 19, 2024
420fbe7
Removes mavericks from institution picker.
carlosmuvi-stripe Mar 19, 2024
bddfb55
Reverts rename.
carlosmuvi-stripe Mar 19, 2024
d0ce301
Updates baseline.
carlosmuvi-stripe Mar 19, 2024
32203df
Adds setState and persists state.
carlosmuvi-stripe Mar 20, 2024
dc1e4e5
Renames result error to fail.
carlosmuvi-stripe Mar 20, 2024
cfff17f
Migrates Initial activity out of mavericks.
carlosmuvi-stripe Mar 20, 2024
bc737a8
Removes persist state.
carlosmuvi-stripe Mar 20, 2024
ce3643e
Updates tests.
carlosmuvi-stripe Mar 20, 2024
f1d8ca2
Regenerates API.
carlosmuvi-stripe Mar 21, 2024
35bcd35
filterNotNull.
carlosmuvi-stripe Mar 21, 2024
0f39b41
Nits.
carlosmuvi-stripe Mar 21, 2024
59a645c
Updates async.
carlosmuvi-stripe Mar 21, 2024
85bc66b
use suspend block.
carlosmuvi-stripe Mar 21, 2024
a019f4a
Update financial-connections/src/main/java/com/stripe/android/financi…
carlosmuvi-stripe Mar 21, 2024
eb82caf
Tries onAsync.
carlosmuvi-stripe Mar 22, 2024
0d0c270
Moves activity to stripe ui core.
carlosmuvi-stripe Mar 22, 2024
d060b53
PR feedback.
carlosmuvi-stripe Mar 22, 2024
1e1d5e7
Regenerates deps.
carlosmuvi-stripe Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion financial-connections/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
<ID>SwallowedException:PostAuthorizationSession.kt$PostAuthorizationSession$e: StripeException</ID>
<ID>TooManyFunctions:FinancialConnectionsManifestRepository.kt$FinancialConnectionsManifestRepository</ID>
<ID>TooManyFunctions:FinancialConnectionsManifestRepository.kt$FinancialConnectionsManifestRepositoryImpl : FinancialConnectionsManifestRepository</ID>
<ID>TooManyFunctions:FinancialConnectionsSheetNativeViewModel.kt$FinancialConnectionsSheetNativeViewModel : MavericksViewModel</ID>
<ID>TooManyFunctions:FinancialConnectionsSheetNativeViewModel.kt$FinancialConnectionsSheetNativeViewModel : FinancialConnectionsViewModel</ID>
</CurrentIssues>
</SmellBaseline>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.widget.Toast
import androidx.activity.addCallback
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -15,9 +16,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.withState
import com.stripe.android.financialconnections.FinancialConnectionsSheetViewEffect.FinishWithResult
import com.stripe.android.financialconnections.FinancialConnectionsSheetViewEffect.OpenAuthFlowWithUrl
import com.stripe.android.financialconnections.FinancialConnectionsSheetViewEffect.OpenNativeAuthFlow
Expand All @@ -29,11 +31,16 @@ import com.stripe.android.financialconnections.launcher.FinancialConnectionsShee
import com.stripe.android.financialconnections.ui.FinancialConnectionsSheetNativeActivity
import com.stripe.android.financialconnections.ui.theme.FinancialConnectionsTheme
import com.stripe.android.financialconnections.utils.argsOrNull
import com.stripe.android.financialconnections.utils.viewModelLazy
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

internal class FinancialConnectionsSheetActivity : AppCompatActivity(), MavericksView {
internal class FinancialConnectionsSheetActivity : AppCompatActivity() {

val viewModel: FinancialConnectionsSheetViewModel by viewModelLazy()
val viewModel: FinancialConnectionsSheetViewModel by viewModels(
factoryProducer = { FinancialConnectionsSheetViewModel.Factory }
)

val args by argsOrNull<FinancialConnectionsSheetActivityArgs>()

Expand All @@ -52,7 +59,7 @@ internal class FinancialConnectionsSheetActivity : AppCompatActivity(), Maverick
if (args == null) {
finish()
} else {
viewModel.onEach { postInvalidate() }
observeViewEffects()
browserManager = BrowserManager(application)
if (savedInstanceState != null) viewModel.onActivityRecreated()
}
Expand Down Expand Up @@ -91,42 +98,55 @@ internal class FinancialConnectionsSheetActivity : AppCompatActivity(), Maverick
/**
* handle state changes here.
*/
override fun invalidate() {
withState(viewModel) { state ->
state.viewEffect?.let { viewEffect ->
when (viewEffect) {
is OpenAuthFlowWithUrl -> startBrowserForResult.launch(
browserManager.createBrowserIntentForUrl(
uri = Uri.parse(viewEffect.url)

private fun observeViewEffects() = lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.stateFlow
.map { it.viewEffect }
.distinctUntilChanged()
.filterNotNull()
.collect { viewEffect ->
when (viewEffect) {
is OpenAuthFlowWithUrl -> startBrowserForResult.launch(
browserManager.createBrowserIntentForUrl(
uri = Uri.parse(viewEffect.url)
)
)
)

is FinishWithResult -> {
viewEffect.finishToast?.let {
Toast.makeText(this, it, Toast.LENGTH_LONG).show()
is FinishWithResult -> {
viewEffect.finishToast?.let { resId ->
Toast.makeText(
this@FinancialConnectionsSheetActivity,
resId,
Toast.LENGTH_LONG
).show()
}
finishWithResult(viewEffect.result)
}
finishWithResult(viewEffect.result)

is OpenNativeAuthFlow -> openNativeAuthFlow(viewEffect)
}
viewModel.onViewEffectLaunched()
}
}
}

is OpenNativeAuthFlow -> startNativeAuthFlowForResult.launch(
Intent(
this,
FinancialConnectionsSheetNativeActivity::class.java
).also {
it.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
it.putExtra(
Mavericks.KEY_ARG,
FinancialConnectionsSheetNativeActivityArgs(
initialSyncResponse = viewEffect.initialSyncResponse,
configuration = viewEffect.configuration
)
)
}
private fun openNativeAuthFlow(viewEffect: OpenNativeAuthFlow) {
startNativeAuthFlowForResult.launch(
Intent(
this@FinancialConnectionsSheetActivity,
FinancialConnectionsSheetNativeActivity::class.java
).also {
it.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
it.putExtra(
Mavericks.KEY_ARG,
FinancialConnectionsSheetNativeActivityArgs(
initialSyncResponse = viewEffect.initialSyncResponse,
configuration = viewEffect.configuration
)
}
viewModel.onViewEffectLaunched()
)
}
}
)
}

private fun finishWithResult(result: FinancialConnectionsSheetActivityResult) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.stripe.android.financialconnections

import android.os.Bundle
import androidx.annotation.StringRes
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.PersistState
import com.stripe.android.financialconnections.launcher.FinancialConnectionsSheetActivityArgs
import com.stripe.android.financialconnections.launcher.FinancialConnectionsSheetActivityResult
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest
Expand All @@ -13,15 +13,28 @@ import com.stripe.android.financialconnections.model.SynchronizeSessionResponse
*/
internal data class FinancialConnectionsSheetState(
val initialArgs: FinancialConnectionsSheetActivityArgs,
val activityRecreated: Boolean = false,
@PersistState val manifest: FinancialConnectionsSessionManifest? = null,
@PersistState val webAuthFlowStatus: AuthFlowStatus = AuthFlowStatus.NONE,
val viewEffect: FinancialConnectionsSheetViewEffect? = null
val activityRecreated: Boolean,
val manifest: FinancialConnectionsSessionManifest?,
val webAuthFlowStatus: AuthFlowStatus,
val viewEffect: FinancialConnectionsSheetViewEffect?
) : MavericksState {

val sessionSecret: String
get() = initialArgs.configuration.financialConnectionsSessionClientSecret

/**
* Constructor used to build the initial state.
*/
constructor(args: FinancialConnectionsSheetActivityArgs, savedState: Bundle?) : this(
initialArgs = args,
activityRecreated = false,
manifest = savedState?.getParcelable(KEY_MANIFEST),
webAuthFlowStatus = savedState?.getSerializable(KEY_WEB_AUTH_FLOW_STATUS)
as? AuthFlowStatus
?: AuthFlowStatus.NONE,
viewEffect = null
)

enum class AuthFlowStatus {
/**
* AuthFlow is happening outside of the SDK (app2app, web browser, etc).
Expand All @@ -47,12 +60,11 @@ internal data class FinancialConnectionsSheetState(
NONE
}

/**
* Constructor used by Mavericks to build the initial state.
*/
constructor(args: FinancialConnectionsSheetActivityArgs) : this(
initialArgs = args
)
companion object {
const val KEY_SAVED_STATE = "financial_connections_sheet_state"
const val KEY_MANIFEST = "financial_connections_sheet_manifest"
const val KEY_WEB_AUTH_FLOW_STATUS = "financial_connections_sheet_web_auth_flow_status"
}
}

/**
Expand Down
Loading
Loading