Last active
January 9, 2018 15:41
-
-
Save makovkastar/e4b2b863dbecbabe162ef7b9a82f91e9 to your computer and use it in GitHub Desktop.
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
class LoginFragment : Fragment(), Injectable { | |
@Inject | |
@VisibleForTesting | |
lateinit var viewModelFactory: ViewModelProvider.Factory | |
private lateinit var dataBinding: LoginFragmentBinding | |
private lateinit var viewModel: LoginViewModel | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
viewModel = ViewModelProviders.of(this, viewModelFactory) | |
.get(LoginViewModel::class.java) | |
} | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle?): View? { | |
val rootView = inflater.inflate(R.layout.fragment_login, container, false) | |
dataBinding = LoginFragmentBinding.bind(rootView) | |
dataBinding.viewModel = viewModel | |
return dataBinding.root | |
} | |
override fun onActivityCreated(savedInstanceState: Bundle?) { | |
super.onActivityCreated(savedInstanceState) | |
viewModel.navigateToForgotPasswordPage.observe(this, Observer { | |
startBrowser(Urls.FORGOT_PASSWORD) | |
}) | |
viewModel.showErrorToast.observe(this, Observer { | |
showToast("Error signing in.") | |
}) | |
viewModel.navigateToNextScreen.observe(this, Observer { | |
startHomeActivity() | |
activity.finish() | |
}) | |
} | |
private fun startHomeActivity() { | |
startActivity(Intent(activity, HomeActivity::class.java)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment