Skip to content

Commit

Permalink
Absence Activity
Browse files Browse the repository at this point in the history
#5
- model Abstype.java for AbsTypesViewHolder and AbsTypesListFragment
- date of cerate from ServerValue.TIMESTAMP in model Abstype.java
  • Loading branch information
eurosecom committed Jan 21, 2017
1 parent 72ab3e8 commit 8fe5381
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 29 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/com/eusecom/attendance/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@
import android.widget.Toast;

import com.eusecom.attendance.models.Attendance;
import com.eusecom.attendance.models.Post;
import com.eusecom.attendance.models.User;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
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.ServerValue;
import com.google.firebase.database.ValueEventListener;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.preference.PreferenceManager;
import android.util.Log;

import com.eusecom.attendance.models.Absence;
import com.eusecom.attendance.models.Abstype;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
Expand Down Expand Up @@ -34,29 +34,29 @@ public void onDataChange(DataSnapshot snapshot) {

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

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

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

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

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

mDatabase.updateChildren(childUpdates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import android.widget.TextView;
import android.widget.Toast;

import com.eusecom.attendance.NewPostActivity;
import com.eusecom.attendance.models.Absence;
import com.eusecom.attendance.models.Abstype;
import com.eusecom.attendance.viewholder.AbsTypesViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.auth.FirebaseAuth;
Expand All @@ -30,7 +29,6 @@
import com.google.firebase.database.Transaction;
import com.eusecom.attendance.R;
import com.eusecom.attendance.models.Post;
import com.eusecom.attendance.viewholder.AbsenceViewHolder;
import com.google.firebase.database.ValueEventListener;

import java.util.HashMap;
Expand All @@ -44,7 +42,7 @@ public abstract class AbsTypesListFragment extends Fragment {
private DatabaseReference mDatabase;
// [END define_database_reference]

private FirebaseRecyclerAdapter<Absence, AbsTypesViewHolder> mAdapter;
private FirebaseRecyclerAdapter<Abstype, AbsTypesViewHolder> mAdapter;
private RecyclerView mRecycler;
private LinearLayoutManager mManager;

Expand Down Expand Up @@ -122,11 +120,11 @@ public void onCancelled(DatabaseError firebaseError) {



mAdapter = new FirebaseRecyclerAdapter<Absence, AbsTypesViewHolder>(Absence.class, R.layout.item_abstypes,
mAdapter = new FirebaseRecyclerAdapter<Abstype, AbsTypesViewHolder>(Abstype.class, R.layout.item_abstypes,
AbsTypesViewHolder.class, absencesQuery) {

@Override
protected void populateViewHolder(final AbsTypesViewHolder viewHolder, final Absence model, final int position) {
protected void populateViewHolder(final AbsTypesViewHolder viewHolder, final Abstype model, final int position) {
final DatabaseReference absRef = getRef(position);

// Set click listener for the whole post view
Expand Down Expand Up @@ -170,7 +168,7 @@ public boolean onLongClick(View v) {
});


// Bind Absence to ViewHolder
// Bind Abstypes to ViewHolder
viewHolder.bindToAbsence(model, new View.OnClickListener() {
@Override
public void onClick(View starView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.widget.Toast;

import com.eusecom.attendance.NewPostActivity;
import com.eusecom.attendance.models.Absence;
import com.eusecom.attendance.models.Attendance;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.auth.FirebaseAuth;
Expand Down Expand Up @@ -169,7 +168,7 @@ public boolean onLongClick(View v) {
});


// Bind Absence to ViewHolder
// Bind Abstype to ViewHolder
viewHolder.bindToAbsence(model, new View.OnClickListener() {
@Override
public void onClick(View starView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.widget.Toast;

import com.eusecom.attendance.NewPostActivity;
import com.eusecom.attendance.models.Absence;
import com.eusecom.attendance.models.Attendance;
import com.eusecom.attendance.viewholder.AttendanceViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
Expand All @@ -31,7 +30,6 @@
import com.google.firebase.database.Transaction;
import com.eusecom.attendance.R;
import com.eusecom.attendance.models.Post;
import com.eusecom.attendance.viewholder.AbsenceViewHolder;
import com.google.firebase.database.ValueEventListener;

import java.util.HashMap;
Expand Down Expand Up @@ -171,7 +169,7 @@ public boolean onLongClick(View v) {
});


// Bind Absence to ViewHolder
// Bind Attendance to ViewHolder
viewHolder.bindToAttendance(model, new View.OnClickListener() {
@Override
public void onClick(View starView) {
Expand Down
73 changes: 73 additions & 0 deletions app/src/main/java/com/eusecom/attendance/models/Abstype.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.eusecom.attendance.models;

import com.google.firebase.database.Exclude;
import com.google.firebase.database.IgnoreExtraProperties;
import com.google.firebase.database.ServerValue;

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

// [START AbsType_class]
@IgnoreExtraProperties
public class Abstype {

public String idm;
public String iname;
private HashMap<String, Object> datm;


public Abstype() {
// Default constructor required for calls to DataSnapshot.getValue(interrupt.class)
}

public Abstype(String idm, String iname) {
this.idm = idm;
this.iname = iname;

HashMap<String, Object> datmObj = new HashMap<String, Object>();
datmObj.put("date", ServerValue.TIMESTAMP);
this.datm = datmObj;

}

// [START AbsType_to_map]
@Exclude
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
result.put("idm", idm);
result.put("iname", iname);
result.put("datm", datm);

return result;
}
// [END AbsType_to_map]


public HashMap<String, Object> getDatm() {
//If there is a dateCreated object already, then return that
if (datm!= null) {
return datm;
}
//Otherwise make a new object set to ServerValue.TIMESTAMP
HashMap<String, Object> datmObj = new HashMap<String, Object>();
datmObj.put("date", ServerValue.TIMESTAMP);
return datmObj;
}


@Exclude
public long getDatmLong() {
return (long)datm.get("date");
}

@Exclude
public String getDatmString() {

long datml = (long)datm.get("date");
String datms = datml + "";

return datms;
}

}
// [END AbsType_class]
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.eusecom.attendance.R;
import com.squareup.picasso.Picasso;

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

public class AbsTypesViewHolder extends RecyclerView.ViewHolder {

public TextView absence_name;
Expand All @@ -31,8 +33,11 @@ public AbsTypesViewHolder(View itemView) {

}

public void bindToAbsence(com.eusecom.attendance.models.Absence abstypes, View.OnClickListener starClickListener) {
absence_name.setText(abstypes.idm + " " + abstypes.iname);
public void bindToAbsence(com.eusecom.attendance.models.Abstype abstypes, View.OnClickListener starClickListener) {

long timestampm = abstypes.getDatmLong();

absence_name.setText(abstypes.idm + " " + abstypes.iname + " " + getDateTime(timestampm ));
if( abstypes.idm.equals("506")) {
Picasso.with(mContext).load(R.drawable.abs506).resize(120, 120).into(absence_photo);
}
Expand All @@ -53,7 +58,17 @@ public void bindToAbsence(com.eusecom.attendance.models.Absence abstypes, View.O

}

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";
}
}


}

0 comments on commit 8fe5381

Please sign in to comment.