Skip to content

Commit

Permalink
Absence Activity
Browse files Browse the repository at this point in the history
#5
- change firebase database structure,  table attendances, absences,
absencetypes
- new layout for AttendanceListFragment.java and
AttendanceViewHolder.java
  • Loading branch information
eurosecom committed Jan 17, 2017
1 parent 05939b3 commit 4a1f7c3
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/eusecom/attendance/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void onClick(View v) {
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 datm) {

String key = mDatabase.child("attendance").push().getKey();
String key = mDatabase.child("attendances").push().getKey();
String gpslat;
String gpslon;
GPSTracker mGPS = new GPSTracker(MainActivity.this);
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/eusecom/attendance/NewAbsenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void onDataChange(DataSnapshot dataSnapshot) {
Long tsLong = System.currentTimeMillis() / 1000;
String ts = tsLong.toString();

writeAttendance(icox, userId, "0", "506","Holliday", dateodlx, datedolx, "0", hodinyx, "0", "0", ts);
writeAbsence(icox, userId, "0", "506","Holliday", dateodlx, datedolx, "0", hodinyx, "0", "0", ts);

}

Expand All @@ -314,11 +314,11 @@ public void onCancelled(DatabaseError databaseError) {
}

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

String userIDX = FirebaseAuth.getInstance().getCurrentUser().getUid();
String key = mDatabase.child("attendance").push().getKey();
String key = mDatabase.child("absences").push().getKey();
String gpslat;
String gpslon;
GPSTracker mGPS = new GPSTracker(NewAbsenceActivity.this);
Expand All @@ -341,9 +341,9 @@ private void writeAttendance(String usico, String usid, String ume, String dmxa,

Map<String, Object> childUpdates = new HashMap<>();

childUpdates.put("/attendances/" + key, attValues);
childUpdates.put("/company-attendances/" + usico + "/" + key, attValues);
childUpdates.put("/user-attendances/" + userIDX + "/" + key, attValues);
childUpdates.put("/absences/" + key, attValues);
childUpdates.put("/company-absences/" + usico + "/" + key, attValues);
childUpdates.put("/user-absences/" + userIDX + "/" + key, attValues);

mDatabase.updateChildren(childUpdates);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,37 @@ public Query getQuery(DatabaseReference databaseReference) {
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.hasChild("absences")) {
if (snapshot.hasChild("absencetypes")) {
// run some code
}else{
Log.d("table interrupts ", "does not exist");

mDatabase = FirebaseDatabase.getInstance().getReference();
String key = mDatabase.child("absences").push().getKey();
String key = mDatabase.child("absencetypes").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);
childUpdates.put("/absencetypes/" + key, intValues);

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

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

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

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

mDatabase.updateChildren(childUpdates);

Expand All @@ -70,7 +70,7 @@ public void onCancelled(DatabaseError databaseError) {
}
});
// [START absences_query]
Query recentAbsencesQuery = databaseReference.child("absences")
Query recentAbsencesQuery = databaseReference.child("absencetypes")
.limitToFirst(200);
// [END absences_query]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public AttendanceListFragment() {}
public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_all_posts, container, false);
View rootView = inflater.inflate(R.layout.fragment_attendances, container, false);

// [START create_database_reference]
mDatabase = FirebaseDatabase.getInstance().getReference();
// [END create_database_reference]

mRecycler = (RecyclerView) rootView.findViewById(R.id.messages_list);
mRecycler = (RecyclerView) rootView.findViewById(R.id.attendances_list);
mRecycler.setHasFixedSize(true);

return rootView;
Expand Down Expand Up @@ -101,6 +101,7 @@ public void onCancelled(DatabaseError error) {

// Set up Layout Manager, reverse layout
mManager = new LinearLayoutManager(getActivity());
// order by datm desc
mManager.setReverseLayout(true);
mManager.setStackFromEnd(true);
mRecycler.setLayoutManager(mManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Query getQuery(DatabaseReference databaseReference) {
final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();

// [START absences_query]
Query recentAbsencesQuery = databaseReference.child("user-attendances").child(userId).orderByChild("dmxa").startAt("500")
Query recentAbsencesQuery = databaseReference.child("user-absences").child(userId).orderByChild("datm")
.limitToFirst(200);
// [END absences_query]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Query getQuery(DatabaseReference databaseReference) {
final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();

// [START absences_query]
Query recentAbsencesQuery = databaseReference.child("user-attendances").child(userId).orderByChild("dmxa").startAt("1").endAt("2")
Query recentAbsencesQuery = databaseReference.child("user-attendances").child(userId).orderByChild("datm")
.limitToFirst(200);
// [END absences_query]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,88 @@
import android.widget.TextView;

import com.eusecom.attendance.R;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AttendanceViewHolder extends RecyclerView.ViewHolder {

public TextView titleView;
public TextView authorView;
public TextView absence_name;
public ImageView starView;
public TextView numStarsView;
public TextView bodyView;
public TextView datefrom;
public TextView dateto;
public TextView hodxb;
public TextView datm;
FirebaseUser user;
private FirebaseAuth mAuth;
String usemail = "";

public AttendanceViewHolder(View itemView) {
super(itemView);

titleView = (TextView) itemView.findViewById(R.id.post_title);
authorView = (TextView) itemView.findViewById(R.id.post_author);
absence_name = (TextView) itemView.findViewById(R.id.absence_name);
starView = (ImageView) itemView.findViewById(R.id.star);
numStarsView = (TextView) itemView.findViewById(R.id.post_num_stars);
bodyView = (TextView) itemView.findViewById(R.id.post_body);



datefrom = (TextView) itemView.findViewById(R.id.datefrom);
dateto = (TextView) itemView.findViewById(R.id.dateto);
hodxb = (TextView) itemView.findViewById(R.id.hodxb);
datm = (TextView) itemView.findViewById(R.id.datm);

mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
if (user != null) {
usemail = user.getEmail();
}
}

public void bindToAttendance(com.eusecom.attendance.models.Attendance attendance, View.OnClickListener starClickListener) {
titleView.setText(attendance.dmxa);
authorView.setText(attendance.dmna);
absence_name.setText(attendance.dmxa + " " + attendance.dmna);
numStarsView.setText("0");
bodyView.setText("0");

//convert unix epoch timestamp (seconds) to milliseconds
long timestampod = Long.parseLong(attendance.daod) * 1000L;
datefrom.setText(getDate(timestampod ));

long timestampdo = Long.parseLong(attendance.dado) * 1000L;
dateto.setText(getDate(timestampdo ));

long timestamp = Long.parseLong(attendance.daod) * 1000L;
hodxb.setText(attendance.hodxb);

long timestampm = Long.parseLong(attendance.datm) * 1000L;
datm.setText(usemail + " " + getDateTime(timestampm ));

starView.setOnClickListener(starClickListener);

}

private String getDate(long timeStamp){

try{
DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Date netDate = (new Date(timeStamp));
return sdf.format(netDate);
}
catch(Exception ex){
return "xx";
}
}

private String getDateTime(long timeStamp){

try{
DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy hh:mm");
Date netDate = (new Date(timeStamp));
return sdf.format(netDate);
}
catch(Exception ex){
return "xx";
}
}


}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_absences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DatabaseActivity">
tools:context=".AbsenceActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/absences_list"
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/fragment_attendances.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AbsenceActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/attendances_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:clipToPadding="false"
android:padding="5dp"
android:scrollbars="vertical"
tools:listitem="@layout/item_absence" />

</FrameLayout>
15 changes: 8 additions & 7 deletions app/src/main/res/layout/item_attendance.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for one item of absence at RcViewer AbsenceListFragmentjava with AbsenceViewHolder.java -->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -11,8 +12,8 @@
android:padding="10dp">

<include
android:id="@+id/post_author_layout"
layout="@layout/include_post_author"
android:id="@+id/absence_type"
layout="@layout/include_absencetype_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
Expand All @@ -21,9 +22,9 @@
android:id="@+id/star_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/post_author_layout"
android:layout_alignBottom="@+id/absence_type"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/post_author_layout"
android:layout_alignTop="@+id/absence_type"
android:gravity="center_vertical"
android:orientation="horizontal">

Expand All @@ -45,11 +46,11 @@

</LinearLayout>

<include layout="@layout/include_post_text"
android:layout_width="wrap_content"
<include layout="@layout/include_absencevalues_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/post_author_layout"
android:layout_below="@+id/absence_type"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp" />

Expand Down

0 comments on commit 4a1f7c3

Please sign in to comment.