AuthenticationActivity.kt 1.67 KB
Newer Older
1 2 3 4 5 6
package chat.rocket.android.authentication.ui

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import chat.rocket.android.R
7
import chat.rocket.android.authentication.presentation.AuthenticationPresenter
8
import chat.rocket.android.authentication.server.ui.ServerFragment
9
import chat.rocket.android.util.extensions.addFragment
10 11 12 13 14 15 16
import dagger.android.AndroidInjection
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.support.HasSupportFragmentInjector
import javax.inject.Inject

class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
17
    @Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
18
    @Inject lateinit var presenter: AuthenticationPresenter
19 20

    override fun onCreate(savedInstanceState: Bundle?) {
21
        AndroidInjection.inject(this)
22 23 24 25 26 27 28
        presenter.loadCredentials { authenticated ->
            if (authenticated) {
                // just call onCreate, and the presenter will call the navigator...
                super.onCreate(savedInstanceState)
            } else {
                showServerInput(savedInstanceState)
            }
29 30 31 32 33 34
        }
    }

    override fun supportFragmentInjector(): AndroidInjector<Fragment> {
        return fragmentDispatchingAndroidInjector
    }
35 36 37 38 39 40 41 42 43 44 45

    fun showServerInput(savedInstanceState: Bundle?) {
        setContentView(R.layout.activity_authentication)
        setTheme(R.style.AuthenticationTheme)

        super.onCreate(savedInstanceState)

        addFragment("ServerFragment", R.id.fragment_container) {
            ServerFragment.newInstance()
        }
    }
46
}