From fe9f6a63ca88a3849d8e5b8ff47fd44e5644d05f Mon Sep 17 00:00:00 2001 From: miladsi90 Date: Mon, 29 Jul 2019 11:31:16 +0430 Subject: [PATCH] Create some methods for codes in initUiListener , add initObserver to base fragment , closed #26 --- .../netalic/peacock/ui/base/BaseFragment.kt | 2 ++ .../CodeVerificationFragment.kt | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/netalic/peacock/ui/base/BaseFragment.kt b/app/src/main/java/de/netalic/peacock/ui/base/BaseFragment.kt index 62c74ae..9ceb516 100644 --- a/app/src/main/java/de/netalic/peacock/ui/base/BaseFragment.kt +++ b/app/src/main/java/de/netalic/peacock/ui/base/BaseFragment.kt @@ -8,12 +8,14 @@ abstract class BaseFragment : Fragment() { abstract fun initUiListener() abstract fun initUiComponent() + abstract fun initObserver() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) initUiListener() initUiComponent() + initObserver() } } \ No newline at end of file diff --git a/app/src/main/java/de/netalic/peacock/ui/registeration/codeverification/CodeVerificationFragment.kt b/app/src/main/java/de/netalic/peacock/ui/registeration/codeverification/CodeVerificationFragment.kt index b5c0017..a5b7b05 100644 --- a/app/src/main/java/de/netalic/peacock/ui/registeration/codeverification/CodeVerificationFragment.kt +++ b/app/src/main/java/de/netalic/peacock/ui/registeration/codeverification/CodeVerificationFragment.kt @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit class CodeVerificationFragment : BaseFragment() { + companion object { var sTimer = 30000 @@ -51,11 +52,22 @@ class CodeVerificationFragment : BaseFragment() { disableButton() } - // TODO-Milad separate the codes in multiple functions override fun initUiListener() { + buttonListener() + resendCodeListener() + pinEntryEditTextListener() + + } + + private fun buttonListener() { + mButton.setOnClickListener { bind() } + } + + private fun resendCodeListener() { + mTextViewResendCode.setOnClickListener { if (!mIsRunning) { @@ -66,6 +78,9 @@ class CodeVerificationFragment : BaseFragment() { } } + } + + private fun pinEntryEditTextListener() { mPinEntryEditText.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(p0: Editable?) { @@ -87,14 +102,15 @@ class CodeVerificationFragment : BaseFragment() { } } }) + } + + override fun initObserver() { + observeBindLiveData() } override fun initUiComponent() { - //TODO-Milad Add initObservers - observeViewModel() - } private fun bind() { @@ -118,14 +134,12 @@ class CodeVerificationFragment : BaseFragment() { "082016" ) ) - } - private fun observeViewModel() { + private fun observeBindLiveData() { mCodeVerificationViewModel.getBindLiveData().observe(this, Observer { - when (it.status) { Status.LOADING -> { } @@ -180,5 +194,4 @@ class CodeVerificationFragment : BaseFragment() { mButton.isEnabled = true } - } \ No newline at end of file