Login Api and login proceed api integration
DecisionDialog implemented For password api integration started
This commit is contained in:
@@ -60,7 +60,6 @@ object RetrofitHelper {
|
||||
// api caller
|
||||
suspend fun <T>handleApiCall(apiCall: suspend () -> Response<ApiResponse<T>>): ApiResult<T> {
|
||||
return try {
|
||||
delay(3000)
|
||||
val response = apiCall() // this api call can throw some exception
|
||||
handleApiResponse(response) // handling the response
|
||||
} catch (e: UnknownHostException) {
|
||||
|
||||
@@ -28,7 +28,7 @@ class ChildAdapter(private val childList: List<Child>) : RecyclerView.Adapter<Ch
|
||||
.fitCenter()
|
||||
.into(image)
|
||||
|
||||
name.text = childList[position].fullname
|
||||
name.text = childList[position].username
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,11 @@ class GetMoreInfoFragment : Fragment() {
|
||||
Toast.makeText(activity, getString(R.string.select_a_gender), Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (viewModel.interestTopics.isEmpty()){
|
||||
Toast.makeText(activity,
|
||||
getString(R.string.please_select_your_interests), Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
findNavController().navigate(R.id.action_getMoreInfoFragment_to_selectAvatarFragment,
|
||||
Bundle().apply
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.woka.databinding.FragmentSignInBinding
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_RESET_PASSWORD_INTENT
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.DecisionDialog
|
||||
import com.woka.utils.ProgressView
|
||||
|
||||
class SignInFragment : Fragment() {
|
||||
@@ -25,6 +26,8 @@ class SignInFragment : Fragment() {
|
||||
|
||||
private lateinit var progressView: ProgressView
|
||||
|
||||
private lateinit var dialog: DecisionDialog
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -36,7 +39,21 @@ class SignInFragment : Fragment() {
|
||||
|
||||
viewModel = ViewModelProvider(it)[OnboardViewModel::class.java]
|
||||
|
||||
progressView = ProgressView(it)
|
||||
progressView = ProgressView(it, getString(R.string.please_wait))
|
||||
|
||||
dialog = DecisionDialog(it).apply {
|
||||
title = getString(R.string.already_logged_in)
|
||||
message = getString(R.string.do_you_want_to_continue_log_in)
|
||||
|
||||
setPositiveButton(getString(R.string.yes)){
|
||||
viewModel.loginProceed(
|
||||
binding.username.text.toString(),
|
||||
binding.password.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
setNegativeButton(getString(R.string.no))
|
||||
}
|
||||
}
|
||||
|
||||
clickEvents()
|
||||
@@ -57,17 +74,34 @@ class SignInFragment : Fragment() {
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
it.data?.result?.let {
|
||||
if (it.already_logged_in){
|
||||
Toast.makeText(activity, "Already logged in", Toast.LENGTH_SHORT).show()
|
||||
it.data?.result?.let {data->
|
||||
if (data.already_logged_in){
|
||||
dialog.show()
|
||||
}else{
|
||||
Toast.makeText(activity, "Log in successful", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.loginProceedData.observe(viewLifecycleOwner){
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show()
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
@@ -105,7 +139,7 @@ class SignInFragment : Fragment() {
|
||||
}
|
||||
|
||||
viewModel.login(username.text.toString(), password.toString())
|
||||
}?:Toast.makeText(activity, "Something went wrong!", Toast.LENGTH_SHORT).show()
|
||||
}?:Toast.makeText(activity, getString(R.string.something_went_wrong), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
data class ForgotPasswrodOTPResponse(
|
||||
val email: String?
|
||||
)
|
||||
@@ -3,6 +3,7 @@ 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.ForgotPasswrodOTPResponse
|
||||
import com.woka.onboard.models.InterestTopicResponse
|
||||
import com.woka.onboard.models.LoginResponse
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
@@ -46,4 +47,7 @@ interface OnboardApiService {
|
||||
@POST("interest_topic_listing")
|
||||
suspend fun getInterestedTopics(): Response<ApiResponse<InterestTopicResponse>>
|
||||
|
||||
@POST("forgot_password_send_otp")
|
||||
suspend fun forgotPasswordSendOTP(@Body body: FormBody): Response<ApiResponse<ForgotPasswrodOTPResponse>>
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ 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.ForgotPasswrodOTPResponse
|
||||
import com.woka.onboard.models.InterestTopicResponse
|
||||
import com.woka.onboard.models.LoginResponse
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
@@ -114,4 +115,14 @@ class OnboardRepository(private val apiService: OnboardApiService) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun forgotPasswordSendOTP(userName: String): ApiResult<ForgotPasswrodOTPResponse>{
|
||||
return handleApiCall {
|
||||
apiService.forgotPasswordSendOTP(
|
||||
FormBody.Builder()
|
||||
.add("username", userName)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
91
app/src/main/java/com/woka/utils/DecisionDialog.kt
Normal file
91
app/src/main/java/com/woka/utils/DecisionDialog.kt
Normal file
@@ -0,0 +1,91 @@
|
||||
package com.woka.utils
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.WindowManager
|
||||
import com.woka.databinding.LayoutDecisionDialogBinding
|
||||
|
||||
class DecisionDialog(context: Context) {
|
||||
private val binding: LayoutDecisionDialogBinding
|
||||
|
||||
private val dialog: Dialog
|
||||
|
||||
var title: String
|
||||
get() = binding.title.text.toString()
|
||||
set(value) {
|
||||
binding.title.text = value
|
||||
}
|
||||
|
||||
var message: String
|
||||
get() = binding.message.text.toString()
|
||||
set(value) {
|
||||
binding.message.text = value
|
||||
}
|
||||
|
||||
init {
|
||||
binding = LayoutDecisionDialogBinding.inflate(
|
||||
LayoutInflater.from(context)
|
||||
)
|
||||
|
||||
dialog = Dialog(context)
|
||||
dialog.setContentView(binding.getRoot())
|
||||
|
||||
try {
|
||||
val back = ColorDrawable(Color.TRANSPARENT)
|
||||
val inset = InsetDrawable(back, 50)
|
||||
dialog.window!!.setBackgroundDrawable(inset)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
val layoutParams = dialog.window!!.attributes
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
dialog.window!!.setAttributes(layoutParams)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
fun setPositiveButton(text: String, click: () -> Unit){
|
||||
binding.positiveBtn.apply {
|
||||
visibility = VISIBLE
|
||||
this.text = text
|
||||
setOnClickListener {
|
||||
click()
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setNegativeButton(text: String, click: (() -> Unit)? = null){
|
||||
binding.negativeBtn.apply {
|
||||
visibility = VISIBLE
|
||||
this.text = text
|
||||
setOnClickListener {
|
||||
click?.invoke()
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun show(titleTxt: String, messageTxt: String): DecisionDialog{
|
||||
binding.apply {
|
||||
title.text = titleTxt
|
||||
message.text = messageTxt
|
||||
}.also {
|
||||
show()
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun show() = dialog.show()
|
||||
|
||||
fun dismiss() = dialog.dismiss()
|
||||
}
|
||||
@@ -27,15 +27,17 @@ class ProgressView(context: Context, title: String? = null): ContextWrapper(cont
|
||||
}?: GONE
|
||||
}
|
||||
|
||||
fun show(title: String? = null) {
|
||||
binding.title.visibility = title?.let {
|
||||
binding.title.text = it
|
||||
VISIBLE
|
||||
}?: GONE
|
||||
fun show(title: String) {
|
||||
binding.title.apply{
|
||||
text = title
|
||||
visibility = VISIBLE
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
show()
|
||||
}
|
||||
|
||||
fun show() = dialog.show()
|
||||
|
||||
fun hide() = dialog.dismiss()
|
||||
|
||||
fun setTitle(title: String) {
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
|
||||
android:hint="@string/otp_hint"
|
||||
android:textColorHint="@android:color/darker_gray"
|
||||
|
||||
android:background="@drawable/otp_et_bg"
|
||||
@@ -138,6 +139,7 @@
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
|
||||
android:hint="@string/otp_hint"
|
||||
android:textColorHint="@android:color/darker_gray"
|
||||
|
||||
android:background="@drawable/otp_et_bg"
|
||||
@@ -168,6 +170,7 @@
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
|
||||
android:hint="@string/otp_hint"
|
||||
android:textColorHint="@android:color/darker_gray"
|
||||
|
||||
android:background="@drawable/otp_et_bg"
|
||||
@@ -197,6 +200,7 @@
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
|
||||
android:hint="@string/otp_hint"
|
||||
android:textColorHint="@android:color/darker_gray"
|
||||
|
||||
android:background="@drawable/otp_et_bg"
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
|
||||
android:text="@string/can_we_have_your_email"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
android:textSize="@dimen/_12ssp"
|
||||
android:textColor="@color/color_primary"
|
||||
android:textAlignment="center"
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
android:background="@drawable/round_25_shadow"
|
||||
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
|
||||
android:elevation="5dp"
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
android:background="@drawable/round_25_shadow"
|
||||
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
|
||||
android:elevation="5dp"
|
||||
@@ -112,7 +112,7 @@
|
||||
android:paddingVertical="15dp"
|
||||
|
||||
android:maxLength="16"
|
||||
android:digits="@string/alphanumeric"
|
||||
android:digits="@string/alphanumeric_special_characters_without_space"
|
||||
|
||||
/>
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
android:background="@drawable/round_25_shadow"
|
||||
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
|
||||
android:elevation="5dp"
|
||||
@@ -179,8 +179,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginVertical="15dp"
|
||||
app:cardElevation="5dp"
|
||||
android:layout_marginVertical="10dp"
|
||||
app:cardElevation="3dp"
|
||||
app:cardCornerRadius="25dp"
|
||||
>
|
||||
|
||||
|
||||
106
app/src/main/res/layout/layout_decision_dialog.xml
Normal file
106
app/src/main/res/layout/layout_decision_dialog.xml
Normal file
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/round_25"
|
||||
android:backgroundTint="@color/white"
|
||||
android:orientation="vertical"
|
||||
android:paddingVertical="0dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:textAlignment="center"
|
||||
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
|
||||
android:maxLines="2"
|
||||
android:textSize="@dimen/_16ssp"
|
||||
android:textColor="@color/color_primary"
|
||||
tools:text="Dialog title"
|
||||
|
||||
/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/darker_gray" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:layout_marginVertical="10dp"
|
||||
android:fontFamily="@font/exo_2_medium"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
|
||||
android:textColor="@color/color_primary"
|
||||
tools:text="This is message that will be shown as subtitle"
|
||||
|
||||
/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:layout_marginTop="25dp"
|
||||
>
|
||||
|
||||
<Button
|
||||
android:id="@+id/negative_btn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:visibility="gone"
|
||||
|
||||
tools:text="No"
|
||||
android:textColor="@color/white"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
|
||||
android:background="@drawable/grad_btn_bg_4"
|
||||
|
||||
android:layout_marginHorizontal="5dp"
|
||||
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/positive_btn"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/positive_btn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:visibility="gone"
|
||||
|
||||
tools:text="Yes"
|
||||
android:textColor="@color/white"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
|
||||
android:background="@drawable/grad_btn_bg_4"
|
||||
|
||||
android:layout_marginHorizontal="5dp"
|
||||
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/negative_btn"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -80,4 +80,9 @@
|
||||
<string name="select_a_gender">एक लिंग चुनें</string>
|
||||
<string name="please_select_an_avatar">कृपया एक अवतार चुनें</string>
|
||||
<string name="loading_avatars">अवतार लोड हो रहे हैं...</string>
|
||||
<string name="please_select_your_interests">कृपया अपनी रुचियों का चयन करें</string>
|
||||
<string name="already_logged_in">पहले से लॉग्ड इन</string>
|
||||
<string name="do_you_want_to_continue_log_in">क्या आप लॉग इन जारी रखना चाहते हैं?</string>
|
||||
<string name="yes">हाँ</string>
|
||||
<string name="no">नहीं</string>
|
||||
</resources>
|
||||
@@ -85,4 +85,11 @@
|
||||
<string name="select_a_gender">Select a gender</string>
|
||||
<string name="please_select_an_avatar">Please select an avatar</string>
|
||||
<string name="loading_avatars">Loading avatars...</string>
|
||||
<string name="otp_hint" translatable="false">*</string>
|
||||
<string name="please_select_your_interests">Please select your interests</string>
|
||||
<string name="alphanumeric_special_characters_without_space" translatable="false"><![CDATA[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!#$%&\'*+/-=^_`{|}~.@]]></string>
|
||||
<string name="already_logged_in">Already logged in</string>
|
||||
<string name="do_you_want_to_continue_log_in">Do you want to continue log in?</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user