Register Api
Avatar api childList api data collection from all onboard fragments into viewmodel
This commit is contained in:
@@ -3,7 +3,7 @@ package com.woka.networking
|
||||
sealed class ApiResult<T>(data: T? = null, errorMessage: String? = null) {
|
||||
|
||||
class Loading<T>: ApiResult<T>()
|
||||
class Success<T>(val data: T? = null): ApiResult<T>(data)
|
||||
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)
|
||||
|
||||
}
|
||||
@@ -73,7 +73,7 @@ object RetrofitHelper {
|
||||
if (response.isSuccessful) {
|
||||
val body = response.body() ?: return ApiResult.Error(errorMessage = "Empty Response")
|
||||
return if (body.success == 1) {
|
||||
ApiResult.Success(body.data)
|
||||
ApiResult.Success(body.data, body.message)
|
||||
} else {
|
||||
ApiResult.Error(errorMessage = body.message)
|
||||
}
|
||||
|
||||
@@ -9,11 +9,9 @@ import com.woka.R
|
||||
import com.woka.databinding.AvatarViewholderBinding
|
||||
import com.woka.onboard.models.Avatar
|
||||
|
||||
class AvatarAdapter(val avatarList: List<Avatar>) :
|
||||
class AvatarAdapter(val avatarList: List<Avatar>, private var selectedPos: Int? = null, private val selectedPosChanged: ((pos: Int?)-> Unit)? = null) :
|
||||
RecyclerView.Adapter<AvatarAdapter.AvatarViewHolder>() {
|
||||
|
||||
var selectedPos: Int? = null
|
||||
|
||||
inner class AvatarViewHolder(val binding: AvatarViewholderBinding) : ViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AvatarViewHolder {
|
||||
@@ -34,10 +32,10 @@ class AvatarAdapter(val avatarList: List<Avatar>) :
|
||||
.into(holder.binding.avatar)
|
||||
|
||||
holder.binding.card.apply {
|
||||
if (selectedPos == position){
|
||||
if (selectedPos == position) {
|
||||
cardElevation = 5f
|
||||
setCardBackgroundColor(holder.itemView.context.getColor(R.color.white))
|
||||
}else{
|
||||
} else {
|
||||
cardElevation = 0f
|
||||
setCardBackgroundColor(holder.itemView.context.getColor(R.color.white_50))
|
||||
}
|
||||
@@ -55,6 +53,7 @@ class AvatarAdapter(val avatarList: List<Avatar>) :
|
||||
notifyItemChanged(it)
|
||||
}
|
||||
selectedPos = position
|
||||
selectedPosChanged?.invoke(selectedPos)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.woka.R
|
||||
import com.woka.databinding.FragmentGetCodeBinding
|
||||
@@ -22,6 +23,7 @@ import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.PARENT_TYPE
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.closeKeyboard
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/*
|
||||
This fragment is to get the otp code input
|
||||
@@ -85,10 +87,6 @@ class GetCodeFragment : Fragment() {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
|
||||
// stating null status for otp sent live data so that when user goes back to the otp screen
|
||||
// they do not encounter a success status again
|
||||
viewModel.clearSendOTPData()
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show("Sending OTP...")
|
||||
@@ -98,6 +96,8 @@ class GetCodeFragment : Fragment() {
|
||||
Toast.makeText(activity, "OTP sent successfully", Toast.LENGTH_SHORT).show()
|
||||
progressView.hide()
|
||||
uniqueString = it.data?.unique_string?:""
|
||||
|
||||
viewModel.clearSendOTPData()
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
@@ -113,17 +113,32 @@ class GetCodeFragment : Fragment() {
|
||||
progressView.show("Validating OTP...")
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
Toast.makeText(activity, "OTP validation successful.", Toast.LENGTH_SHORT).show()
|
||||
progressView.hide()
|
||||
val args = Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(EMAIL_ARG, email)
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
val listOfChild = viewModel.getChildList(email)
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_getCodeFragment_to_signUpFragment,
|
||||
args
|
||||
)
|
||||
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()
|
||||
progressView.hide()
|
||||
val args = Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(EMAIL_ARG, email)
|
||||
}
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_getCodeFragment_to_signUpFragment,
|
||||
args
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
null -> {}
|
||||
|
||||
@@ -90,6 +90,45 @@ class GetEmailFragment : Fragment() {
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
// listening to otp live data
|
||||
viewModel.sendOTPLiveData.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show(title = "Sending OTP")
|
||||
}
|
||||
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
|
||||
viewModel.email = binding.email.text.toString()
|
||||
|
||||
val args = if (isResetPasswordIntent) {
|
||||
Bundle().apply {
|
||||
putBoolean(IS_RESET_PASSWORD_INTENT, isResetPasswordIntent)
|
||||
}
|
||||
} else {
|
||||
Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(UNIQUE_STRING_ARG, it.data?.unique_string)
|
||||
putString(EMAIL_ARG, binding.email.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_getEmailFragment_to_getCodeFragment,
|
||||
args
|
||||
)
|
||||
}
|
||||
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
@@ -129,43 +168,6 @@ class GetEmailFragment : Fragment() {
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
// listening to otp live data
|
||||
viewModel.sendOTPLiveData.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show(title = "Sending OTP")
|
||||
}
|
||||
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
|
||||
val args = if (isResetPasswordIntent) {
|
||||
Bundle().apply {
|
||||
putBoolean(IS_RESET_PASSWORD_INTENT, isResetPasswordIntent)
|
||||
}
|
||||
} else {
|
||||
Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(UNIQUE_STRING_ARG, it.data?.unique_string)
|
||||
putString(EMAIL_ARG, binding.email.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.action_getEmailFragment_to_getCodeFragment,
|
||||
args
|
||||
)
|
||||
}
|
||||
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isUnder16) {
|
||||
// parent
|
||||
viewModel.checkEmailExist(binding.email.text.toString(), PARENT_TYPE)
|
||||
|
||||
@@ -6,35 +6,34 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.ViewGroup
|
||||
import android.widget.DatePicker
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.allViews
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.woka.R
|
||||
import com.woka.databinding.FragmentGetMoreInfoBinding
|
||||
import com.woka.onboard.InterestTopicView
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.models.Interest
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.Gender
|
||||
import java.util.Calendar
|
||||
|
||||
class GetMoreInfoFragment : Fragment() {
|
||||
|
||||
companion object{
|
||||
const val USER_NAME_ARG = "arg_user_name"
|
||||
}
|
||||
|
||||
private lateinit var binding: FragmentGetMoreInfoBinding
|
||||
|
||||
private lateinit var viewModel: OnboardViewModel
|
||||
|
||||
private var isUnder16 = false
|
||||
private var userName: String? = null
|
||||
private var selectedGender: Gender = Gender.NONE
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
isUnder16 = it.getBoolean(IS_UNDER_16)
|
||||
userName = it.getString(USER_NAME_ARG)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +42,11 @@ class GetMoreInfoFragment : Fragment() {
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = FragmentGetMoreInfoBinding.inflate(inflater, container, false)
|
||||
|
||||
activity?.let {
|
||||
viewModel = ViewModelProvider(it)[OnboardViewModel::class.java]
|
||||
}
|
||||
|
||||
initViews()
|
||||
clickEvents()
|
||||
return binding.root
|
||||
@@ -50,22 +54,37 @@ class GetMoreInfoFragment : Fragment() {
|
||||
|
||||
private fun clickEvents() {
|
||||
binding.apply {
|
||||
genderM.setOnClickListener{selectGender(Gender.MALE)}
|
||||
genderF.setOnClickListener{selectGender(Gender.FEMALE)}
|
||||
genderM.setOnClickListener { selectGender(Gender.MALE) }
|
||||
genderF.setOnClickListener { selectGender(Gender.FEMALE) }
|
||||
|
||||
backBtn.setOnClickListener { activity?.onBackPressedDispatcher?.onBackPressed() }
|
||||
|
||||
next.setOnClickListener {
|
||||
findNavController().navigate(R.id.action_getMoreInfoFragment_to_selectAvatarFragment)
|
||||
if (viewModel.selectedGender == Gender.NONE) {
|
||||
Toast.makeText(activity, "Select a gender", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
findNavController().navigate(R.id.action_getMoreInfoFragment_to_selectAvatarFragment,
|
||||
Bundle().apply
|
||||
{
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
selectGender(selectedGender)
|
||||
selectGender(viewModel.selectedGender)
|
||||
|
||||
binding.apply {
|
||||
if (isUnder16){
|
||||
if (isUnder16) {
|
||||
// child
|
||||
datePicker.minDate =
|
||||
Calendar.getInstance().apply { add(Calendar.YEAR, -16) }.timeInMillis
|
||||
datePicker.maxDate =
|
||||
Calendar.getInstance().apply { add(Calendar.YEAR, -3) }.timeInMillis
|
||||
|
||||
interestView.visibility = VISIBLE
|
||||
|
||||
// static
|
||||
@@ -77,18 +96,35 @@ class GetMoreInfoFragment : Fragment() {
|
||||
addView(InterestTopicView(context, "Education"))
|
||||
}
|
||||
|
||||
} else {
|
||||
// parent
|
||||
datePicker.minDate =
|
||||
Calendar.getInstance().apply { add(Calendar.YEAR, -150) }.timeInMillis
|
||||
datePicker.maxDate =
|
||||
Calendar.getInstance().apply { add(Calendar.YEAR, -16) }.timeInMillis
|
||||
}
|
||||
|
||||
name.text = userName
|
||||
name.text = viewModel.name
|
||||
|
||||
datePicker.init(
|
||||
viewModel.selectedDOB.get(Calendar.YEAR),
|
||||
viewModel.selectedDOB.get(Calendar.MONTH),
|
||||
viewModel.selectedDOB.get(Calendar.DAY_OF_MONTH)
|
||||
) { v, year, monthOfYear, dayOfMonth ->
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(Calendar.YEAR, year)
|
||||
cal.set(Calendar.MONTH, monthOfYear)
|
||||
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth)
|
||||
|
||||
viewModel.selectedDOB = cal
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun selectGender(gender: Gender){
|
||||
if (selectedGender == gender) return
|
||||
|
||||
private fun selectGender(gender: Gender) {
|
||||
binding.apply {
|
||||
when(gender){
|
||||
when (gender) {
|
||||
Gender.MALE -> {
|
||||
genderM.setCardBackgroundColor(Color.WHITE)
|
||||
genderM.cardElevation = 5f
|
||||
@@ -96,6 +132,7 @@ class GetMoreInfoFragment : Fragment() {
|
||||
genderF.setCardBackgroundColor(resources.getColor(R.color.white_50))
|
||||
genderF.cardElevation = 0f
|
||||
}
|
||||
|
||||
Gender.FEMALE -> {
|
||||
genderF.setCardBackgroundColor(Color.WHITE)
|
||||
genderF.cardElevation = 5f
|
||||
@@ -103,6 +140,7 @@ class GetMoreInfoFragment : Fragment() {
|
||||
genderM.setCardBackgroundColor(resources.getColor(R.color.white_50))
|
||||
genderM.cardElevation = 0f
|
||||
}
|
||||
|
||||
Gender.NONE -> {
|
||||
genderM.setCardBackgroundColor(resources.getColor(R.color.white_50))
|
||||
genderM.cardElevation = 0f
|
||||
@@ -111,7 +149,8 @@ class GetMoreInfoFragment : Fragment() {
|
||||
genderF.cardElevation = 0f
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
viewModel.selectedGender = gender
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,54 @@
|
||||
package com.woka.onboard.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.databinding.FragmentSelectAvatarBinding
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.onboard.AvatarAdapter
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.models.Avatar
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.Gender
|
||||
import com.woka.utils.ProgressView
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
class SelectAvatarFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentSelectAvatarBinding
|
||||
|
||||
private var isUnder16: Boolean = false
|
||||
|
||||
private var adapter: AvatarAdapter? = null
|
||||
|
||||
private lateinit var viewModel: OnboardViewModel
|
||||
private lateinit var progressView: ProgressView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
isUnder16 = it.getBoolean(IS_UNDER_16)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = FragmentSelectAvatarBinding.inflate(inflater, container, false)
|
||||
activity?.let {
|
||||
viewModel = ViewModelProvider(it)[OnboardViewModel::class.java]
|
||||
progressView = ProgressView(it)
|
||||
}
|
||||
|
||||
clickEvents()
|
||||
return binding.root
|
||||
}
|
||||
@@ -32,56 +60,79 @@ class SelectAvatarFragment : Fragment() {
|
||||
}
|
||||
|
||||
next.setOnClickListener {
|
||||
if (adapter?.selectedPos == null){
|
||||
if (viewModel.selectedAvatarPos == null) {
|
||||
Toast.makeText(activity, "Please select an avatar", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
Toast.makeText(activity, "${adapter?.avatarList?.get(adapter?.selectedPos!!)?.id}", Toast.LENGTH_SHORT).show()
|
||||
|
||||
val registerRequestData = with(viewModel){
|
||||
RegisterRequestData(
|
||||
add_child = if (isUnder16) null else "1",
|
||||
avtar = adapter?.avatarList?.get(selectedAvatarPos!!)?.avatar_name,
|
||||
birthdate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(selectedDOB.time),
|
||||
email = email,
|
||||
full_name = name,
|
||||
gender = if (selectedGender == Gender.MALE) "2" else "1",
|
||||
guardian_email = null,
|
||||
language_id = if (userPrefs?.appLanguage == "en") "1" else "2",
|
||||
password = password,
|
||||
user_type = if (isUnder16) "1" else "2",
|
||||
username = userName
|
||||
)
|
||||
}
|
||||
|
||||
viewModel.registerUser(registerRequestData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
// static avatars
|
||||
adapter = AvatarAdapter(
|
||||
listOf(
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar1.png?d=1714636151",
|
||||
"1", 1
|
||||
),
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar2.png?d=1714636151",
|
||||
"2", 2
|
||||
),
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar3.png?d=1714636151",
|
||||
"1", 3
|
||||
),
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar4.png?d=1714636151",
|
||||
"2", 4
|
||||
),
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar1.png?d=1714636151",
|
||||
"1", 5
|
||||
),
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar2.png?d=1714636151",
|
||||
"2", 6
|
||||
),
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar3.png?d=1714636151",
|
||||
"1", 7
|
||||
),
|
||||
Avatar(
|
||||
"https://wokastaging.in/storage/app/public/uploads/avtar/avatar4.png?d=1714636151",
|
||||
"2", 8
|
||||
)
|
||||
)
|
||||
)
|
||||
viewModel.avatarListLiveData.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
binding.rvAvatar.adapter = adapter
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show("Loading avatars...")
|
||||
}
|
||||
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
it.data?.result?.let { avatarList ->
|
||||
adapter = AvatarAdapter(avatarList, viewModel.selectedAvatarPos) { pos ->
|
||||
viewModel.selectedAvatarPos = pos
|
||||
}
|
||||
binding.rvAvatar.adapter = adapter
|
||||
}
|
||||
}
|
||||
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
if (!viewModel.avatarListLiveData.isInitialized) {
|
||||
viewModel.getAvatarList()
|
||||
}
|
||||
|
||||
viewModel.registerUserLiveData.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show("Please wait...")
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import com.woka.databinding.FragmentSignUpBinding
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.onboard.fragments.GetCodeFragment.Companion.EMAIL_ARG
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.fragments.GetMoreInfoFragment.Companion.USER_NAME_ARG
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.CHILD_TYPE
|
||||
import com.woka.utils.PARENT_TYPE
|
||||
@@ -72,9 +71,15 @@ class SignUpFragment : Fragment() {
|
||||
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
|
||||
binding.apply {
|
||||
viewModel.userName = username.text.toString()
|
||||
viewModel.name = name.text.toString()
|
||||
viewModel.password = password.text?.toString()
|
||||
}
|
||||
|
||||
val args = Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, isUnder16)
|
||||
putString(USER_NAME_ARG, binding.name.text.trim().toString())
|
||||
}
|
||||
|
||||
findNavController().navigate(
|
||||
@@ -98,6 +103,10 @@ class SignUpFragment : Fragment() {
|
||||
if (isUnder16) {
|
||||
doNotShare.visibility = VISIBLE
|
||||
}
|
||||
|
||||
name.setText(viewModel.name)
|
||||
username.setText(viewModel.userName)
|
||||
password.setText(viewModel.password)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class Avatar(
|
||||
val avatar_image_url: String,
|
||||
val avatar_name: String,
|
||||
val avatar_image_url: String?,
|
||||
val avatar_name: String?,
|
||||
val id: Int
|
||||
)
|
||||
6
app/src/main/java/com/woka/onboard/models/AvatarList.kt
Normal file
6
app/src/main/java/com/woka/onboard/models/AvatarList.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class AvatarList(
|
||||
val result: List<Avatar>,
|
||||
val total_records: Int
|
||||
)
|
||||
8
app/src/main/java/com/woka/onboard/models/Child.kt
Normal file
8
app/src/main/java/com/woka/onboard/models/Child.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class Child(
|
||||
val avtar: String,
|
||||
val fullname: String,
|
||||
val id: Int,
|
||||
val username: String
|
||||
)
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class ChildListResponse(
|
||||
val result: List<Child>
|
||||
)
|
||||
6
app/src/main/java/com/woka/onboard/models/GenderX.kt
Normal file
6
app/src/main/java/com/woka/onboard/models/GenderX.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class GenderX(
|
||||
val gender_name: String,
|
||||
val id: Int
|
||||
)
|
||||
6
app/src/main/java/com/woka/onboard/models/LanguageX.kt
Normal file
6
app/src/main/java/com/woka/onboard/models/LanguageX.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class LanguageX(
|
||||
val id: Int,
|
||||
val language_name: String
|
||||
)
|
||||
18
app/src/main/java/com/woka/onboard/models/RegisterData.kt
Normal file
18
app/src/main/java/com/woka/onboard/models/RegisterData.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class RegisterData(
|
||||
val already_logged_in: Boolean,
|
||||
val avtar: String,
|
||||
val birthdate: String,
|
||||
val child_detail: Any,
|
||||
val email: String,
|
||||
val fullname: String,
|
||||
val gender: GenderX,
|
||||
val id: Int,
|
||||
val language: LanguageX,
|
||||
val language_master_id: Int,
|
||||
val last_login: String,
|
||||
val remember_token: String,
|
||||
val user_type: String,
|
||||
val username: String
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class RegisterRequestData(
|
||||
val add_child: String?,
|
||||
val avtar: String?,
|
||||
val birthdate: String?,
|
||||
val email: String?,
|
||||
val full_name: String?,
|
||||
val gender: String?,
|
||||
val guardian_email: String?,
|
||||
val language_id: String? = "1",
|
||||
val password: String?,
|
||||
val user_type: String?,
|
||||
val username: String?
|
||||
)
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class RegisterResponse(
|
||||
val result: RegisterData
|
||||
)
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.woka.onboard.mvvm
|
||||
|
||||
import com.woka.networking.ApiResponse
|
||||
import com.woka.onboard.models.AvatarList
|
||||
import com.woka.onboard.models.ChildListResponse
|
||||
import com.woka.onboard.models.LoginResponse
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
import com.woka.onboard.models.RegisterResponse
|
||||
import com.woka.onboard.models.VerifyEmail
|
||||
import okhttp3.FormBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
|
||||
interface OnboardApiService {
|
||||
@@ -28,4 +33,13 @@ interface OnboardApiService {
|
||||
@POST("check_exist_username")
|
||||
suspend fun checkUserNameExist(@Body body: FormBody): Response<ApiResponse<Any>>
|
||||
|
||||
@GET("avatar_listing")
|
||||
suspend fun getAvatarList(): Response<ApiResponse<AvatarList>>
|
||||
|
||||
@POST("child_registration")
|
||||
suspend fun registerUser(@Body registerRequestData: RegisterRequestData): Response<ApiResponse<RegisterResponse>>
|
||||
|
||||
@POST("get_linked_child")
|
||||
suspend fun getChildList(@Body body: FormBody): Response<ApiResponse<ChildListResponse>>
|
||||
|
||||
}
|
||||
@@ -4,7 +4,11 @@ import com.woka.networking.ApiResponse
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper.handleApiCall
|
||||
import com.woka.networking.RetrofitHelper.handleApiResponse
|
||||
import com.woka.onboard.models.AvatarList
|
||||
import com.woka.onboard.models.ChildListResponse
|
||||
import com.woka.onboard.models.LoginResponse
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
import com.woka.onboard.models.RegisterResponse
|
||||
import com.woka.onboard.models.VerifyEmail
|
||||
import com.woka.utils.NO_INTERNET_MESSAGE
|
||||
import com.woka.utils.UNKNOWN_ERROR_MESSAGE
|
||||
@@ -81,4 +85,26 @@ class OnboardRepository(private val apiService: OnboardApiService) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getAvatarList(): ApiResult<AvatarList>{
|
||||
return handleApiCall {
|
||||
apiService.getAvatarList()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun registerUser(registerRequestData: RegisterRequestData): ApiResult<RegisterResponse>{
|
||||
return handleApiCall {
|
||||
apiService.registerUser(registerRequestData)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getChildList(email: String): ApiResult<ChildListResponse>{
|
||||
return handleApiCall {
|
||||
apiService.getChildList(
|
||||
FormBody.Builder()
|
||||
.add("email", email)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,31 @@ import androidx.lifecycle.ViewModel
|
||||
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.ChildListResponse
|
||||
import com.woka.onboard.models.LoginResponse
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
import com.woka.onboard.models.RegisterResponse
|
||||
import com.woka.onboard.models.VerifyEmail
|
||||
import com.woka.utils.Gender
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Calendar
|
||||
|
||||
class OnboardViewModel: ViewModel(){
|
||||
|
||||
private val repository: OnboardRepository = OnboardRepository(RetrofitHelper.getRetrofit().create(OnboardApiService::class.java))
|
||||
|
||||
// user registration data
|
||||
var email: String? = null
|
||||
var selectedAvatarPos: Int? = null
|
||||
var selectedGender: Gender = Gender.NONE
|
||||
var selectedDOB: Calendar = Calendar.getInstance()
|
||||
var userName: String? = null
|
||||
var name: String? = null
|
||||
var password: String? = null
|
||||
|
||||
// live_data
|
||||
/*
|
||||
Login Fragment
|
||||
@@ -60,6 +76,18 @@ class OnboardViewModel: ViewModel(){
|
||||
get() = _checkUserNameExistLiveData
|
||||
|
||||
|
||||
/*
|
||||
SelectAvatarFragment
|
||||
*/
|
||||
private val _avatarListLiveData = MutableLiveData<ApiResult<AvatarList>?>()
|
||||
val avatarListLiveData: LiveData<ApiResult<AvatarList>?>
|
||||
get() = _avatarListLiveData
|
||||
|
||||
private val _registerUserLiveData = MutableLiveData<ApiResult<RegisterResponse>?>()
|
||||
fun clearRegisterUserData() = _registerUserLiveData.postValue(null)
|
||||
val registerUserLiveData: LiveData<ApiResult<RegisterResponse>?>
|
||||
get() = _registerUserLiveData
|
||||
|
||||
fun login(userName: String, password: String){
|
||||
viewModelScope.launch {
|
||||
_loginLiveData.postValue(ApiResult.Loading())
|
||||
@@ -108,8 +136,30 @@ class OnboardViewModel: ViewModel(){
|
||||
}
|
||||
}
|
||||
|
||||
fun getAvatarList(){
|
||||
viewModelScope.launch {
|
||||
_avatarListLiveData.postValue(ApiResult.Loading())
|
||||
val response = repository.getAvatarList()
|
||||
_avatarListLiveData.postValue(response)
|
||||
}
|
||||
}
|
||||
|
||||
fun registerUser(registerRequestData: RegisterRequestData){
|
||||
viewModelScope.launch {
|
||||
_registerUserLiveData.postValue(ApiResult.Loading())
|
||||
val response = repository.registerUser(registerRequestData)
|
||||
_registerUserLiveData.postValue(response)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getChildList(email: String): ApiResult<ChildListResponse>{
|
||||
return viewModelScope.async {
|
||||
repository.getChildList(email)
|
||||
}.await()
|
||||
}
|
||||
|
||||
// otp count down timer
|
||||
private val OTP_RESEND_COUNT_DOWN_TIME = 10 * 60 * 1000L // 10 min
|
||||
private val OTP_RESEND_COUNT_DOWN_TIME = 30 * 1000L // 10 min
|
||||
|
||||
private var countDownTimer: CountDownTimer? = null
|
||||
private var _otpResendTimeLiveData = MutableLiveData<Long>()
|
||||
|
||||
@@ -192,6 +192,7 @@
|
||||
/>
|
||||
|
||||
<DatePicker
|
||||
android:id="@+id/date_picker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:datePickerMode="spinner"
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
android:paddingVertical="15dp"
|
||||
|
||||
android:maxLength="16"
|
||||
android:digits="@string/alphanumeric"
|
||||
|
||||
/>
|
||||
|
||||
@@ -157,6 +158,8 @@
|
||||
|
||||
android:maxLength="50"
|
||||
|
||||
android:digits="@string/alphanumeric_with_space"
|
||||
|
||||
/>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
android:name="com.woka.onboard.fragments.GetEmailFragment"
|
||||
android:label="fragment_get_email"
|
||||
tools:layout="@layout/fragment_get_email" >
|
||||
<argument
|
||||
android:name="is_under_16"
|
||||
app:argType="boolean"
|
||||
android:defaultValue="false" />
|
||||
<action
|
||||
android:id="@+id/action_getEmailFragment_to_getCodeFragment"
|
||||
app:destination="@id/getCodeFragment" />
|
||||
@@ -50,10 +46,16 @@
|
||||
android:defaultValue="false" />
|
||||
<action
|
||||
android:id="@+id/action_getCodeFragment_to_signUpFragment"
|
||||
app:destination="@id/signUpFragment" />
|
||||
app:destination="@id/signUpFragment"
|
||||
app:popUpTo="@id/getEmailFragment"
|
||||
app:popUpToInclusive="false"
|
||||
/>
|
||||
<action
|
||||
android:id="@+id/action_getCodeFragment_to_newPasswordFragment2"
|
||||
app:destination="@id/newPasswordFragment2" />
|
||||
app:destination="@id/newPasswordFragment2"
|
||||
app:popUpTo="@id/getEmailFragment"
|
||||
app:popUpToInclusive="false"
|
||||
/>
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/signUpFragment"
|
||||
|
||||
@@ -70,5 +70,6 @@
|
||||
<string name="enter_your_password">Enter your password</string>
|
||||
<string name="please_wait">Please wait...</string>
|
||||
<string name="alphanumeric" translatable="false">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890</string>
|
||||
<string name="alphanumeric_with_space" translatable="false">ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890</string>
|
||||
<string name="resend_otp">Resend OTP?</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user