Created
July 9, 2019 01:08
-
-
Save bsscco/65e70856ab1ab725efaee8aec22294bc to your computer and use it in GitHub Desktop.
RxBinding 사용 전
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 MainActivity : AppCompatActivity() { | |
private var isButtonClickProcessing = false | |
@SuppressLint("CheckResult") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val nicknameInputField = findViewById<EditText>(R.id.nicknameInputField) | |
val passwordInputField = findViewById<EditText>(R.id.passwordInputField) | |
val okButton = findViewById<Button>(R.id.okButton) | |
nicknameInputField.addTextChangedListener(object : TextWatcher { | |
override fun afterTextChanged(p0: Editable?) { | |
} | |
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { | |
} | |
override fun onTextChanged(text: CharSequence?, p1: Int, p2: Int, p3: Int) { | |
text?.let { // 입력 내용에 따라 버튼색 변하게 하기 | |
if (text.length >= 4 && passwordInputField.length() >= 4) { | |
okButton.setBackgroundColor(Color.BLUE) | |
} else { | |
okButton.setBackgroundColor(Color.GRAY) | |
} | |
} | |
} | |
}) | |
passwordInputField.addTextChangedListener(object : TextWatcher { | |
override fun afterTextChanged(p0: Editable?) { | |
} | |
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { | |
} | |
override fun onTextChanged(text: CharSequence?, p1: Int, p2: Int, p3: Int) { | |
text?.let { // 입력 내용에 따라 버튼색 변하게 하기 | |
if (text.length >= 4 && nicknameInputField.length() >= 4) { | |
okButton.setBackgroundColor(Color.BLUE) | |
} else { | |
okButton.setBackgroundColor(Color.GRAY) | |
} | |
} | |
} | |
}) | |
okButton.setOnClickListener { | |
// 버튼 클릭에 쿨타임 걸기 | |
if(isButtonClickProcessing) return@setOnClickListener | |
isButtonClickProcessing = true | |
Observable.timer(1, TimeUnit.SECONDS).subscribe { isButtonClickProcessing = false } | |
when { | |
nicknameInputField.length() < 4 -> Toast.makeText(this, "닉네임 4글자 이상!", Toast.LENGTH_SHORT).show() | |
passwordInputField.length() < 4 -> Toast.makeText(this, "패스워드 4글자 이상!", Toast.LENGTH_SHORT).show() | |
else -> { | |
nicknameInputField.setText("") | |
passwordInputField.setText("") | |
Toast.makeText(this, "OK!", Toast.LENGTH_SHORT).show() | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment