Skip to content

Commit

Permalink
register fragment debugged
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketk13 committed Mar 23, 2023
1 parent 92f24ce commit 5e9bb82
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/teamdefine/signease/api/HelloSignAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ interface HelloSignAPI {
@Headers("Content-Type: application/json")
@POST("v3/api_app")
suspend fun createApp(@Body body: CreateAPIApp): CreateAppResponse

@DELETE("v3/api_app/{client_id}")
suspend fun deleteApp(@Path("client_id") clientId: String): retrofit2.Response<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.teamdefine.signease.loginandregister

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
Expand All @@ -14,6 +16,7 @@ import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.ktx.Firebase
import com.teamdefine.signease.databinding.FragmentRegisterBinding


class RegisterFragment : Fragment() {
private lateinit var binding: FragmentRegisterBinding //binding
private lateinit var auth: FirebaseAuth //firebase auth
Expand All @@ -36,6 +39,14 @@ class RegisterFragment : Fragment() {
binding.progressBar.visibility = View.VISIBLE
registerUser(fullName, uid, email, password, clientId)
}
viewModel.deleteClient.observe(requireActivity()) {
if (it == true) {
binding.progressBar.visibility = View.GONE
binding.inputPassword.setText("")
binding.inputPassword.requestFocus()
view?.showKeyboard()
}
}
//on click of sign up button
binding.signUpButton.setOnClickListener {
fullName = binding.inputName.text.toString()
Expand Down Expand Up @@ -74,15 +85,23 @@ class RegisterFragment : Fragment() {
//once successfully authenticated, save user data to firestore
saveUserData(fullName, uid, clientId, currentUser.uid)
}
} else
} else {
Toast.makeText(
activity,
task.exception!!.message.toString(),
Toast.LENGTH_LONG
).show()
viewModel.deleteClient(clientId)
}

}
}

private fun View.showKeyboard() {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
}

//saving user data to firestore
private fun saveUserData(fullName: String, uid: String, clientId: String, currentUser: String) {
val database = FirebaseFirestore.getInstance()
Expand All @@ -97,7 +116,6 @@ class RegisterFragment : Fragment() {
Toast.makeText(activity, "Registered Successfully", Toast.LENGTH_SHORT).show()
findNavController().navigate(RegisterFragmentDirections.actionRegisterFragmentToLoginFragment())
}.addOnFailureListener { e ->
binding.progressBar.visibility = View.GONE
Toast.makeText(activity, e.toString(), Toast.LENGTH_LONG).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class RegisterViewModel : ViewModel() {
val appResponse: LiveData<CreateAppResponse>
get() = _appResponse

private val _deleteClient: MutableLiveData<Boolean> = MutableLiveData(false)
val deleteClient: LiveData<Boolean>
get() = _deleteClient

fun getClientId(uid: String) {
val name = "Sign Ease${uid}"
val domains = arrayListOf<String>()
Expand All @@ -24,10 +28,25 @@ class RegisterViewModel : ViewModel() {
viewModelScope.launch {
try {
val response = RetrofitInstance.api.createApp(body)
Log.i("clientId", response.toString())
_appResponse.value = response
} catch (e: Exception) {
Log.i("helloabc", e.toString())
}
}
}

fun deleteClient(clientId: String) {
viewModelScope.launch {
try {
val response = RetrofitInstance.api.deleteApp(clientId)
Log.i("success", response.toString())
if (response.code() == 204)
_deleteClient.value = true

} catch (e: Exception) {
Log.i("helloabc", e.toString())
}
}
}
}

0 comments on commit 5e9bb82

Please sign in to comment.