Skip to content

Commit

Permalink
Approve Activity
Browse files Browse the repository at this point in the history
#12
- new ApproveViewHolder.java
- Approve / Refuse dialog

TODO
- do to approve / to refuse absence
  • Loading branch information
eurosecom committed Mar 27, 2017
1 parent dbb250c commit e49ba43
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 54 deletions.
8 changes: 2 additions & 6 deletions app/src/main/java/com/eusecom/attendance/ApproveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;

import com.eusecom.attendance.fragment.AbsTypesFragment;
import com.eusecom.attendance.fragment.ContactFragment;
import com.eusecom.attendance.fragment.LiveFragment;
import com.eusecom.attendance.fragment.MyAbsenceFragment;
import com.eusecom.attendance.fragment.MyAttendanceFragment;
import com.eusecom.attendance.fragment.MyApproveFragment;
import com.google.firebase.auth.FirebaseAuth;


Expand All @@ -59,7 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Create the adapter that will return a fragment for each section
mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
private final Fragment[] mFragments = new Fragment[] {
new MyAbsenceFragment(),
new MyApproveFragment(),
new AbsTypesFragment()
};
private final String[] mFragmentNames = new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.eusecom.attendance.SettingsActivity;
import com.eusecom.attendance.models.Attendance;
import com.eusecom.attendance.models.DeletedAbs;
import com.eusecom.attendance.viewholder.ApproveViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
Expand All @@ -32,21 +33,21 @@
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.eusecom.attendance.viewholder.ApproveViewHolder;
import com.google.firebase.database.ValueEventListener;

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

public abstract class ApproveListFragment extends Fragment {

private static final String TAG = "AbsenceListFragment";
private static final String TAG = "ApproveListFragment";

// [START define_database_reference]
private DatabaseReference mDatabase;
// [END define_database_reference]

private FirebaseRecyclerAdapter<Attendance, AbsenceViewHolder> mAdapter;
private FirebaseRecyclerAdapter<Attendance, ApproveViewHolder> mAdapter;
private RecyclerView mRecycler;
private LinearLayoutManager mManager;

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



mAdapter = new FirebaseRecyclerAdapter<Attendance, AbsenceViewHolder>(Attendance.class, R.layout.item_absence,
AbsenceViewHolder.class, absencesQuery) {
mAdapter = new FirebaseRecyclerAdapter<Attendance, ApproveViewHolder>(Attendance.class, R.layout.item_absence,
ApproveViewHolder.class, absencesQuery) {

@Override
protected void populateViewHolder(final AbsenceViewHolder viewHolder, final Attendance model, final int position) {
protected void populateViewHolder(final ApproveViewHolder viewHolder, final Attendance model, final int position) {

final DatabaseReference absRef = getRef(position);

Expand Down Expand Up @@ -187,11 +188,7 @@ public boolean onLongClick(View v) {

abskeydel = absKey;

if( rozdiel < 180000 ) {
getDialog(abskeydel);
}else{
Toast.makeText(getActivity(), getResources().getString(R.string.cantdel),Toast.LENGTH_SHORT).show();
}
getDialog(abskeydel);


return true;
Expand All @@ -202,7 +199,7 @@ public boolean onLongClick(View v) {


// Bind Abstype to ViewHolder
viewHolder.bindToAbsence(model, new View.OnClickListener() {
viewHolder.bindToApprove(model, new View.OnClickListener() {
@Override
public void onClick(View starView) {
// Need to write to both places the post is stored
Expand Down Expand Up @@ -272,36 +269,18 @@ public String getUid() {
public abstract Query getQuery(DatabaseReference databaseReference);

// [START deletefan_out]
private void deletePost(String postkey) {

// delete post key from /posts and user-posts/$userid simultaneously
String userId = getUid();
String key = postkey;
String usicox = SettingsActivity.getUsIco(getActivity());
private void approvePost(String postkey, int anodaj) {

Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/absences/" + key, null);
childUpdates.put("/user-absences/" + userId + "/" + key, null);
childUpdates.put("/company-absences/" + usicox + "/" + key, null);
mDatabase.updateChildren(childUpdates);


String keydel = mDatabase.child("deleted-absences").push().getKey();
DeletedAbs deletedabs = new DeletedAbs(usicox, userId, postkey );
Log.d(TAG, "postkey " + postkey);
Map<String, Object> delValues = deletedabs.toMap();
Map<String, Object> childDelUpdates = new HashMap<>();
childDelUpdates.put("/deleted-absences/" + keydel, delValues);
mDatabase.updateChildren(childDelUpdates);

}
// [END delete_fan_out]

private void getDialog(String postkey) {

// custom dialog
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.custom_dialog);
dialog.setContentView(R.layout.approve_dialog);
dialog.setTitle(R.string.item);
// set the custom dialog components - text, image and button
String textx = getString(R.string.item) + " " + abskeydel;
Expand All @@ -310,31 +289,24 @@ private void getDialog(String postkey) {
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_image_edit);

Button buttonDelete = (Button) dialog.findViewById(R.id.buttonDelete);
Button buttonApprove = (Button) dialog.findViewById(R.id.buttonApprove);
// if button is clicked, close the custom dialog
buttonDelete.setOnClickListener(new View.OnClickListener() {
buttonApprove.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
dialog.dismiss();
deletePost(abskeydel);
approvePost(abskeydel, 1);
}
});
Button buttonEdit = (Button) dialog.findViewById(R.id.buttonEdit);
Button buttonRefuse = (Button) dialog.findViewById(R.id.buttonRefuse);
// if button is clicked, close the custom dialog
buttonEdit.setOnClickListener(new View.OnClickListener() {
buttonRefuse.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
dialog.dismiss();
approvePost(abskeydel, 0);

Toast.makeText(getActivity(), getResources().getString(R.string.cantedititem), Toast.LENGTH_SHORT).show();

//Intent i = new Intent(getActivity(), NewPostActivity.class);
//Bundle extras = new Bundle();
//extras.putString("editx", "1");
//extras.putString("keyx", abskeydel);

//i.putExtras(extras);
//startActivity(i);
}
});
dialog.show();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.eusecom.attendance.fragment;
import com.eusecom.attendance.SettingsActivity;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.Query;


public class MyApproveFragment extends AbsenceListFragment {
public class MyApproveFragment extends ApproveListFragment {

private DatabaseReference mDatabase;

Expand All @@ -13,10 +14,10 @@ public MyApproveFragment() {}
@Override
public Query getQuery(DatabaseReference databaseReference) {

final String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
final String companyIco = SettingsActivity.getUsIco(getActivity());

// [START absences_query]
Query recentAbsencesQuery = databaseReference.child("user-absences").child(userId).orderByChild("datm")
Query recentAbsencesQuery = databaseReference.child("company-absences").child(companyIco).orderByChild("aprv").equalTo("0")
.limitToFirst(200);
// [END absences_query]

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

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.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.squareup.picasso.Picasso;

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

public class ApproveViewHolder extends RecyclerView.ViewHolder {

public TextView absence_name;
public ImageView absence_photo;
public ImageView starView;
public TextView numStarsView;
public TextView datefrom;
public TextView dateto;
public TextView hodxb;
public TextView datm;
FirebaseUser user;
private FirebaseAuth mAuth;
String usemail = "";
Context mContext;

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

absence_name = (TextView) itemView.findViewById(R.id.absence_name);
absence_photo = (ImageView) itemView.findViewById(R.id.absence_photo);
starView = (ImageView) itemView.findViewById(R.id.star);
numStarsView = (TextView) itemView.findViewById(R.id.post_num_stars);
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);
mContext = itemView.getContext();

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

}

public void bindToApprove(com.eusecom.attendance.models.Attendance attendance, View.OnClickListener starClickListener) {

absence_name.setText(attendance.dmxa + " " + attendance.dmna);
if( attendance.dmxa.equals("506")) {
Picasso.with(mContext).load(R.drawable.abs506).resize(120, 120).into(absence_photo);
}
if( attendance.dmxa.equals("510")) {
Picasso.with(mContext).load(R.drawable.abs510).resize(120, 120).into(absence_photo);
}
if( attendance.dmxa.equals("518")) {
Picasso.with(mContext).load(R.drawable.abs518).resize(120, 120).into(absence_photo);
}
if( attendance.dmxa.equals("520")) {
Picasso.with(mContext).load(R.drawable.abs520).resize(120, 120).into(absence_photo);
}
if( attendance.dmxa.equals("801")) {
Picasso.with(mContext).load(R.drawable.abs801).resize(120, 120).into(absence_photo);
}
numStarsView.setText(attendance.aprv);
if( attendance.aprv.equals("1")) {
Picasso.with(mContext).load(R.drawable.ic_check_circle_black_24dp).resize(120, 120).into(starView);
}

//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;
long timestampm = attendance.getDatsLong();
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";
}
}

}
47 changes: 47 additions & 0 deletions app/src/main/res/layout/approve_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp" />

<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:layout_toRightOf="@+id/image"/>/>

<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:layout_below="@+id/image"
android:orientation="horizontal">

<Button
android:id="@+id/buttonApprove"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="@string/approve"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
/>

<Button
android:id="@+id/buttonRefuse"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="@string/refuse"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
/>

</LinearLayout>

</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<string name="attendances">Attendances</string>
<string name="abstypes">AbsTypes</string>
<string name="approve">Approve</string>
<string name="refuse">Refuse</string>

<string-array name="AbsenceSpinnerArray">
<item>506 Holliday</item>
Expand Down

0 comments on commit e49ba43

Please sign in to comment.