codelab-android-dagger icon indicating copy to clipboard operation
codelab-android-dagger copied to clipboard

Content of MainActivity.kt in the code block is wrong

Open KunalDhyani opened this issue 3 years ago • 0 comments

class MainActivity : AppCompatActivity() {

// 1) Remove userManager field
@Inject
lateinit var userManager: UserManager

@Inject
lateinit var mainViewModel: MainViewModel

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_settings) <<<<<<<<<<<<< Not Supposed to be here <<<<<<<<<<

    // 2) Grab userManager from appComponent to check if the user is logged in or not
    val userManager = (application as MyApplication).appComponent.userManager()
    if (!userManager.isUserLoggedIn()) { ... }
    else {
        setContentView(R.layout.activity_main)
        // 3) If the MainActivity needs to be displayed, we get the UserComponent
        // from the application graph and gets this Activity injected
        userManager.userComponent!!.inject(this)
        setupViews()
    }
}
...

}

KunalDhyani avatar Jun 23 '22 09:06 KunalDhyani