Skip to content

Commit

Permalink
Attendance
Browse files Browse the repository at this point in the history
  • Loading branch information
JapneetRajput committed May 2, 2022
1 parent 88411dc commit d9b0762
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 14 deletions.
27 changes: 24 additions & 3 deletions app/src/main/java/com/example/workflow/AdapterNotices.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public class AdapterNotices extends RecyclerView.Adapter<AdapterNotices.MyViewHo
Context context;
ArrayList<NoticeList> list;
private static RecyclerViewClickListener listener;
private onItemClickListener mListener;

public interface onItemClickListener{
void onItemClick(int position);

}

public void setOnItemClickListener(onItemClickListener listener){
mListener=listener;
}

public AdapterNotices(Context context, ArrayList<NoticeList> list, RecyclerViewClickListener listener) {
this.context = context;
Expand All @@ -31,7 +41,7 @@ public AdapterNotices(Context context, ArrayList<NoticeList> list) {
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.notices_card,parent,false);
return new MyViewHolder(v);
return new MyViewHolder(v,mListener);
}

@Override
Expand All @@ -50,12 +60,22 @@ public int getItemCount() {
public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

TextView description, title,department;
public MyViewHolder(@NonNull View itemView) {
public MyViewHolder(@NonNull View itemView,onItemClickListener listener) {
super(itemView);
title=itemView.findViewById(R.id.NoticeTitle);
description=itemView.findViewById(R.id.NoticeDesc);
department=itemView.findViewById(R.id.NoticeDepartment);
itemView.setOnClickListener(this);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(listener!=null){
int position=getAdapterPosition();
if(position!=RecyclerView.NO_POSITION){
listener.onItemClick(position);
}
}
}
});
}

@Override
Expand All @@ -64,6 +84,7 @@ public void onClick(View v) {
}
}


public interface RecyclerViewClickListener{
void onClick(View v, int position);
}
Expand Down
82 changes: 75 additions & 7 deletions app/src/main/java/com/example/workflow/Attendance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.workflow;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
Expand All @@ -14,17 +16,34 @@
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class Attendance extends AppCompatActivity {
String loginTime;
String logoutTime;
TextView difference;
int hrDiff,minDiff,secDiff;
// FirebaseFirestore db;
// String absentCount="0",presentCount="0",halfDayCount="0";
// int AbsentCount=0,PresentCount=0,HalfDayCount=0;
// String uid = Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid();
String initialYear,finalYear,initialMonth,finalMonth,initialDay,finalDay,initialHour,finalHour,initialMinutes,finalMinutes,initialSeconds,finalSeconds;
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -34,21 +53,39 @@ protected void onCreate(Bundle savedInstanceState) {
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String officeSSID=wifiInfo.getSSID();
String officeIP="172.20.10.11";
String officeIP=""+Formatter.formatIpAddress(wifiManager.getConnectionInfo().getIpAddress());
String employeeSSID = wifiInfo.getSSID();
String employeeIP =""+Formatter.formatIpAddress(wifiManager.getConnectionInfo().getIpAddress());

Button login = (Button) findViewById(R.id.login);
Button logout = (Button) findViewById(R.id.logout);
Button login = findViewById(R.id.login);
Button logout = findViewById(R.id.logout);
difference= findViewById(R.id.difference);

// db=FirebaseFirestore.getInstance();
// TextView check = (TextView) findViewById(R.id.textView3);
// check.setText(officeSSID+" "+officeIP+" "+employeeSSID+" "+employeeIP);

login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (employeeSSID.equals(officeSSID) && employeeIP.equals(officeIP)){
// db.collection("Users").document(uid).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
// @Override
// public void onSuccess(DocumentSnapshot documentSnapshot) {
// if(documentSnapshot!=null) {
// absentCount = documentSnapshot.getString("absentCount");
// AbsentCount = Integer.parseInt(absentCount);
// presentCount = documentSnapshot.getString("presentCount");
// PresentCount = Integer.parseInt(presentCount);
// halfDayCount = documentSnapshot.getString("halfDayCount");
// HalfDayCount = Integer.parseInt(halfDayCount);
// }
// }
// }).addOnFailureListener(new OnFailureListener() {
// @Override
// public void onFailure(@NonNull Exception e) {
// Toast.makeText(Attendance.this, "Hi", Toast.LENGTH_SHORT).show();
// }
// });
loginTime= new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss").format(new Date());
TextView time = (TextView) findViewById(R.id.logintime);
// time.setText("Login Time: "+loginTime);
Expand All @@ -58,7 +95,7 @@ public void onClick(View view) {
initialHour=loginTime.substring(14,16);
initialMinutes=loginTime.substring(17,19);
initialSeconds=loginTime.substring(20,22);
time.setText("Login Time: "+initialYear+"."+initialMonth+"."+initialDay+". at "+initialHour+":"+initialMinutes+":"+initialSeconds);
time.setText("Login Time: "+initialYear+"."+initialMonth+"."+initialDay+" at "+initialHour+":"+initialMinutes+":"+initialSeconds);
logout.setVisibility(View.VISIBLE);
login.setVisibility(View.INVISIBLE);
}
Expand Down Expand Up @@ -95,21 +132,52 @@ public void onClick(View view) {
secDiff = -Integer.parseInt(initialSeconds) + Integer.parseInt(finalSeconds);
// }
if(initialYear.equals(finalYear) || initialMonth.equals(finalMonth) || initialDay.equals(finalDay)){
if(hrDiff>16){
difference.setText(hrDiff+":"+minDiff+":"+secDiff);
if(hrDiff<4){
// AbsentCount++;
Toast.makeText(Attendance.this, "Attendance not marked!", Toast.LENGTH_SHORT).show();
}
else if(hrDiff>4&&hrDiff<8){
// HalfDayCount++;
Toast.makeText(Attendance.this, "Attendance partially marked!", Toast.LENGTH_SHORT).show();

}
else if(hrDiff>16){
// AbsentCount++;
Toast.makeText(Attendance.this, "Attendance not marked!", Toast.LENGTH_SHORT).show();
}
else{
difference.setText(hrDiff+":"+minDiff+":"+secDiff);
// PresentCount++;
Toast.makeText(Attendance.this, "Attendance marked!", Toast.LENGTH_SHORT).show();
}
}
else{
// AbsentCount++;
Toast.makeText(Attendance.this, "Attendance not marked!", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(Attendance.this, "Please check your Network and try again. ", Toast.LENGTH_SHORT).show();
}
// Map<String, Object> attt = new HashMap<>();
// absentCount=AbsentCount+"";
// presentCount=PresentCount+"";
// halfDayCount=HalfDayCount+"";
// attt.put("absentCount",absentCount);
// attt.put("presentCount",presentCount);
// attt.put("halfDayCount",halfDayCount);
// db.collection("Users").document(uid).set(attt).addOnCompleteListener(new OnCompleteListener<Void>() {
// @Override
// public void onComplete(@NonNull Task<Void> task) {
// if (task.isSuccessful()) {
// Toast.makeText(Attendance.this, "Updated successfully", Toast.LENGTH_SHORT).show();
// startActivity(new Intent(Attendance.this, Attendance.class));
// finish();
// } else {
// Toast.makeText(Attendance.this, "Update failed", Toast.LENGTH_SHORT).show();
// }
// }
// });
}
});
}
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/example/workflow/MyNotices.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ protected void onCreate(Bundle savedInstanceState) {
db=FirebaseFirestore.getInstance();

recyclerView.setAdapter(adapterNotices);
adapterNotices.setOnItemClickListener(new AdapterNotices.onItemClickListener() {
@Override
public void onItemClick(int position) {

}
});

EventChangeListener();
}
Expand Down Expand Up @@ -135,7 +141,7 @@ public void onSuccess(DocumentSnapshot documentSnapshot) {
notices.put("department", uidDepartment);

if (uidNotice.equals(uid)){
db.collection("Notices").document(Position).set(notices).addOnCompleteListener(new OnCompleteListener<Void>() {
db.collection("Notices").document(Position).update(notices).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Expand Down Expand Up @@ -176,7 +182,7 @@ public void onFailure(@NonNull Exception e) {
private void EventChangeListener() {

db.collection("Notices")
.whereEqualTo("department","Full Stack Developer")
.whereEqualTo("department","Full Stack Developer")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/workflow/MyProjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void onSuccess(DocumentSnapshot documentSnapshot) {
Projects.put("department", uidDepartment);

if (uidProject.equals(uid)){
db.collection("Projects").document(Position).set(Projects).addOnCompleteListener(new OnCompleteListener<Void>() {
db.collection("Projects").document(Position).update(Projects).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/example/workflow/NoticeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public NoticeList(String title, String description,Integer count,String departme
this.department=department;
}

public void changeText1(String text){

}

public String getTitle() {
return title;
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/notices_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@
android:layout_marginTop="7dp"
android:text=""
android:textSize="20sp"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_star" />

</androidx.appcompat.widget.LinearLayoutCompat>


</LinearLayout>
</androidx.cardview.widget.CardView>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.google.gms:google-services:4.3.10'

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit d9b0762

Please sign in to comment.