Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JapneetRajput committed May 2, 2022
2 parents d9b0762 + 8ca0231 commit ae4c16d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 28 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/example/workflow/LeaveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ public void onClick(View v) {
leave.put("Type", l_type);
leave.put("description", des);
leave.put("department", dept);
leave.put("approved",0);
count++;
leave.put("count",count);
String Count = count.toString();

Map<String, Object> LCount = new HashMap<>();
LCount.put("LeaveCount", count);
db1.updateChildren(LCount);
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/example/workflow/LeaveList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
public class LeaveList {
String Type;
String to_date,from_date,email;
Integer count;

public LeaveList(){}

public LeaveList(String Type, String to_date, String from_date, String email) {
public LeaveList(String Type, String to_date, String from_date, String email, Integer count) {
this.Type = Type;
this.to_date = to_date;
this.from_date = from_date;
this.email = email;
this.count = count;
}

public void setType(String type) {
Expand All @@ -29,6 +31,14 @@ public void setEmail(String email) {
this.email = email;
}

public Integer getCount() {
return count;
}

public void setCount(Integer count) {
this.count = count;
}

public String getType() {
return Type;
}
Expand Down
75 changes: 49 additions & 26 deletions app/src/main/java/com/example/workflow/LeaveRequests.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

Expand All @@ -37,12 +39,14 @@
import java.util.Objects;

public class LeaveRequests extends AppCompatActivity {

String pos,department;
RecyclerView recyclerView;
AdapterLeave.RecyclerViewClickListener listener;
AdapterLeave adapterLeave;
ArrayList<LeaveList> list;
FirebaseFirestore db;
Integer count;
String uid = Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid();
ProgressDialog progressDialog;
DatabaseReference noticeCounT= FirebaseDatabase.getInstance().getReference();
Expand Down Expand Up @@ -89,31 +93,6 @@ public void onCancelled(@NonNull DatabaseError error) {
db=FirebaseFirestore.getInstance();
recyclerView.setAdapter(adapterLeave);
}
private void EventChangeListener() {

db.collection("Leave")
.whereEqualTo("department",department)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
if (error != null) {
if (progressDialog.isShowing())
progressDialog.dismiss();
Toast.makeText(LeaveRequests.this, "Snapshot error", Toast.LENGTH_SHORT).show();
} else {
for (DocumentChange dc : value.getDocumentChanges()) {
if (progressDialog.isShowing())
progressDialog.dismiss();

if (dc.getType() == DocumentChange.Type.ADDED) {
list.add(dc.getDocument().toObject(LeaveList.class));
}
adapterLeave.notifyDataSetChanged();
}
}
}
});
}
private void setOnClickListener() {
listener=new AdapterLeave.RecyclerViewClickListener() {
@Override
Expand Down Expand Up @@ -163,24 +142,68 @@ public void onClick(View v, int position){
// });
// String Position = (position+1) + "";
// Toast.makeText(LeaveRequests.this, Position, Toast.LENGTH_SHORT).show();
count = list.get(position).getCount();
String Position = (count) + "";
new AlertDialog.Builder(LeaveRequests.this)
.setMessage("Do you wish to approve this request?")
.setCancelable(true)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.collection("Leave").document(Position)
.update("approved", 1);
Toast.makeText(getApplicationContext(), "Leave Approved!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(LeaveRequests.this, LeaveRequests.class));
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.collection("Leave").document(Position)
.update("approved", -1);
Toast.makeText(getApplicationContext(), "Leave Denied!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(LeaveRequests.this, LeaveRequests.class));
finish();
}
})
.show();
}
};
}
private void EventChangeListener() {

db.collection("Leave")
.whereEqualTo("department",department)
.whereEqualTo("approved",0)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
if (error != null) {
if (progressDialog.isShowing())
progressDialog.dismiss();
Toast.makeText(LeaveRequests.this, "Snapshot error", Toast.LENGTH_SHORT).show();
} else {
for (DocumentChange dc : value.getDocumentChanges()) {
if (progressDialog.isShowing())
progressDialog.dismiss();

if (dc.getType() == DocumentChange.Type.ADDED) {
list.add(dc.getDocument().toObject(LeaveList.class));
}
adapterLeave.notifyDataSetChanged();
}
}
}
});
}


}

}
//db.collection("users")
// .document("frank")
// .update({
// "age": 13,
// "favorites.color": "Red"
// });

0 comments on commit ae4c16d

Please sign in to comment.