Skip to content

Commit

Permalink
Working on data migration between the two registration pages
Browse files Browse the repository at this point in the history
  • Loading branch information
1HazArd1 committed Sep 21, 2022
1 parent aba7ad3 commit e1ecd61
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 32 deletions.
10 changes: 5 additions & 5 deletions app/src/main/java/com/hazard/samarpan/ngo/NgoSignup1Fragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NgoSignup1Fragment : Fragment() {
val orgPhone = phone?.text.toString().trim()
val officeAdd = add?.text.toString().trim()
val orgPinCode = pinCode?.text.toString().trim()
val pass = password?.text.toString().trim()
val orgPass = password?.text.toString().trim()
val confirmPass=confirmPassword?.text.toString().trim()


Expand All @@ -76,23 +76,23 @@ class NgoSignup1Fragment : Fragment() {
name?.error = "Name cannot be empty"
markButtonDisable(nextBtn)
}
if (pass.isEmpty()){
if (orgPass.isEmpty()){
password?.error = "Password cannot be empty"
markButtonDisable(nextBtn)
}
if (!(orgMail.matches(emailPattern.toRegex()))) {
mail?.error = "Invalid email"
markButtonDisable(nextBtn)
}
if (!(isValidPassword(pass))) {
if (!(isValidPassword(orgPass))) {
password?.error = "Password format is invalid"
markButtonDisable(nextBtn)
}
if(pass != confirmPass){
if(orgPass != confirmPass){
confirmPassword?.error = "Passwords doesn't match"
markButtonDisable(nextBtn)
}else{
communicator.passDataCom(orgName,orgMail,orgPhone,officeAdd,orgPinCode,pass)
communicator.passDataCom(orgName,orgMail,orgPhone,officeAdd,orgPinCode,orgPass)
activity?.supportFragmentManager?.beginTransaction()
?.replace(
R.id.fragment_container1,
Expand Down
50 changes: 32 additions & 18 deletions app/src/main/java/com/hazard/samarpan/ngo/NgoSignup2Fragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.fragment.app.Fragment
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import com.google.firebase.auth.ktx.auth
Expand All @@ -20,14 +22,18 @@ class NgoSignup2Fragment : Fragment(){

private var v : View?=null
private var btnNgoRegister: Button?=null
private var tvSample :TextView?=null
private var tilCategoryOthers: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 pass:String =""
private var orgPass:String =""
private var category:String=""

private lateinit var registerAuth: FirebaseAuth


Expand All @@ -39,31 +45,39 @@ class NgoSignup2Fragment : Fragment(){
v = layoutInflater.inflate(R.layout.ngo_signup2_fragment,container,false)

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

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)
autoCompleteTV?.setAdapter(arrayAdapter)


category=autoCompleteTV?.text.toString().trim()

registerAuth= Firebase.auth

orgName=arguments?.getString("Name").toString()
orgMail= arguments?.getString("Mail").toString()
orgPhone=arguments?.getString("Phone").toString()
officeAdd=arguments?.getString("Address").toString()
orgPin=arguments?.getString("PinCode").toString()
pass=arguments?.getString("Password").toString()
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()

btnNgoRegister?.setOnClickListener {
if(category == "Others"){
//get the category from the user of the type he is from other than the list
btnNgoRegister?.isEnabled=false
tilCategoryOthers?.visibility=View.VISIBLE
category=etCategoryOthers?.text.toString()
btnNgoRegister?.isEnabled=true
}
val db = FirebaseFirestore.getInstance()
try{
registerAuth.createUserWithEmailAndPassword(orgMail,pass)
registerAuth.createUserWithEmailAndPassword(orgMail,orgPass)
.addOnCompleteListener{ task->
if(task.isSuccessful){
val ngo: FirebaseUser? =registerAuth.currentUser
val ngo: FirebaseUser? =registerAuth.currentUser
Toast.makeText(
activity,
"Thank You! for choosing us",
Expand All @@ -73,12 +87,12 @@ class NgoSignup2Fragment : Fragment(){
ngo?.uid ?: ""
)
val ngoInfo :MutableMap<String,Any> = HashMap()
ngoInfo["OrgName"]= orgName
ngoInfo["OrgMail"]= orgMail
ngoInfo["OrgPhone"]=orgPhone
ngoInfo["OfficeAdd"]=officeAdd
ngoInfo["OrgPinCode"]=orgPin
ngoInfo["isDonor"]=0
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 work
documentReference.set(ngoInfo).addOnSuccessListener {
Log.d(ContentValues.TAG, "User data for $orgName was collected successfully ")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package com.hazard.samarpan.user

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import com.hazard.samarpan.adapters.ClothAdapter
import com.hazard.samarpan.R
import com.hazard.samarpan.common.MainActivity


class UserDashboardFragment : Fragment() {

private lateinit var clothRecycler: RecyclerView
private var donate: FloatingActionButton?= null
private var btnLogout : ImageButton?=null

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -26,7 +33,9 @@ class UserDashboardFragment : Fragment() {

donate = v.findViewById(R.id.btnDonate)

var clothList: ArrayList<Int> = ArrayList()
btnLogout=v.findViewById(R.id.profile_button)

val clothList: ArrayList<Int> = ArrayList()
for (i in 1..15) {
clothList.add(R.drawable.ic_uploadimage)
}
Expand All @@ -35,6 +44,12 @@ class UserDashboardFragment : Fragment() {
LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
clothRecycler.adapter = ClothAdapter(clothList)

btnLogout?.setOnClickListener{
Firebase.auth.signOut()
val intent= Intent(context, MainActivity::class.java)
startActivity(intent)
activity?.finish()
}

donate?.setOnClickListener {
val donationInfo= DonationInfoFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class UserRegisterFragment : Fragment() {
donorInfo["Address"] = donorAddress
donorInfo["Pin Code"] = donorPinCode
//specify if the user is donor
donorInfo["isDonor"] = 1 // in case of NGO give this value 0
donorInfo["isDonor"] = "1" // in case of NGO give this value 0

documentReference.set(donorInfo).addOnSuccessListener {
Log.d(TAG, "User data for $donorName was collected successfully ")
Expand Down
25 changes: 18 additions & 7 deletions app/src/main/res/layout/ngo_signup2_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_category_others"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginTop="35dp"
app:boxStrokeColor="@color/black"
android:visibility="gone">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_category_others"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textShortMessage"
android:textCursorDrawable="@null"
/>
</com.google.android.material.textfield.TextInputLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -192,13 +210,6 @@
android:textColor="@color/theme_button_text"
android:text="@string/get_started" />

<TextView
android:id="@+id/tv_Sample"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sample"
android:layout_marginTop="10dp"
/>

</LinearLayout>

Expand Down

0 comments on commit e1ecd61

Please sign in to comment.