-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaDetails.java
138 lines (117 loc) · 4.91 KB
/
StaDetails.java
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
package com.example.fbans.projecthm;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.EditText;
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.JsonArrayRequest;
import com.android.volley.toolbox.StringRequest;
import com.example.fbans.projecthm.utils.Constants;
import com.example.fbans.projecthm.utils.Patient;
import com.example.fbans.projecthm.utils.RequestHandler;
import com.example.fbans.projecthm.utils.Staff;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class StaDetails extends Fragment {
View vi;
RecyclerView recyclerView;
StaffDetailsAdapter adapter =new StaffDetailsAdapter();
List<Staff> staffs = new ArrayList<>();
EditText searchText;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
vi = inflater.inflate(R.layout.layout_staffdetails,container,false);
return vi;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
recyclerView = vi.findViewById(R.id.StaffDetailsRecyclerView);
searchText = vi.findViewById(R.id.editTextSearch);
searchText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
//after the change calling the method and passing the search input
filter(editable.toString());
}
});
if (recyclerView!=null) {
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
recyclerView.setAdapter(adapter);
staffData();
}
private void filter(String text) {
//new array list that will hold the filtered data
ArrayList<Staff> filterdNames = new ArrayList<>();
//looping through existing elements
for (Staff row : staffs) {
//if the existing elements contains the search input
if (row.getName().toLowerCase().contains(text.toLowerCase())) {
//adding the element to filtered list
filterdNames.add(row);
}
}
//calling a method of the adapter class and passing the filtered list
adapter.filterList(filterdNames);
}
public void staffData(){
final StringRequest request = new StringRequest(Request.Method.POST, Constants.Users_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray array = new JSONArray(response);
for (int i = 0;i<array.length();i++){
JSONObject object = array.getJSONObject(i);
Staff staff= new Staff(object.getString("name"),object.getString("age"),
object.getString("gender"),object.getString("moblie"));
staffs.add(staff);
}
adapter = new StaffDetailsAdapter(getContext(),staffs);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Volley Error:",error.getMessage());
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("f1","staff");
return params;
}
};
RequestHandler.getInstance(getContext()).addToRequestQueue(request);
}
}