-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collecting NGO sign up info to the database from both the registratio…
…n pages
- Loading branch information
Showing
11 changed files
with
230 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.hazard.samarpan.ngo | ||
|
||
interface Communicator { | ||
fun passDataCom(orgName :String,orgMail :String ,orgPhone :String ,officeAdd :String,orgPin :String,orgPass:String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 79 additions & 4 deletions
83
app/src/main/java/com/hazard/samarpan/ngo/NgoSignup2Fragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,103 @@ | ||
package com.hazard.samarpan.ngo | ||
|
||
import android.content.ContentValues | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import android.widget.AutoCompleteTextView | ||
import android.widget.* | ||
import androidx.fragment.app.Fragment | ||
import com.google.firebase.auth.FirebaseAuth | ||
import com.google.firebase.auth.FirebaseUser | ||
import com.google.firebase.auth.ktx.auth | ||
import com.google.firebase.firestore.DocumentReference | ||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.google.firebase.ktx.Firebase | ||
import com.hazard.samarpan.R | ||
|
||
class NgoSignup2Fragment : Fragment(){ | ||
|
||
private var v : View?=null | ||
private var btnNgoRegister: Button?=null | ||
private var tvSample :TextView?=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 lateinit var registerAuth: FirebaseAuth | ||
|
||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
v = layoutInflater.inflate(R.layout.ngo_signup2_fragment,container,false) | ||
|
||
val types = resources.getStringArray(R.array.organisation_type) | ||
val arrayAdapter = ArrayAdapter(requireContext(),R.layout.dropdown_item,types) | ||
btnNgoRegister=v?.findViewById(R.id.btnNgoRegister) | ||
tvSample=v?.findViewById(R.id.tv_Sample) | ||
|
||
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) | ||
|
||
|
||
|
||
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() | ||
|
||
btnNgoRegister?.setOnClickListener { | ||
val db = FirebaseFirestore.getInstance() | ||
try{ | ||
registerAuth.createUserWithEmailAndPassword(orgMail,pass) | ||
.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["OrgName"]= orgName | ||
ngoInfo["OrgMail"]= orgMail | ||
ngoInfo["OrgPhone"]=orgPhone | ||
ngoInfo["OfficeAdd"]=officeAdd | ||
ngoInfo["OrgPinCode"]=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 ") | ||
}.addOnFailureListener{ e -> | ||
Log.w(ContentValues.TAG, "Error adding data", e) | ||
} | ||
}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() | ||
} | ||
} | ||
return v | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.