|
|
@ -11,7 +11,6 @@ import android.widget.EditText |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import com.nivesh.production.niveshfd.R |
|
|
|
import com.nivesh.production.niveshfd.databinding.FragmentOtpBinding |
|
|
|
import com.nivesh.production.niveshfd.databinding.FragmentSignupBinding |
|
|
|
import com.nivesh.production.niveshfd.fd.util.Common |
|
|
|
|
|
|
|
class OTPFragment : Fragment() { |
|
|
@ -41,19 +40,65 @@ class OTPFragment : Fragment() { |
|
|
|
binding.edtOTP1.setOnKeyListener(GenericKeyEvent(binding.edtOTP1, null)) |
|
|
|
binding.edtOTP2.setOnKeyListener(GenericKeyEvent(binding.edtOTP2, binding.edtOTP1)) |
|
|
|
binding.edtOTP3.setOnKeyListener(GenericKeyEvent(binding.edtOTP3, binding.edtOTP2)) |
|
|
|
binding.edtOTP4.setOnKeyListener(GenericKeyEvent(binding.edtOTP4,binding.edtOTP3)) |
|
|
|
binding.edtOTP5.setOnKeyListener(GenericKeyEvent(binding.edtOTP5,binding.edtOTP4)) |
|
|
|
binding.edtOTP6.setOnKeyListener(GenericKeyEvent(binding.edtOTP6,binding.edtOTP5)) |
|
|
|
binding.edtOTP4.setOnKeyListener(GenericKeyEvent(binding.edtOTP4, binding.edtOTP3)) |
|
|
|
binding.edtOTP5.setOnKeyListener(GenericKeyEvent(binding.edtOTP5, binding.edtOTP4)) |
|
|
|
binding.edtOTP6.setOnKeyListener(GenericKeyEvent(binding.edtOTP6, binding.edtOTP5)) |
|
|
|
|
|
|
|
binding.btnContinue.setOnClickListener { |
|
|
|
if (validate()) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private fun validate(): Boolean { |
|
|
|
return false; |
|
|
|
return if (binding.edtOTP1.text.toString().isEmpty()) { // EditText |
|
|
|
Common.commonErrorMethod( |
|
|
|
binding.edtOTP1, |
|
|
|
binding.tlOTP1, |
|
|
|
getString(R.string.invalidOTP) |
|
|
|
) |
|
|
|
} else if (binding.edtOTP2.text.toString().isEmpty()) { // EditText |
|
|
|
Common.commonErrorMethod( |
|
|
|
binding.edtOTP2, |
|
|
|
binding.tlOTP2, |
|
|
|
getString(R.string.invalidOTP) |
|
|
|
) |
|
|
|
} else if (binding.edtOTP3.text.toString().isEmpty()) { // EditText |
|
|
|
Common.commonErrorMethod( |
|
|
|
binding.edtOTP3, |
|
|
|
binding.tlOTP3, |
|
|
|
getString(R.string.invalidOTP) |
|
|
|
) |
|
|
|
} else if (binding.edtOTP4.text.toString().isEmpty()) { // EditText |
|
|
|
Common.commonErrorMethod( |
|
|
|
binding.edtOTP4, |
|
|
|
binding.tlOTP4, |
|
|
|
getString(R.string.invalidOTP) |
|
|
|
) |
|
|
|
} else if (binding.edtOTP5.text.toString().isEmpty()) { // EditText |
|
|
|
Common.commonErrorMethod( |
|
|
|
binding.edtOTP5, |
|
|
|
binding.tlOTP5, |
|
|
|
getString(R.string.invalidOTP) |
|
|
|
) |
|
|
|
} else if (binding.edtOTP6.text.toString().isEmpty()) { // EditText |
|
|
|
Common.commonErrorMethod( |
|
|
|
binding.edtOTP6, |
|
|
|
binding.tlOTP6, |
|
|
|
getString(R.string.invalidOTP) |
|
|
|
) |
|
|
|
} else { |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class GenericKeyEvent internal constructor(private val currentView: EditText, private val previousView: EditText?) : View.OnKeyListener{ |
|
|
|
class GenericKeyEvent internal constructor( |
|
|
|
private val currentView: EditText, |
|
|
|
private val previousView: EditText? |
|
|
|
) : View.OnKeyListener { |
|
|
|
override fun onKey(p0: View?, keyCode: Int, event: KeyEvent?): Boolean { |
|
|
|
if(event!!.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_DEL && currentView.id != R.id.edtOTP1 && currentView.text.isEmpty()) { |
|
|
|
if (event!!.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_DEL && currentView.id != R.id.edtOTP1 && currentView.text.isEmpty()) { |
|
|
|
//If current is empty then previous EditText's number will also be deleted |
|
|
|
previousView!!.text = null |
|
|
|
previousView.requestFocus() |
|
|
@ -63,7 +108,10 @@ class OTPFragment : Fragment() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class GenericTextWatcher internal constructor(private val currentView: View, private val nextView: View?) : TextWatcher { |
|
|
|
class GenericTextWatcher internal constructor( |
|
|
|
private val currentView: View, |
|
|
|
private val nextView: View? |
|
|
|
) : TextWatcher { |
|
|
|
override fun afterTextChanged(editable: Editable) { // TODO Auto-generated method stub |
|
|
|
val text = editable.toString() |
|
|
|
when (currentView.id) { |
|
|
|