Skip to content
This repository has been archived by the owner on Aug 4, 2019. It is now read-only.

Commit

Permalink
Create code verification test , closed #21
Browse files Browse the repository at this point in the history
  • Loading branch information
miladsalimiiii committed Jul 27, 2019
1 parent 581ede0 commit aded398
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 65 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/de/netalic/peacock/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

supportFragmentManager.beginTransaction().add(R.id.frameLayout_mainActivity_fragmentContainer, CodeVerificationFragment()).commit()
supportFragmentManager.beginTransaction().add(R.id.frameLayout_mainActivity_fragmentContainer,
CodeVerificationFragment()).commit()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.netalic.peacock.data.exception

class ActivationCodeIsNotValid :Throwable()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.netalic.peacock.data.exception

class BadRequestException : Throwable()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.netalic.peacock.data.exception

class InvalidDeviceName:Throwable()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.netalic.peacock.data.exception

class InvalidUdidOrPhone :Throwable()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.netalic.peacock.data.exception

class ServerException : Throwable()
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import com.alimuzaffar.lib.pin.PinEntryEditText
import de.netalic.peacock.R

import de.netalic.peacock.data.model.Status
import de.netalic.peacock.data.model.User
import de.netalic.peacock.ui.base.BaseFragment
import kotlinx.android.synthetic.main.fragment_codeverification.*
import org.koin.android.viewmodel.ext.android.viewModel
import java.util.concurrent.TimeUnit


class CodeVerificationFragment : BaseFragment() {


Expand All @@ -26,20 +27,21 @@ class CodeVerificationFragment : BaseFragment() {
var sTimer = 30000
}

private var mIsRunning:Boolean = false
private lateinit var mCountDownTimer:CountDownTimer
private var mIsRunning: Boolean = false
private lateinit var mCountDownTimer: CountDownTimer
private lateinit var mView: View

private val mCodeVerificationViewModel: CodeVerificationViewModel by viewModel()

private val mImageView by lazy { imageView_codeVerification_icon }
private val mTextViewPhoneNumber by lazy { textView_codeVerification_phoneNumber }
private val mPinEntryEditText by lazy { pinEntryEditText_codeVerification_setPin }
private val mButton by lazy { button_codeVerification_continue }
private val mTextViewTimer by lazy { textView_codeVerification_resendTime }

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

mView = inflater.inflate(R.layout.fragment_codeverification, container, false)
mView = inflater.inflate(de.netalic.peacock.R.layout.fragment_codeverification, container, false)
return mView
}

Expand All @@ -55,9 +57,9 @@ class CodeVerificationFragment : BaseFragment() {

override fun initUiListener() {

button_codeVerification_continue.setOnClickListener { bind() }
mButton.setOnClickListener { bind() }

textView_codeVerification_resendTime.setOnClickListener {
mTextViewTimer.setOnClickListener {

if (!mIsRunning) {
setTimer()
Expand All @@ -66,13 +68,8 @@ class CodeVerificationFragment : BaseFragment() {
}
}

pinEntryEditText_codeVerification_setPin.setOnPinEnteredListener(PinEntryEditText.OnPinEnteredListener {



})

pinEntryEditText_codeVerification_setPin.addTextChangedListener(object :TextWatcher{
mPinEntryEditText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {

}
Expand All @@ -84,11 +81,10 @@ class CodeVerificationFragment : BaseFragment() {
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {


if (p0!!.length==6){
if (p0!!.length == 6) {

enableButton()
}
else{
} else {
disableButton()
}
}
Expand Down Expand Up @@ -127,13 +123,7 @@ class CodeVerificationFragment : BaseFragment() {
})
}

private fun navigationToEmailVerification() {

//navigate to Email verification fragment here

}

private fun setTimer(){
private fun setTimer() {


mCountDownTimer = object : CountDownTimer(sTimer.toLong(), 1000) {
Expand All @@ -143,33 +133,33 @@ class CodeVerificationFragment : BaseFragment() {
val secondTimer = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)
)
textView_codeVerification_resendTime.text = String.format("%02d:%02d ", minuteTimer, secondTimer)
textView_codeVerification_resendTime.isEnabled = false
textView_codeVerification_resendTime.setTextColor(ContextCompat.getColor(requireContext(),R.color.colorText))
mTextViewTimer.text = String.format("%02d:%02d ", minuteTimer, secondTimer)
mTextViewTimer.isEnabled = false
mTextViewTimer.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorText))

}

override fun onFinish() {

textView_codeVerification_resendTime.isEnabled = true
mTextViewTimer.isEnabled = true
mIsRunning = false
if (context != null) {
textView_codeVerification_resendTime.text=getString(R.string.codeVerification_resendCode)
textView_codeVerification_resendTime.setTextColor(ContextCompat.getColor(requireContext(),R.color.colorTertiaryDark))
mTextViewTimer.text = getString(R.string.codeVerification_resendCode)
mTextViewTimer.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorTertiaryDark))
}
}
}.start()

}

private fun disableButton(){
private fun disableButton() {

button_codeVerification_continue.isEnabled=false
mButton.isEnabled = false
}

private fun enableButton(){
private fun enableButton() {

button_codeVerification_continue.isEnabled=true
mButton.isEnabled = true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package de.netalic.peacock.ui.registeration.codeverification

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import de.netalic.peacock.data.exception.ActivationCodeIsNotValid
import de.netalic.peacock.data.exception.BadRequestException
import de.netalic.peacock.data.exception.InvalidDeviceName
import de.netalic.peacock.data.exception.InvalidUdidOrPhone
import de.netalic.peacock.data.model.MyResponse
import de.netalic.peacock.data.model.User
import de.netalic.peacock.data.repository.UserRepository
Expand Down Expand Up @@ -34,12 +38,17 @@ class CodeVerificationViewModel(private val userRepository: UserRepository) : Ba
mBindResponseLiveData.value = MyResponse.success(it.body()!!)
}
400 -> {
mBindResponseLiveData.value = MyResponse.success(it.body()!!)
mBindResponseLiveData.value = MyResponse.failed(BadRequestException())
}
700 -> {
mBindResponseLiveData.value
710 -> {
mBindResponseLiveData.value = MyResponse.failed(InvalidUdidOrPhone())
}
711 -> {
mBindResponseLiveData.value = MyResponse.failed(ActivationCodeIsNotValid())
}
716 -> {
mBindResponseLiveData.value = MyResponse.failed(InvalidDeviceName())
}


}
},
Expand Down
25 changes: 0 additions & 25 deletions app/src/main/java/de/netalic/peacock/ui/util/FragmentUtil.kt

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_codeverification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</RelativeLayout>

<ImageView
android:id="@+id/ImageView_codeVerification_icon"
android:id="@+id/imageView_codeVerification_icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="28dp"
Expand All @@ -45,7 +45,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/codeVerification_codeVerification"
android:layout_below="@+id/ImageView_codeVerification_icon"
android:layout_below="@+id/imageView_codeVerification_icon"
android:gravity="center"
android:layout_marginTop="20dp"
style="@style/TextAppearanceBaseBold"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/test/java/de/netalic/peacock/base/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class BaseTest {
}

override fun createWorker(): Worker {
return ExecutorScheduler.ExecutorWorker(Executor { it.run() })
return ExecutorScheduler.ExecutorWorker(Executor { it.run()})
}
}
RxJavaPlugins.setInitIoSchedulerHandler { scheduler -> immediate }
Expand Down
Loading

0 comments on commit aded398

Please sign in to comment.