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

[Connect SDK] Update Connect example app to use Hilt dependency injection #9579

Merged
merged 5 commits into from
Nov 11, 2024

Conversation

simond-stripe
Copy link
Collaborator

Summary

Integrate Hilt into the example app.

Motivation

The connect example app is getting more complicated, and integrating Hilt will make it faster (and less error-prone) to test.

Testing

  • Added tests
  • Modified tests
  • Manually verified

I tested all of the flow (there aren't many of them) and tested that they still work + don't crash.

Screenshots

demo-1731098981.mp4

@simond-stripe simond-stripe marked this pull request as ready for review November 8, 2024 20:52
@simond-stripe simond-stripe requested review from a team as code owners November 8, 2024 20:52
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Risky Change

This is considered a risky change because it adjusts the sample app build.gradle, please review carefully.
We've seen issues in the past which resulted in failed builds for merchants. Please make sure the build.gradle change is intended.

By adding the label accept-risky-change to this PR, I acknowledge that I'm changing an example app and have verified that the SDK remains in a shippable state.

@simond-stripe simond-stripe added the accept-risky-change accept-risky-change label Nov 8, 2024
@simond-stripe simond-stripe changed the title Simond/connect example to hilt [Connect SDK] Update Connect example app to use Hilt dependency injection Nov 8, 2024
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Diffuse output:

OLD: paymentsheet-example-release-master.apk (signature: V1, V2)
NEW: paymentsheet-example-release-pr.apk (signature: V1, V2)

          │          compressed          │         uncompressed         
          ├───────────┬───────────┬──────┼───────────┬───────────┬──────
 APK      │ old       │ new       │ diff │ old       │ new       │ diff 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
      dex │   3.8 MiB │   3.8 MiB │  0 B │   8.4 MiB │   8.4 MiB │  0 B 
     arsc │   2.3 MiB │   2.3 MiB │  0 B │   2.3 MiB │   2.3 MiB │  0 B 
 manifest │     5 KiB │     5 KiB │  0 B │  24.9 KiB │  24.9 KiB │  0 B 
      res │ 902.2 KiB │ 902.2 KiB │  0 B │   1.4 MiB │   1.4 MiB │  0 B 
   native │   2.6 MiB │   2.6 MiB │  0 B │     6 MiB │     6 MiB │  0 B 
    asset │   1.6 MiB │   1.6 MiB │  0 B │   1.6 MiB │   1.6 MiB │  0 B 
    other │ 199.8 KiB │ 199.8 KiB │ -1 B │ 440.1 KiB │ 440.1 KiB │  0 B 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
    total │  11.4 MiB │  11.4 MiB │ -1 B │  20.2 MiB │  20.2 MiB │  0 B 

 DEX     │ old   │ new   │ diff      
─────────┼───────┼───────┼───────────
   files │     1 │     1 │ 0         
 strings │ 39758 │ 39758 │ 0 (+0 -0) 
   types │ 13711 │ 13711 │ 0 (+0 -0) 
 classes │ 11403 │ 11403 │ 0 (+0 -0) 
 methods │ 58601 │ 58601 │ 0 (+0 -0) 
  fields │ 38901 │ 38901 │ 0 (+0 -0) 

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  242 │  242 │  0   
 entries │ 6189 │ 6189 │  0
APK
    compressed    │   uncompressed   │                                           
───────────┬──────┼───────────┬──────┤                                           
 size      │ diff │ size      │ diff │ path                                      
───────────┼──────┼───────────┼──────┼───────────────────────────────────────────
    53 KiB │ -3 B │ 117.6 KiB │  0 B │ ∆ META-INF/CERT.SF                        
     272 B │ +2 B │     120 B │  0 B │ ∆ META-INF/version-control-info.textproto 
   1.2 KiB │ -2 B │   1.2 KiB │  0 B │ ∆ META-INF/CERT.RSA                       
  49.7 KiB │ +2 B │ 117.5 KiB │  0 B │ ∆ META-INF/MANIFEST.MF                    
───────────┼──────┼───────────┼──────┼───────────────────────────────────────────
 104.2 KiB │ -1 B │ 236.4 KiB │  0 B │ (total)

Base automatically changed from simond/implement-payout-component to master November 8, 2024 21:06
Copy link
Contributor

@lng-stripe lng-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not use the @Singleton annotation?

) : ViewModel() {

private val logger: Logger = Logger.getInstance(enableLogging = BuildConfig.DEBUG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add the logger to DI graph as well but can do in follow-ups.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked, I'll do this in a follow-up

import kotlinx.coroutines.launch
import java.io.IOException

@OptIn(PrivateBetaConnectSDK::class)
class EmbeddedComponentManagerWrapper private constructor() {
class EmbeddedComponentManagerWrapper(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class EmbeddedComponentManagerWrapper(
@Singleton
class EmbeddedComponentManagerWrapper @Inject constructor(


class EmbeddedComponentService private constructor(
private val settingsService: SettingsService = SettingsService.getInstance(),
class EmbeddedComponentService @Inject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class EmbeddedComponentService @Inject constructor(
@Singleton
class EmbeddedComponentService @Inject constructor(

Comment on lines 14 to 16
@Module
@InstallIn(SingletonComponent::class)
object ServiceModule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary if we use the @Singleton annotation appropriately, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I didn't realize this annotation existed. Much better, and yes we shouldn't need this module anymore!

class SettingsService private constructor(context: Context) {
class SettingsService @Inject constructor(context: Context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class SettingsService private constructor(context: Context) {
class SettingsService @Inject constructor(context: Context) {
@Singleton
class SettingsService @Inject constructor(
@ApplicationContext context: Context
) {

@simond-stripe simond-stripe merged commit af7b2e6 into master Nov 11, 2024
18 checks passed
@simond-stripe simond-stripe deleted the simond/connect-example-to-hilt branch November 11, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accept-risky-change accept-risky-change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants