Skip to content

Commit

Permalink
Absence Activity
Browse files Browse the repository at this point in the history
#5
- divide layouts, ViewHolder and fragment for Absence and AbsenceTypes
  • Loading branch information
eurosecom committed Dec 10, 2016
1 parent 0eeb4c2 commit dd86db8
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 80 deletions.
7 changes: 4 additions & 3 deletions app/src/main/java/com/eusecom/attendance/AbsenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.view.MenuItem;
import android.view.View;

import com.eusecom.attendance.fragment.AbsTypesFragment;
import com.eusecom.attendance.fragment.EmptyFragment;
import com.eusecom.attendance.fragment.MyAbsenceFragment;
import com.google.firebase.auth.FirebaseAuth;
Expand All @@ -51,12 +52,12 @@ protected void onCreate(Bundle savedInstanceState) {
private final Fragment[] mFragments = new Fragment[] {
new MyAbsenceFragment(),
new EmptyFragment(),
new EmptyFragment(),
new AbsTypesFragment(),
};
private final String[] mFragmentNames = new String[] {
"Absences",
"Next",
"Next"
"Attendances",
"AbsTypes"
};
@Override
public Fragment getItem(int position) {
Expand Down
42 changes: 29 additions & 13 deletions app/src/main/java/com/eusecom/attendance/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,20 @@ public void onClick(View v) {

if (user != null) {

final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
String icox = SettingsActivity.getUsIco(MainActivity.this);
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
String usatwx = SettingsActivity.getUsAtw(MainActivity.this);
if( usatwx.equals("0")) {

writeAttendance(icox,userId,"0","1",ts,ts,"0","0","0","0" );
final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
String icox = SettingsActivity.getUsIco(MainActivity.this);
Long tsLong = System.currentTimeMillis() / 1000;
String ts = tsLong.toString();

writeAttendance(icox, userId, "0", "1","Incoming work", ts, ts, "0", "0", "0", "0");

}else{
Toast.makeText(MainActivity.this, "You are at work now.",
Toast.LENGTH_SHORT).show();
}



Expand All @@ -212,12 +220,20 @@ public void onClick(View v) {

if (user != null) {

final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
String icox = SettingsActivity.getUsIco(MainActivity.this);
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
String usatwx = SettingsActivity.getUsAtw(MainActivity.this);
if( usatwx.equals("1")) {

writeAttendance(icox,userId,"0","2",ts,ts,"0","0","0","0" );
final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
String icox = SettingsActivity.getUsIco(MainActivity.this);
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();

writeAttendance(icox,userId,"0","2","Leaving work",ts,ts,"0","0","0","0" );

}else{
Toast.makeText(MainActivity.this, "You are out of work now.",
Toast.LENGTH_SHORT).show();
}

}else{

Expand Down Expand Up @@ -263,7 +279,7 @@ public void onCancelled(DatabaseError error) {
public void onClick(View v) {

if (user != null) {
Intent i = new Intent(getApplicationContext(), DatabaseActivity.class);
Intent i = new Intent(getApplicationContext(), AbsenceActivity.class);
startActivity(i);
} else {
// User is signed out
Expand All @@ -280,7 +296,7 @@ public void onClick(View v) {


// [START basic_write]
private void writeAttendance(String usico, String usid, String ume, String dmxa, String daod, String dado, String dnixa,
private void writeAttendance(String usico, String usid, String ume, String dmxa, String dmna, String daod, String dado, String dnixa,
String hodxb, String longi, String lati) {

String key = mDatabase.child("attendance").push().getKey();
Expand All @@ -300,7 +316,7 @@ private void writeAttendance(String usico, String usid, String ume, String dmxa,
mGPS.showSettingsAlert();
}

Attendance attendance = new Attendance(usico, usid, ume, dmxa, daod, dado, dnixa, hodxb, gpslon, gpslat );
Attendance attendance = new Attendance(usico, usid, ume, dmxa, dmna, daod, dado, dnixa, hodxb, gpslon, gpslat );

Map<String, Object> attValues = attendance.toMap();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.eusecom.attendance.fragment;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

import com.eusecom.attendance.models.Absence;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;

import java.util.HashMap;
import java.util.Map;

public class AbsTypesFragment extends AbsTypesListFragment {

private DatabaseReference mDatabase;

public AbsTypesFragment() {}

@Override
public Query getQuery(DatabaseReference databaseReference) {

databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.hasChild("absences")) {
// run some code
}else{
Log.d("table interrupts ", "does not exist");

mDatabase = FirebaseDatabase.getInstance().getReference();
String key = mDatabase.child("absences").push().getKey();
Absence absence = new Absence("506","Holliday");
Map<String, Object> intValues = absence.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/absences/" + key, intValues);

key = mDatabase.child("interrupts").push().getKey();
absence = new Absence("510","Bank holliday");
intValues = absence.toMap();
childUpdates.put("/absences/" + key, intValues);

key = mDatabase.child("interrupts").push().getKey();
absence = new Absence("518","Visit Doctor");
intValues = absence.toMap();
childUpdates.put("/absences/" + key, intValues);

key = mDatabase.child("interrupts").push().getKey();
absence = new Absence("520","Other");
intValues = absence.toMap();
childUpdates.put("/absences/" + key, intValues);

key = mDatabase.child("interrupts").push().getKey();
absence = new Absence("801","Illness");
intValues = absence.toMap();
childUpdates.put("/absences/" + key, intValues);

mDatabase.updateChildren(childUpdates);

}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
// [START absences_query]
Query recentAbsencesQuery = databaseReference.child("absences")
.limitToFirst(200);
// [END absences_query]

return recentAbsencesQuery;
}





}
Loading

0 comments on commit dd86db8

Please sign in to comment.