-
Notifications
You must be signed in to change notification settings - Fork 662
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
native link dagger setup #9465
Merged
Merged
native link dagger setup #9465
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7a1a890
native link dagger setup
toluo-stripe 9e5d387
migrate from NativeLinkEnabled to FeatureFlag
toluo-stripe 29a6ca9
remove link dependency
toluo-stripe 5821589
use feature flag test rule
toluo-stripe 63a83fd
unit tests for viewmodel factory
toluo-stripe da1e5e5
Suppress swallowed exception
toluo-stripe 56ca299
remove suppress
toluo-stripe 0acbd76
api dump
toluo-stripe 1b170a6
Use logger instead of log
toluo-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,71 @@ | ||
package com.stripe.android.link | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.viewModels | ||
import androidx.annotation.VisibleForTesting | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.core.os.bundleOf | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
import com.stripe.android.core.Logger | ||
import com.stripe.android.link.ui.cardedit.CardEditScreen | ||
import com.stripe.android.link.ui.paymentmenthod.PaymentMethodScreen | ||
import com.stripe.android.link.ui.signup.SignUpScreen | ||
import com.stripe.android.link.ui.verification.VerificationScreen | ||
import com.stripe.android.link.ui.wallet.WalletScreen | ||
import com.stripe.android.ui.core.CircularProgressIndicator | ||
|
||
internal class LinkActivity : AppCompatActivity() { | ||
@VisibleForTesting | ||
internal var viewModelFactory: ViewModelProvider.Factory = LinkActivityViewModel.Factory() | ||
private val viewModel: LinkActivityViewModel by viewModels { viewModelFactory } | ||
internal class LinkActivity : ComponentActivity() { | ||
internal var viewModel: LinkActivityViewModel? = null | ||
|
||
@VisibleForTesting | ||
internal lateinit var navController: NavHostController | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
try { | ||
viewModel = ViewModelProvider(this, LinkActivityViewModel.factory())[LinkActivityViewModel::class.java] | ||
} catch (e: NoArgsException) { | ||
Logger.getInstance(BuildConfig.DEBUG).error("Failed to create LinkActivityViewModel", e) | ||
setResult(Activity.RESULT_CANCELED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this canceled instead of being a failure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the pattern here, but I'm happy to change it to a failure |
||
finish() | ||
} | ||
|
||
setContent { | ||
navController = rememberNavController() | ||
|
||
LaunchedEffect(Unit) { | ||
viewModel.navController = navController | ||
viewModel.dismissWithResult = ::dismissWithResult | ||
viewModel?.navController = navController | ||
viewModel?.dismissWithResult = ::dismissWithResult | ||
} | ||
|
||
NavHost( | ||
navController = navController, | ||
startDestination = LinkScreen.SignUp.route | ||
startDestination = LinkScreen.Loading.route | ||
) { | ||
composable(LinkScreen.Loading.route) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
CircularProgressIndicator() | ||
} | ||
} | ||
|
||
composable(LinkScreen.SignUp.route) { | ||
SignUpScreen() | ||
} | ||
|
@@ -79,6 +102,22 @@ internal class LinkActivity : AppCompatActivity() { | |
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
viewModel.unregisterActivity() | ||
viewModel?.unregisterActivity() | ||
} | ||
|
||
companion object { | ||
internal const val EXTRA_ARGS = "native_link_args" | ||
|
||
internal fun createIntent( | ||
context: Context, | ||
args: NativeLinkArgs | ||
): Intent { | ||
return Intent(context, LinkActivity::class.java) | ||
.putExtra(EXTRA_ARGS, args) | ||
} | ||
|
||
internal fun getArgs(savedStateHandle: SavedStateHandle): NativeLinkArgs? { | ||
return savedStateHandle.get<NativeLinkArgs>(EXTRA_ARGS) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
link/src/main/java/com/stripe/android/link/NativeLinkArgs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.stripe.android.link | ||
|
||
import android.os.Parcelable | ||
import androidx.annotation.RestrictTo | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
@Parcelize | ||
internal data class NativeLinkArgs( | ||
val configuration: LinkConfiguration, | ||
val publishableKey: String, | ||
val stripeAccountId: String? | ||
) : Parcelable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
link/src/main/java/com/stripe/android/link/injection/NativeLinkComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.stripe.android.link.injection | ||
|
||
import android.content.Context | ||
import com.stripe.android.core.Logger | ||
import com.stripe.android.core.injection.PUBLISHABLE_KEY | ||
import com.stripe.android.core.injection.STRIPE_ACCOUNT_ID | ||
import com.stripe.android.link.LinkActivityViewModel | ||
import com.stripe.android.link.LinkConfiguration | ||
import com.stripe.android.link.account.LinkAccountManager | ||
import com.stripe.android.link.analytics.LinkEventsReporter | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
import javax.inject.Named | ||
import javax.inject.Scope | ||
|
||
@Scope | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class NativeLinkScope | ||
|
||
@NativeLinkScope | ||
@Component( | ||
modules = [ | ||
NativeLinkModule::class, | ||
] | ||
) | ||
internal interface NativeLinkComponent { | ||
val linkAccountManager: LinkAccountManager | ||
val configuration: LinkConfiguration | ||
val linkEventsReporter: LinkEventsReporter | ||
val logger: Logger | ||
val viewModel: LinkActivityViewModel | ||
|
||
@Component.Builder | ||
interface Builder { | ||
@BindsInstance | ||
fun configuration(configuration: LinkConfiguration): Builder | ||
|
||
@BindsInstance | ||
fun publishableKeyProvider(@Named(PUBLISHABLE_KEY) publishableKeyProvider: () -> String): Builder | ||
|
||
@BindsInstance | ||
fun stripeAccountIdProvider(@Named(STRIPE_ACCOUNT_ID) stripeAccountIdProvider: () -> String?): Builder | ||
|
||
@BindsInstance | ||
fun context(context: Context): Builder | ||
|
||
fun build(): NativeLinkComponent | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this a
lateinit
variable? I think then you won't need to make the type nullableThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it nullable because
onDestroy
will get called when we finish the activity andviewModel.unregisterActivity()
will crash since it's not initializedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh gotcha, thanks