-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRaiseComplaint.java
More file actions
58 lines (48 loc) · 2.57 KB
/
Copy pathRaiseComplaint.java
File metadata and controls
58 lines (48 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
The function is used to raise a compliant if the user is CR , it takes data from user first and
than takes input from parameter and than upload it to respective reference
@param Title : Title is taken from user through UI
@param Description : Description is taken from user
@param Category : Category is taken from user through spinner
@param Cell : Cell is taken from user from Spinner
*/
public void raiseComplaint(String Title, String Description, final String Category, String Cell){
final DatabaseReference mRootDatabase;
final DatabaseReference mDatabase;
final HashMap<String,String> mComplaintMap = new HashMap<>();
mRootDatabase = FirebaseDatabase.getInstance().getReference().child("app");
mDatabase = mRootDatabase.child("users").child("student");
FirebaseUser mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
String uid = null;
mComplaintMap.put("title",Title);
mComplaintMap.put("description",Description);
mComplaintMap.put("category",Category);
mComplaintMap.put("cell",Cell);
if (mCurrentUser != null) {
uid = mCurrentUser.getUid();
}
mDatabase.child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
mComplaintMap.put("class",dataSnapshot.child("class").toString());
mComplaintMap.put("section",dataSnapshot.child("section").toString());
mComplaintMap.put("year",dataSnapshot.child("year").toString());
mComplaintMap.put("department",dataSnapshot.child("department").toString());
mComplaintmap.put("lastvisible","0"); //to see the active state of complaint
mRootDatabase.child("complaints").child(Category).setValue(mComplaintMap).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Snackbar snackbar = new Snackbar(rootLayout,"Complaint Raised",Snackbar.LENGTH_LONG);
snackbar.show();
}
else {
Log.v("Error_In_Complaints",task.getException().getMessage());
}
}
});
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});