-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 - divide layouts, ViewHolder and fragment for Absence and AbsenceTypes
- Loading branch information
Showing
9 changed files
with
512 additions
and
80 deletions.
There are no files selected for viewing
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
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/eusecom/attendance/fragment/AbsTypesFragment.java
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,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; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.