Last active
July 10, 2017 18:45
-
-
Save theerasan/183279ddf01aee2ff8f3b536484a6790 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| private var emailField: AutoCompleteTextView? = null | |
| private var passwordField: EditText? = null | |
| private var signInButton: Button? = null | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_login) | |
| emailField = findViewById(R.id.email) as AutoCompleteTextView | |
| passwordField = findViewById(R.id.password) as EditText | |
| signInButton = findViewById(R.id.email_sign_in_button) as Button | |
| val textWatcher = object:TextWatcher { | |
| override fun afterTextChanged(s: Editable?) { } | |
| override fun beforeTextChanged(s: CharSequence?, | |
| start: Int, | |
| count: Int, | |
| after: Int) { } | |
| override fun onTextChanged(s: CharSequence?, | |
| start: Int, | |
| before: Int, | |
| count: Int) { | |
| checkIsReadyToSignIn() | |
| } | |
| } | |
| emailField!!.addTextChangedListener(textWatcher) | |
| passwordField!!.addTextChangedListener(textWatcher) | |
| signInButton!!.setOnClickListener { performLogin() } | |
| signInButton!!.isEnabled = false | |
| } | |
| private fun performLogin() { | |
| val stringToShow = emailField?.text.toString() | |
| + " " | |
| + passwordField?.text.toString() | |
| Toast.makeText(this, stringToShow, Toast.LENGTH_LONG).show() | |
| emailField?.setText("") | |
| passwordField?.setText("") | |
| } | |
| private fun checkIsReadyToSignIn() { | |
| val notEmptyStrings = TextHelper.isNotEmptyStrings(emailField!!.text.toString(), | |
| passwordField!!.text.toString()) | |
| signInButton!!.isEnabled = notEmptyStrings | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment