Commit 95a1d1bf authored by shohboz's avatar shohboz

[ADD] MUS-127 Feature, add sms verification code api

parent a9f50c61
...@@ -18,8 +18,8 @@ import uz.ssd.mobiuz.network.model.UiStateObject ...@@ -18,8 +18,8 @@ import uz.ssd.mobiuz.network.model.UiStateObject
import uz.ssd.mobiuz.ui.base.BaseFragment import uz.ssd.mobiuz.ui.base.BaseFragment
import uz.ssd.mobiuz.ui.global.TextWatcherWrapper import uz.ssd.mobiuz.ui.global.TextWatcherWrapper
import uz.ssd.mobiuz.utils.ButtonClick import uz.ssd.mobiuz.utils.ButtonClick
import uz.ssd.mobiuz.utils.CONSTANTS
import uz.ssd.mobiuz.utils.Utils import uz.ssd.mobiuz.utils.Utils
import uz.ssd.mobiuz.utils.extensions.customLog
import uz.ssd.mobiuz.utils.extensions.hideKeyboard import uz.ssd.mobiuz.utils.extensions.hideKeyboard
import uz.ssd.mobiuz.utils.extensions.showKeyboard import uz.ssd.mobiuz.utils.extensions.showKeyboard
import uz.ssd.mobiuz.utils.extensions.showMessage import uz.ssd.mobiuz.utils.extensions.showMessage
...@@ -31,7 +31,17 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -31,7 +31,17 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
private val bn get() = _bn ?: throw NullPointerException("cannot inflate") private val bn get() = _bn ?: throw NullPointerException("cannot inflate")
private val viewModel: AuthViewModel by viewModels() private val viewModel: AuthViewModel by viewModels()
private val navController: NavController by lazy(LazyThreadSafetyMode.NONE) { NavHostFragment.findNavController(this) } private val navController: NavController by lazy(LazyThreadSafetyMode.NONE) { NavHostFragment.findNavController(this) }
private var code = ""
private var phone = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
phone = it.getString(CONSTANTS.PHONE) ?: ""
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
_bn = FragmentVerificationBinding.bind(view) _bn = FragmentVerificationBinding.bind(view)
setUpUI() setUpUI()
...@@ -46,15 +56,28 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -46,15 +56,28 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
navController.navigateUp() navController.navigateUp()
} }
loadEdited() loadEdited()
viewGroup.setOnClickListener(object : ButtonClick(){
override fun onSingleClick(v: View?) {
v?.hideKeyboard()
}
})
frame.setOnClickListener(object : ButtonClick(){
override fun onSingleClick(v: View?) {
clearPins()
}
})
btnLogin.setOnClickListener(object : ButtonClick() { btnLogin.setOnClickListener(object : ButtonClick() {
override fun onSingleClick(v: View?) { override fun onSingleClick(v: View?) {
viewModel.login(UserAuth("phone", "password")) getLinePinCodes()
if(code.length == 6){
viewModel.verification(UserAuth(phone, null,code))
}else{
clearPins()
}
} }
}) })
...@@ -63,7 +86,6 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -63,7 +86,6 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
sentCodeAgain.setTextColor(Color.parseColor("#FF9500")) sentCodeAgain.setTextColor(Color.parseColor("#FF9500"))
sentCodeAgain.setOnClickListener { sentCodeAgain.setOnClickListener {
// viewModel.login(UserAuth("",""))
count(true) count(true)
} }
coutdownView.setOnCountdownEndListener { coutdownView.setOnCountdownEndListener {
...@@ -72,19 +94,21 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -72,19 +94,21 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
} }
} }
private fun loadEdited() { private fun getLinePinCodes() {
bn.apply { bn.apply {
code = ""
code += pin1.text.toString()
toolbar.setNavigationOnClickListener { code += pin2.text.toString()
navController.navigateUp() code += pin3.text.toString()
code += pin4.text.toString()
code += pin5.text.toString()
code += pin6.text.toString()
} }
viewGroup.setOnClickListener {
it.hideKeyboard()
} }
frame.setOnClickListener {
private fun clearPins() {
bn.apply {
pin1.text?.clear() pin1.text?.clear()
pin2.text?.clear() pin2.text?.clear()
pin3.text?.clear() pin3.text?.clear()
...@@ -93,6 +117,10 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -93,6 +117,10 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
pin6.text?.clear() pin6.text?.clear()
pin1.showKeyboard() pin1.showKeyboard()
} }
}
private fun loadEdited() {
bn.apply {
pin1.addTextChangedListener(object : TextWatcherWrapper() { pin1.addTextChangedListener(object : TextWatcherWrapper() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
...@@ -171,44 +199,15 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -171,44 +199,15 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
pin6.setBackgroundResource(R.drawable.bgn_ver_unchecked) pin6.setBackgroundResource(R.drawable.bgn_ver_unchecked)
} }
} }
}) })
pin1.setOnKeyListener { _, keyCode, _ -> for (i in 0 until pinView.childCount){
pinView.getChildAt(i).setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_DEL) { if (keyCode == KeyEvent.KEYCODE_DEL) {
checkFocus().requestFocus() checkFocus().requestFocus()
} }
false false
} }
pin2.setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_DEL) {
checkFocus().requestFocus()
}
false
}
pin3.setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_DEL) {
checkFocus().requestFocus()
}
false
}
pin4.setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_DEL) {
checkFocus().requestFocus()
}
false
}
pin5.setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_DEL) {
checkFocus().requestFocus()
}
false
}
pin6.setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_DEL) {
checkFocus().requestFocus()
}
false
} }
} }
} }
...@@ -246,7 +245,7 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -246,7 +245,7 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
override fun collects() { override fun collects() {
viewLifecycleOwner.lifecycleScope.launchWhenStarted { viewLifecycleOwner.lifecycleScope.launchWhenStarted {
viewModel.loginUiState.collect { viewModel.verificationUiState.collect {
when (it) { when (it) {
is UiStateObject.SUCCESS -> { is UiStateObject.SUCCESS -> {
showProgressDialog(false) showProgressDialog(false)
...@@ -270,7 +269,7 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) { ...@@ -270,7 +269,7 @@ class VerificationFragment : BaseFragment(R.layout.fragment_verification) {
sentCodeAgain.isVisible = !status sentCodeAgain.isVisible = !status
countWaitText.isVisible = status countWaitText.isVisible = status
coutdownView.isVisible = status coutdownView.isVisible = status
if (status) coutdownView.start(120000) if (status) coutdownView.start(60000)
} }
} }
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/view_group" android:id="@+id/view_group"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
...@@ -27,21 +27,22 @@ ...@@ -27,21 +27,22 @@
<FrameLayout <FrameLayout
android:id="@+id/pin_view" android:id="@+id/pin_view_group"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_80sdp"
android:layout_marginHorizontal="@dimen/_12sdp" android:layout_marginHorizontal="@dimen/_12sdp"
android:layout_marginTop="@dimen/_80sdp"
android:orientation="horizontal" android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txt_enter_phone"> app:layout_constraintTop_toBottomOf="@id/txt_enter_phone">
<LinearLayout <LinearLayout
android:id="@+id/pin_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center">
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
...@@ -72,14 +73,16 @@ ...@@ -72,14 +73,16 @@
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/pin_6" android:id="@+id/pin_6"
style="@style/PinStyle" style="@style/PinStyle"
android:background="@drawable/bgn_ver_unchecked" /> android:background="@drawable/bgn_ver_unchecked"
android:imeOptions="actionDone" />
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout
android:layout_width="match_parent"
android:id="@+id/frame" android:id="@+id/frame"
android:visibility="visible" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"
android:visibility="visible" />
</FrameLayout> </FrameLayout>
<TextView <TextView
...@@ -93,7 +96,7 @@ ...@@ -93,7 +96,7 @@
app:layout_constraintEnd_toStartOf="@id/coutdown_view" app:layout_constraintEnd_toStartOf="@id/coutdown_view"
app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pin_view" /> app:layout_constraintTop_toBottomOf="@+id/pin_view_group" />
<TextView <TextView
android:id="@+id/sent_code_again" android:id="@+id/sent_code_again"
...@@ -108,7 +111,7 @@ ...@@ -108,7 +111,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pin_view" /> app:layout_constraintTop_toBottomOf="@+id/pin_view_group" />
<cn.iwgang.countdownview.CountdownView <cn.iwgang.countdownview.CountdownView
android:id="@+id/coutdown_view" android:id="@+id/coutdown_view"
...@@ -151,10 +154,10 @@ ...@@ -151,10 +154,10 @@
android:layout_marginHorizontal="@dimen/_16sdp" android:layout_marginHorizontal="@dimen/_16sdp"
android:layout_marginTop="@dimen/_24sdp" android:layout_marginTop="@dimen/_24sdp"
android:enabled="false" android:enabled="false"
android:text="@string/continuoue_task" android:text="@string/continuoue"
android:textSize="@dimen/_12sdp" android:textSize="@dimen/_12sdp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/pin_view" /> app:layout_constraintTop_toBottomOf="@id/pin_view_group" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment