childList fragment
This commit is contained in:
@@ -4,6 +4,6 @@ sealed class ApiResult<T>(data: T? = null, errorMessage: String? = null) {
|
||||
|
||||
class Loading<T>: ApiResult<T>()
|
||||
class Success<T>(val data: T? = null, val message: String? = null): ApiResult<T>(data)
|
||||
class Error<T>(val errorMessage: String? = null): ApiResult<T>(errorMessage = errorMessage)
|
||||
class Error<T>(val errorMessage: String? = null, val error: Throwable? = null): ApiResult<T>(errorMessage = errorMessage)
|
||||
|
||||
}
|
||||
3
app/src/main/java/com/woka/networking/NoSuccessError.kt
Normal file
3
app/src/main/java/com/woka/networking/NoSuccessError.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package com.woka.networking
|
||||
|
||||
class NoSuccessError: Throwable()
|
||||
@@ -62,9 +62,9 @@ object RetrofitHelper {
|
||||
val response = apiCall() // this api call can throw some exception
|
||||
handleApiResponse(response) // handling the response
|
||||
} catch (e: UnknownHostException) {
|
||||
ApiResult.Error(errorMessage = NO_INTERNET_MESSAGE)
|
||||
ApiResult.Error(errorMessage = NO_INTERNET_MESSAGE, error = e)
|
||||
} catch (e: Exception) {
|
||||
ApiResult.Error(errorMessage = UNKNOWN_ERROR_MESSAGE)
|
||||
ApiResult.Error(errorMessage = UNKNOWN_ERROR_MESSAGE, error = e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ object RetrofitHelper {
|
||||
return if (body.success == 1) {
|
||||
ApiResult.Success(body.data, body.message)
|
||||
} else {
|
||||
ApiResult.Error(errorMessage = body.message)
|
||||
ApiResult.Error(errorMessage = body.message, error = NoSuccessError())
|
||||
}
|
||||
} else {
|
||||
return ApiResult.Error(errorMessage = response.message())
|
||||
|
||||
34
app/src/main/java/com/woka/onboard/ChildAdapter.kt
Normal file
34
app/src/main/java/com/woka/onboard/ChildAdapter.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.woka.onboard
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import com.bumptech.glide.Glide
|
||||
import com.woka.databinding.ChildViewHolderBinding
|
||||
import com.woka.onboard.models.Child
|
||||
|
||||
class ChildAdapter(private val childList: List<Child>) : RecyclerView.Adapter<ChildAdapter.ChildViewHolder>(){
|
||||
|
||||
inner class ChildViewHolder(val binding: ChildViewHolderBinding): ViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChildViewHolder {
|
||||
return ChildViewHolder(ChildViewHolderBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent, false
|
||||
))
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = childList.size
|
||||
|
||||
override fun onBindViewHolder(holder: ChildViewHolder, position: Int) {
|
||||
holder.binding.apply {
|
||||
Glide.with(image)
|
||||
.load(childList[position].avtar)
|
||||
.fitCenter()
|
||||
.into(image)
|
||||
|
||||
name.text = childList[position].fullname
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.woka.onboard.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.woka.R
|
||||
import com.woka.databinding.FragmentChildListBinding
|
||||
import com.woka.onboard.ChildAdapter
|
||||
import com.woka.onboard.fragments.GetCodeFragment.Companion.EMAIL_ARG
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.models.Child
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
|
||||
class ChildListFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentChildListBinding
|
||||
private lateinit var viewModel: OnboardViewModel
|
||||
|
||||
private var isUnder16: Boolean = false
|
||||
private var email: String = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
isUnder16 = it.getBoolean(IS_UNDER_16)
|
||||
email = it.getString(EMAIL_ARG, "")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = FragmentChildListBinding.inflate(inflater, container, false)
|
||||
activity?.let {
|
||||
viewModel = ViewModelProvider(it)[OnboardViewModel::class.java]
|
||||
}
|
||||
|
||||
clickEvents()
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun clickEvents() {
|
||||
binding.apply {
|
||||
next.setOnClickListener { gotoSignUpFragment() }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
if (viewModel.childList == null){
|
||||
gotoSignUpFragment()
|
||||
return
|
||||
}
|
||||
|
||||
binding.apply {
|
||||
rvChild.adapter = ChildAdapter(viewModel.childList!!)
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotoSignUpFragment(){
|
||||
val args = Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(EMAIL_ARG, email)
|
||||
}
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_childListFragment_to_signUpFragment,
|
||||
args
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import androidx.navigation.fragment.findNavController
|
||||
import com.woka.R
|
||||
import com.woka.databinding.FragmentGetCodeBinding
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.NoSuccessError
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_RESET_PASSWORD_INTENT
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
@@ -113,31 +114,49 @@ class GetCodeFragment : Fragment() {
|
||||
progressView.show("Validating OTP...")
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
lifecycleScope.launch {
|
||||
val listOfChild = viewModel.getChildList(email)
|
||||
// OTP validation successful
|
||||
|
||||
when (listOfChild){
|
||||
is ApiResult.Error -> {
|
||||
Log.d("aditya_testing", "onViewCreated: ${listOfChild.errorMessage}")
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
Log.d("aditya_testing", "onViewCreated: ${listOfChild.data}")
|
||||
}
|
||||
}
|
||||
|
||||
Toast.makeText(activity, "OTP validation successful.", Toast.LENGTH_SHORT).show()
|
||||
if (isResetPasswordIntent){
|
||||
progressView.hide()
|
||||
val args = Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(EMAIL_ARG, email)
|
||||
}
|
||||
Toast.makeText(activity, "OTP validation successful.", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
findNavController().navigate(R.id.action_getCodeFragment_to_newPasswordFragment2)
|
||||
}else{
|
||||
lifecycleScope.launch {
|
||||
val listOfChild = viewModel.getChildList(email)
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_getCodeFragment_to_signUpFragment,
|
||||
args
|
||||
)
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "OTP validation successful.", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
|
||||
if (listOfChild is ApiResult.Error){
|
||||
if (listOfChild.error is NoSuccessError){
|
||||
// no child list found
|
||||
gotoSignUpFragment()
|
||||
}else{
|
||||
// some other error happened
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"${listOfChild.errorMessage}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}else if (listOfChild is ApiResult.Success && listOfChild.data?.result != null){
|
||||
// child list is available
|
||||
viewModel.childList = listOfChild.data.result
|
||||
val args = Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(EMAIL_ARG, email)
|
||||
}
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_getCodeFragment_to_childListFragment,
|
||||
args
|
||||
)
|
||||
}else{
|
||||
gotoSignUpFragment()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,11 +239,7 @@ class GetCodeFragment : Fragment() {
|
||||
}
|
||||
|
||||
next.setOnClickListener {
|
||||
if (isResetPasswordIntent) {
|
||||
findNavController().navigate(R.id.action_getCodeFragment_to_newPasswordFragment2)
|
||||
} else {
|
||||
viewModel.validateOTP(uniqueString, getOTP())
|
||||
}
|
||||
viewModel.validateOTP(uniqueString, getOTP())
|
||||
}
|
||||
|
||||
resend.setOnClickListener {
|
||||
@@ -235,6 +250,18 @@ class GetCodeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotoSignUpFragment(){
|
||||
val args = Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(EMAIL_ARG, email)
|
||||
}
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_getCodeFragment_to_signUpFragment,
|
||||
args
|
||||
)
|
||||
}
|
||||
|
||||
private fun getOTP(): String {
|
||||
binding.apply {
|
||||
return "${et1.text}${et2.text}${et3.text}${et4.text}"
|
||||
|
||||
@@ -128,6 +128,7 @@ class SelectAvatarFragment : Fragment() {
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
Log.d("aditya_testing", "onViewCreated: ${it.data}")
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper
|
||||
import com.woka.onboard.models.AvatarList
|
||||
import com.woka.onboard.models.Child
|
||||
import com.woka.onboard.models.ChildListResponse
|
||||
import com.woka.onboard.models.LoginResponse
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
@@ -32,6 +33,8 @@ class OnboardViewModel: ViewModel(){
|
||||
var name: String? = null
|
||||
var password: String? = null
|
||||
|
||||
var childList: List<Child>? = null
|
||||
|
||||
// live_data
|
||||
/*
|
||||
Login Fragment
|
||||
@@ -159,7 +162,7 @@ class OnboardViewModel: ViewModel(){
|
||||
}
|
||||
|
||||
// otp count down timer
|
||||
private val OTP_RESEND_COUNT_DOWN_TIME = 30 * 1000L // 10 min
|
||||
private val OTP_RESEND_COUNT_DOWN_TIME = 10 * 60 * 1000L // 10 min
|
||||
|
||||
private var countDownTimer: CountDownTimer? = null
|
||||
private var _otpResendTimeLiveData = MutableLiveData<Long>()
|
||||
|
||||
Reference in New Issue
Block a user