android / codelab-android-dagger

Apache License 2.0
183 stars 157 forks source link

Content of MainActivity.kt in the code block is wrong #69

Open KunalDhyani opened 2 years ago

KunalDhyani commented 2 years ago

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()
    }
}
...

}