-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaffViewAppo.java
More file actions
157 lines (135 loc) · 5.93 KB
/
StaffViewAppo.java
File metadata and controls
157 lines (135 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.example.fbans.projecthm;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.fbans.projecthm.utils.Appointment;
import com.example.fbans.projecthm.utils.Constants;
import com.example.fbans.projecthm.utils.RequestHandler;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class StaffViewAppo extends Fragment {
Button datepicker ;
TextView date;
private int mYear, mMonth, mDay;
RecyclerView recyclerView;
StaffViewAppoAdap adapter = new StaffViewAppoAdap();
List<Appointment> appointments=new ArrayList<>();
View vi;
ProgressDialog progressDialog;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
vi = inflater.inflate(R.layout.staff_view_appo,container,false);
return vi;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
datepicker= (Button) vi.findViewById(R.id.submit);
recyclerView = vi.findViewById(R.id.recycler);
if (recyclerView!=null) {
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
recyclerView.setAdapter(adapter);
datepicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewAppo();
}
});
date=(TextView)vi.findViewById(R.id.search_date);
date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view == date) {
// Get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year,
int monthOfYear, int dayOfMonth) {
date.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis()-1000);
datePickerDialog.show();
}
}
});
progressDialog = new ProgressDialog(getContext());
}
public void viewAppo() {
Log.i("Into View Appo:", "Json Parsing");
final String apdate = date.getText().toString();
if (date.getText().toString().equals("")) {
Toast.makeText(getContext(), "Enter date", Toast.LENGTH_LONG).show();
}
progressDialog.setMessage("Loading...");
progressDialog.show();
final StringRequest request = new StringRequest(Request.Method.POST, Constants.VIEW_APPO_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
appointments.clear();
progressDialog.dismiss();
try {
JSONArray array = new JSONArray(response);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
Appointment appointment = new Appointment(object.getInt("id"), object.getString("name"), object.getString("time"), object.getString("moblie"), object.getString("purpose"));
appointments.add(appointment);
}
if (appointments.isEmpty()){
Toast.makeText(getContext(), "No appointments", Toast.LENGTH_SHORT).show();
}
adapter = new StaffViewAppoAdap(getContext(), appointments);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Log.i("Volley Error:", error.getMessage());
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("f1", apdate);
return params;
}
};
RequestHandler.getInstance(getContext()).addToRequestQueue(request);
}
}