childList fragment
This commit is contained in:
@@ -71,6 +71,9 @@ dependencies {
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
|
||||
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
|
||||
|
||||
// circle image view
|
||||
implementation 'de.hdodenhof:circleimageview:3.1.0'
|
||||
|
||||
implementation libs.androidx.core.ktx
|
||||
implementation libs.androidx.appcompat
|
||||
implementation libs.material
|
||||
|
||||
@@ -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>()
|
||||
|
||||
48
app/src/main/res/layout/child_view_holder.xml
Normal file
48
app/src/main/res/layout/child_view_holder.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
app:cardCornerRadius="@dimen/_20sdp"
|
||||
app:cardElevation="0dp"
|
||||
app:cardBackgroundColor="@color/white_60">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginVertical="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="@dimen/_40sdp"
|
||||
android:layout_height="@dimen/_40sdp"
|
||||
|
||||
tools:src="@mipmap/ic_launcher"
|
||||
app:civ_circle_background_color="@color/white"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
tools:text="Aditya Gaikwad"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
android:textColor="@color/color_primary"
|
||||
android:textSize="@dimen/_12ssp"
|
||||
|
||||
android:layout_marginStart="15dp"
|
||||
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
113
app/src/main/res/layout/fragment_child_list.xml
Normal file
113
app/src/main/res/layout/fragment_child_list.xml
Normal file
@@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="@drawable/splash_bg"
|
||||
tools:context=".onboard.fragments.ChildListFragment">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_btn"
|
||||
android:layout_width="@dimen/_25sdp"
|
||||
android:layout_height="@dimen/_25sdp"
|
||||
android:contentDescription="@string/back_btn"
|
||||
android:src="@drawable/ic_arrow_back"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/logo"
|
||||
app:layout_constraintEnd_toStartOf="@+id/logo"
|
||||
app:layout_constraintHorizontal_bias="0.30"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/logo"
|
||||
app:tint="@color/color_primary" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/logo"
|
||||
android:layout_width="140dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
|
||||
android:contentDescription="@string/app_name"
|
||||
android:src="@drawable/woka_logo_full"
|
||||
|
||||
android:transitionName="logo"
|
||||
|
||||
android:layout_marginTop="15dp"
|
||||
|
||||
android:visibility="visible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:text="@string/your_email_looks_familiar"
|
||||
android:fontFamily="@font/exo_2_medium"
|
||||
android:textSize="@dimen/_18ssp"
|
||||
android:textColor="@color/color_primary"
|
||||
android:textAlignment="center"
|
||||
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/logo"
|
||||
|
||||
android:layout_marginTop="15dp"
|
||||
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sub_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:text="@string/we_found_below_usernames_linked_to_this_email_address"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
android:textSize="@dimen/_11ssp"
|
||||
android:textColor="@color/color_primary"
|
||||
android:textAlignment="center"
|
||||
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title"
|
||||
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
|
||||
/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_child"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@id/sub_title"
|
||||
app:layout_constraintBottom_toTopOf="@id/next"
|
||||
|
||||
android:layout_marginVertical="15dp"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/child_view_holder"
|
||||
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:text="@string/next"
|
||||
android:textColor="@color/white"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
|
||||
android:background="@drawable/grad_btn_bg_4"
|
||||
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginBottom="@dimen/_25sdp"
|
||||
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -56,6 +56,12 @@
|
||||
app:popUpTo="@id/getEmailFragment"
|
||||
app:popUpToInclusive="false"
|
||||
/>
|
||||
<action
|
||||
android:id="@+id/action_getCodeFragment_to_childListFragment"
|
||||
app:destination="@id/childListFragment"
|
||||
app:popUpTo="@id/getEmailFragment"
|
||||
app:popUpToInclusive="false"
|
||||
/>
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/signUpFragment"
|
||||
@@ -105,4 +111,13 @@
|
||||
android:name="com.woka.onboard.fragments.NewPasswordFragment"
|
||||
android:label="fragment_new_password"
|
||||
tools:layout="@layout/fragment_new_password" />
|
||||
<fragment
|
||||
android:id="@+id/childListFragment"
|
||||
android:name="com.woka.onboard.fragments.ChildListFragment"
|
||||
android:label="fragment_child_list"
|
||||
tools:layout="@layout/fragment_child_list" >
|
||||
<action
|
||||
android:id="@+id/action_childListFragment_to_signUpFragment"
|
||||
app:destination="@id/signUpFragment" />
|
||||
</fragment>
|
||||
</navigation>
|
||||
@@ -72,4 +72,6 @@
|
||||
<string name="alphanumeric" translatable="false">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890</string>
|
||||
<string name="alphanumeric_with_space" translatable="false">ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890</string>
|
||||
<string name="resend_otp">Resend OTP?</string>
|
||||
<string name="your_email_looks_familiar">Your Email Looks Familiar!</string>
|
||||
<string name="we_found_below_usernames_linked_to_this_email_address">WE FOUND BELOW USERNAMES LINKED TO THIS EMAIL ADDRESS</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user