CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 17:43:21 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=6069d492a9649c0c346960d4fd29f6578e65b71290223dab8a1b22926fe7d7f3a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22tbyQxerwpetrvWfLsHONzblyphg80I-T%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d028c7fc6dd3d4-BLR
Pendekatan Primitive - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dicoding.myreactiveform
- import android.os.Bundle
- import android.text.Editable
- import android.text.TextWatcher
- import android.util.Patterns
- import androidx.appcompat.app.AppCompatActivity
- import androidx.core.content.ContextCompat
- import com.dicoding.myreactiveform.databinding.ActivityMainBinding
- class MainActivity : AppCompatActivity() {
- private var emailValid = false
- private var passwordValid = false
- private var passwordConfirmationValid = false
- private lateinit var binding: ActivityMainBinding
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- binding = ActivityMainBinding.inflate(layoutInflater)
- setContentView(binding.root)
- validateButton()
- binding.edEmail.addTextChangedListener(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) {
- validateEmail()
- }
- })
- binding.edPassword.addTextChangedListener(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) {
- validatePassword()
- }
- })
- binding.edConfirmPassword.addTextChangedListener(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) {
- validatePasswordConfirmation()
- }
- })
- }
- fun validateEmail() {
- // jika password tidak valid tampilkan peringatan
- val input = binding.edEmail.text.toString()
- if (!Patterns.EMAIL_ADDRESS.matcher(input).matches()) {
- emailValid = false
- showEmailExistAlert(true)
- } else {
- emailValid = true
- showEmailExistAlert(false)
- }
- validateButton()
- }
- fun validatePassword() {
- // jika password < 6 karakter tampilkan peringatan
- val input = binding.edPassword.text.toString()
- if (input.length < 6) {
- passwordValid = false
- showPasswordMinimalAlert(true)
- } else {
- passwordValid = true
- showPasswordMinimalAlert(false)
- }
- validateButton()
- }
- fun validatePasswordConfirmation() {
- // jika konfirmasi password tidak sesuai tampilkan peringatan
- val input = binding.edConfirmPassword.text.toString()
- if (input != binding.edPassword.text.toString()) {
- passwordConfirmationValid = false
- showPasswordConfirmationAlert(true)
- } else {
- passwordConfirmationValid = true
- showPasswordConfirmationAlert(false)
- }
- validateButton()
- }
- private fun validateButton() {
- // jika semua field sudah terisi, enable button submit
- if (emailValid && passwordValid && passwordConfirmationValid) {
- binding.btnRegister.isEnabled = true
- binding.btnRegister.setBackgroundColor(ContextCompat.getColor(this, R.color.purple_500))
- } else {
- binding.btnRegister.isEnabled = false
- binding.btnRegister.setBackgroundColor(ContextCompat.getColor(this, android.R.color.darker_gray))
- }
- }
- private fun showEmailExistAlert(isNotValid: Boolean) {
- binding.edEmail.error = if (isNotValid) getString(R.string.email_not_valid) else null
- }
- private fun showPasswordMinimalAlert(isNotValid: Boolean) {
- binding.edPassword.error = if (isNotValid) getString(R.string.password_not_valid) else null
- }
- private fun showPasswordConfirmationAlert(isNotValid: Boolean) {
- binding.edConfirmPassword.error = if (isNotValid) getString(R.string.password_not_same) else null
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 3 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 10 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ✅ NEVER SEEN...
JavaScript | 19 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 29 sec ago | 0.24 KB
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 38 sec ago | 0.24 KB
-
⭐✅ Trading Profit Method ✅ NEVER SEEN BEFORE...
JavaScript | 51 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 1 min ago | 0.24 KB
-
⭐⭐⭐MAKE $9OO INSTANTLY D M⭐⭐
Java | 1 min ago | 0.10 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand