Skip to content

Commit

Permalink
Fixed NGO registration bug
Browse files Browse the repository at this point in the history
  • Loading branch information
1HazArd1 committed Sep 30, 2022
1 parent 125ea36 commit c5abbac
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 91 deletions.
25 changes: 13 additions & 12 deletions app/src/main/java/com/hazard/samarpan/common/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.hazard.samarpan.R
import com.hazard.samarpan.ngo.Communicator
import com.hazard.samarpan.ngo.NgoSignup2Fragment

class MainActivity : AppCompatActivity(),Communicator {
class MainActivity : AppCompatActivity(), Communicator {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
/*This part of the code is used to set the default theme as the theme was set to the splash screen before setting the main activity layout
Expand All @@ -18,8 +18,9 @@ class MainActivity : AppCompatActivity(),Communicator {
}

private fun addFragment() {
val userSignInLayout= LoginFragment()
supportFragmentManager.beginTransaction().add(R.id.fragment_container1,userSignInLayout).commit()
val userSignInLayout = LoginFragment()
supportFragmentManager.beginTransaction().add(R.id.fragment_container1, userSignInLayout)
.commit()
}

override fun passDataCom(
Expand All @@ -30,17 +31,17 @@ class MainActivity : AppCompatActivity(),Communicator {
orgPin: String,
orgPass: String
) {
val bundle=Bundle()
bundle.putString("Name",orgName)
bundle.putString("Mail",orgMail)
bundle.putString("Phone",orgPhone)
bundle.putString("Address",officeAdd)
bundle.putString("PinCode",orgPin)
bundle.putString("Password",orgPass)
val bundle = Bundle()
bundle.putString("Name", orgName)
bundle.putString("Mail", orgMail)
bundle.putString("Phone", orgPhone)
bundle.putString("Address", officeAdd)
bundle.putString("PinCode", orgPin)
bundle.putString("Password", orgPass)

val transaction=this.supportFragmentManager.beginTransaction()
val transaction = this.supportFragmentManager.beginTransaction()
val ngoSignUp2 = NgoSignup2Fragment()
ngoSignUp2.arguments = bundle
transaction.replace(R.id.fragment_container1,ngoSignUp2).addToBackStack(null).commit()
transaction.replace(R.id.fragment_container1, ngoSignUp2).addToBackStack(null).commit()
}
}
34 changes: 18 additions & 16 deletions app/src/main/java/com/hazard/samarpan/ngo/NgoSignup1Fragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class NgoSignup1Fragment : Fragment() {
private lateinit var communicator: Communicator
private lateinit var nextBtn: Button

private var name : TextInputEditText ?=null
private var mail : TextInputEditText ?=null
private var phone : TextInputEditText ?=null
private var add :TextInputEditText ?=null
private var pinCode :TextInputEditText ?=null
private var password :TextInputEditText ?=null
private var confirmPassword :TextInputEditText ?=null
private var name: TextInputEditText? = null
private var mail: TextInputEditText? = null
private var phone: TextInputEditText? = null
private var add: TextInputEditText? = null
private var pinCode: TextInputEditText? = null
private var password: TextInputEditText? = null
private var confirmPassword: TextInputEditText? = null

private val emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+"

Expand All @@ -41,8 +41,8 @@ class NgoSignup1Fragment : Fragment() {
phone = v?.findViewById(R.id.et_ngosignup_phone)
add = v?.findViewById(R.id.et_ngosignup_address)
pinCode = v?.findViewById(R.id.et_ngosignup_pincode)
password =v?.findViewById(R.id.et_ngosignup_password)
confirmPassword =v?.findViewById(R.id.et_ngosignup_confirmpassword)
password = v?.findViewById(R.id.et_ngosignup_password)
confirmPassword = v?.findViewById(R.id.et_ngosignup_confirmpassword)

nextBtn.setOnClickListener {

Expand All @@ -53,7 +53,7 @@ class NgoSignup1Fragment : Fragment() {
val officeAdd = add?.text.toString().trim()
val orgPinCode = pinCode?.text.toString().trim()
val orgPass = password?.text.toString().trim()
val confirmPass=confirmPassword?.text.toString().trim()
val confirmPass = confirmPassword?.text.toString().trim()


if (orgName.isEmpty()) {
Expand All @@ -76,7 +76,7 @@ class NgoSignup1Fragment : Fragment() {
name?.error = "Name cannot be empty"
markButtonDisable(nextBtn)
}
if (orgPass.isEmpty()){
if (orgPass.isEmpty()) {
password?.error = "Password cannot be empty"
markButtonDisable(nextBtn)
}
Expand All @@ -88,17 +88,18 @@ class NgoSignup1Fragment : Fragment() {
password?.error = "Password format is invalid"
markButtonDisable(nextBtn)
}
if(orgPass != confirmPass){
if (orgPass != confirmPass) {
confirmPassword?.error = "Passwords doesn't match"
markButtonDisable(nextBtn)
}else{
communicator.passDataCom(orgName,orgMail,orgPhone,officeAdd,orgPinCode,orgPass)
} else {
communicator.passDataCom(orgName, orgMail, orgPhone, officeAdd, orgPinCode, orgPass)
//this method already have the logic to navigate to sign up page 2
}
}

return v
}

private fun isValidPassword(password: String): Boolean {
val passwordREGEX = Pattern.compile(
"^" +
Expand All @@ -113,8 +114,9 @@ class NgoSignup1Fragment : Fragment() {
)
return passwordREGEX.matcher(password).matches()
}
private fun markButtonDisable(b:Button){
b.isEnabled =false

private fun markButtonDisable(b: Button) {
b.isEnabled = false
b.setBackgroundColor(resources.getColor(R.color.theme_button_disabled))
}
}
130 changes: 67 additions & 63 deletions app/src/main/java/com/hazard/samarpan/ngo/NgoSignup2Fragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.ktx.Firebase
import com.hazard.samarpan.R

class NgoSignup2Fragment : Fragment(){
class NgoSignup2Fragment : Fragment() {

private var v : View?=null
private var btnNgoRegister: Button?=null
private var tilCategoryOthers:TextInputLayout?=null
private var tilSelectOrgType:TextInputLayout?=null
private var etCategoryOthers:TextInputEditText?=null
private var v: View? = null
private var btnNgoRegister: Button? = null
private var tilCategoryOthers: TextInputLayout? = null
private var tilSelectOrgType: TextInputLayout? = null
private var etCategoryOthers: TextInputEditText? = null


private var orgName:String? =""
private var orgMail:String? =""
private var orgPhone:String? =""
private var officeAdd:String? =""
private var orgPin:String? =""
private var orgPass:String? =""
private var category:String? =""
private var orgName: String? = ""
private var orgMail: String? = ""
private var orgPhone: String? = ""
private var officeAdd: String? = ""
private var orgPin: String? = ""
private var orgPass: String? = ""
private var category: String? = ""

private lateinit var registerAuth: FirebaseAuth

Expand All @@ -43,44 +43,45 @@ class NgoSignup2Fragment : Fragment(){
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
v = layoutInflater.inflate(R.layout.ngo_signup2_fragment,container,false)
v = layoutInflater.inflate(R.layout.ngo_signup2_fragment, container, false)

btnNgoRegister=v?.findViewById(R.id.btnNgoRegister)
tilCategoryOthers=v?.findViewById(R.id.til_category_others)
etCategoryOthers=v?.findViewById(R.id.et_category_others)
btnNgoRegister = v?.findViewById(R.id.btnNgoRegister)
tilCategoryOthers = v?.findViewById(R.id.til_category_others)
etCategoryOthers = v?.findViewById(R.id.et_category_others)


tilSelectOrgType=v?.findViewById(R.id.ngosignup_select_orgtype)
tilSelectOrgType = v?.findViewById(R.id.ngosignup_select_orgtype)

val organisationTypes = resources.getStringArray(R.array.organisation_type)
val arrayAdapter = ArrayAdapter(requireContext(),R.layout.dropdown_item,organisationTypes)
val autoCompleteTV= v?.findViewById<AutoCompleteTextView>(R.id.ngosignup_select_orgtype_items)
val arrayAdapter = ArrayAdapter(requireContext(), R.layout.dropdown_item, organisationTypes)
val autoCompleteTV =
v?.findViewById<AutoCompleteTextView>(R.id.ngosignup_select_orgtype_items)
autoCompleteTV?.setAdapter(arrayAdapter)


registerAuth= Firebase.auth
registerAuth = Firebase.auth

orgName=arguments?.getString("Name").toString().trim()
orgMail= arguments?.getString("Mail").toString().trim()
orgPhone=arguments?.getString("Phone").toString().trim()
officeAdd=arguments?.getString("Address").toString().trim()
orgPin=arguments?.getString("PinCode").toString().trim()
orgPass=arguments?.getString("Password").toString().trim()
orgName = arguments?.getString("Name").toString().trim()
orgMail = arguments?.getString("Mail").toString().trim()
orgPhone = arguments?.getString("Phone").toString().trim()
officeAdd = arguments?.getString("Address").toString().trim()
orgPin = arguments?.getString("PinCode").toString().trim()
orgPass = arguments?.getString("Password").toString().trim()

autoCompleteTV?.setOnClickListener {
category = autoCompleteTV.text.toString()
if (category != "") {
if (category == "Others") {
tilCategoryOthers?.visibility = View.VISIBLE
etCategoryOthers?.setOnClickListener {
category = etCategoryOthers?.text.toString()
}
} else {
category = autoCompleteTV.text.toString().trim()
tilCategoryOthers?.visibility = View.GONE
}
autoCompleteTV?.setOnClickListener {
category = autoCompleteTV.text.toString()
if (category != "") {
if (category == "Others") {
tilCategoryOthers?.visibility = View.VISIBLE
etCategoryOthers?.setOnClickListener {
category = etCategoryOthers?.text.toString()
}
} else {
category = autoCompleteTV.text.toString().trim()
tilCategoryOthers?.visibility = View.GONE
}
}
}

// if(category == "Others"){
// //get the category from the user of the type he is from other than the list
Expand All @@ -92,45 +93,48 @@ class NgoSignup2Fragment : Fragment(){

btnNgoRegister?.setOnClickListener {
val db = FirebaseFirestore.getInstance()
try{
registerAuth.createUserWithEmailAndPassword(orgMail!!,orgPass!!)
.addOnCompleteListener{ task->
if(task.isSuccessful){
val ngo: FirebaseUser? =registerAuth.currentUser
try {
registerAuth.createUserWithEmailAndPassword(orgMail!!, orgPass!!)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val ngo: FirebaseUser? = registerAuth.currentUser
Toast.makeText(
activity,
"Thank You! for choosing us",
Toast.LENGTH_SHORT
).show()
val documentReference : DocumentReference =db.collection("users").document(
ngo?.uid ?: ""
)
val ngoInfo :MutableMap<String,Any> = HashMap()
ngoInfo["Full Name"]= orgName!!
ngoInfo["Email"]= orgMail!!
ngoInfo["PhoneNumber"]=orgPhone!!
ngoInfo["Address"]=officeAdd!!
ngoInfo["Pin Code"]=orgPin!!
ngoInfo["isDonor"]="0"
).show()
val documentReference: DocumentReference =
db.collection("users").document(
ngo?.uid ?: ""
)
val ngoInfo: MutableMap<String, Any> = HashMap()
ngoInfo["Full Name"] = orgName!!
ngoInfo["Email"] = orgMail!!
ngoInfo["PhoneNumber"] = orgPhone!!
ngoInfo["Address"] = officeAdd!!
ngoInfo["Pin Code"] = orgPin!!
ngoInfo["isDonor"] = "0"

// add the value of the org type from the dropdown and upload document
documentReference.set(ngoInfo).addOnSuccessListener {
Log.d(ContentValues.TAG, "User data for $orgName was collected successfully ")
}.addOnFailureListener{ e ->
Log.d(
ContentValues.TAG,
"User data for $orgName was collected successfully "
)
}.addOnFailureListener { e ->
Log.w(ContentValues.TAG, "Error adding data", e)
}
}else{
} else {
Toast.makeText(
activity,
task.exception!!.message.toString(),
Toast.LENGTH_SHORT
).show()
}
}
}
catch(e :Exception){
Toast.makeText(context, "Fields cannot be empty $e", Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
Toast.makeText(context, "Fields cannot be empty $e", Toast.LENGTH_SHORT).show()
}
}
return v
}
Expand Down

0 comments on commit c5abbac

Please sign in to comment.