Guest User

Untitled

a guest
Feb 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. public class UserStatusEntry {
  2. String name,people,esti,phone;
  3. public UserStatusEntry(){
  4. }
  5. public String getPhone() {
  6. return phone;
  7. }
  8. public void setPhone(String phone) {
  9. this.phone = phone;
  10. }
  11. public String getName() {
  12. return name;
  13. }
  14. public void setName(String name) {
  15. this.name = name;
  16. }
  17. public String getPeople() {
  18. return people;
  19. }
  20. public void setPeople(String people) {
  21. this.people = people;
  22. }
  23. public String getEsti() {
  24. return esti;
  25. }
  26. public void setEsti(String esti) {
  27. this.esti = esti;
  28. }
  29. }
  30.  
  31. public class CardAdapter extends BaseAdapter {
  32. private ArrayList<UserStatusEntry> entries;
  33. private Context context;
  34. private LayoutInflater inflater;
  35. public CardAdapter(Context context,LayoutInflater inflater,ArrayList<UserStatusEntry> entries)
  36. {
  37. this.entries=entries;
  38. this.context=context;
  39. this.inflater=inflater;
  40. }
  41. @Override
  42. public int getCount() {
  43. return entries.size();
  44. }
  45. @Override
  46. public Object getItem(int position) {
  47. return entries.get(position);
  48. }
  49. @Override
  50. public long getItemId(int position)
  51. {
  52. return position;
  53. }
  54.  
  55. public static class ViewHolder {
  56. public TextView name;
  57. public TextView people;
  58. public TextView esti;
  59. public TextView phone;
  60. }
  61. @Override
  62. public View getView(int position, View convertView, ViewGroup parent) {
  63. ViewHolder viewHolder;
  64. if(convertView==null)
  65. {
  66. convertView=inflater.inflate(R.layout.user_satus_info_card,parent,false);
  67. viewHolder=new ViewHolder();
  68. viewHolder.name=(TextView)convertView.findViewById(R.id.name);
  69. viewHolder.people=(TextView)convertView.findViewById(R.id.adults);
  70. viewHolder.phone=(TextView)convertView.findViewById(R.id.phone);
  71. viewHolder.esti=(TextView)convertView.findViewById(R.id.esti);
  72. convertView.setTag(viewHolder);
  73. }
  74. else
  75. {
  76. viewHolder=(ViewHolder)convertView.getTag();
  77. }
  78. UserStatusEntry entry=entries.get(position);
  79. viewHolder.name.setText(entry.getName());
  80. viewHolder.people.setText(entry.getPeople());
  81. viewHolder.phone.setText(entry.getPhone());
  82. viewHolder.esti.setText(entry.getEsti());
  83. return convertView;
  84. }
  85.  
  86. }
  87.  
  88. @Override
  89. protected void onCreate(Bundle savedInstanceState) {
  90. super.onCreate(savedInstanceState);
  91. setContentView(R.layout.activity_main);
  92. //entry=new ArrayList<>();
  93. flingAdapterView=(SwipeFlingAdapterView)findViewById(R.id.swipe_fling_view);
  94. setCardAdapter();
  95. flingAdapterView.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
  96. @Override
  97. public void removeFirstObjectInAdapter() {
  98.  
  99. }
  100.  
  101. @Override
  102. public void onLeftCardExit(Object o) {
  103. entry.remove(0);
  104. adapter.notifyDataSetChanged();
  105. }
  106.  
  107. @Override
  108. public void onRightCardExit(Object o) {
  109. entry.remove(0);
  110. adapter.notifyDataSetChanged();
  111. }
  112.  
  113. @Override
  114. public void onAdapterAboutToEmpty(int i) {
  115.  
  116. }
  117.  
  118. @Override
  119. public void onScroll(float v) {
  120.  
  121. View view = flingAdapterView.getSelectedView();
  122.  
  123. }
  124.  
  125. });
  126.  
  127. JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, url, null,
  128. new Response.Listener<JSONObject>() {
  129. @Override
  130. public void onResponse(JSONObject response) {
  131. try
  132. {
  133.  
  134. JSONObject object=new JSONObject(response.toString());
  135. JSONArray data=object.getJSONArray("results");
  136. for(int i=0;i<data.length();i++)
  137. {
  138. JSONObject json = data.getJSONObject(i);
  139. final UserStatusEntry c=new UserStatusEntry();
  140. c.setPeople(json.getString("no_people"));
  141. String temp=json.getString("predicated_t");
  142. // c.setName(foodie_name+"t"+lname);
  143. c.setEsti(temp+"min");
  144. userUrl=json.getString("namie");
  145. JsonObjectRequest request=new JsonObjectRequest(Request.Method.GET, userUrl, null, new Response.Listener<JSONObject>() {
  146. @Override
  147. public void onResponse(JSONObject response) {
  148. try {
  149. c.setPhone(response.getString("phone"));
  150. JSONObject temp=response.getJSONObject("user");
  151. foodie_name=temp.getString("first_name");
  152. lname=temp.getString("last_name");
  153. c.setName(foodie_name+"t"+lname);
  154. } catch (JSONException e) {
  155. e.printStackTrace();
  156. }
  157. }
  158. }, new Response.ErrorListener() {
  159. @Override
  160. public void onErrorResponse(VolleyError error) {
  161.  
  162. }
  163. })
  164.  
  165. {
  166.  
  167. }
  168. AppController.getInstance().addToRequestQueue(request,second_req);
  169. entry.add(c);
  170. adapter=new CardAdapter(MainActivity.this,getLayoutInflater(),entry);
  171. flingAdapterView.setAdapter(adapter);
  172. }
  173. }
  174. catch (JSONException e)
  175. {
  176. e.printStackTrace();
  177. }
  178.  
  179. }
  180. },
  181. new Response.ErrorListener() {
  182. @Override
  183. public void onErrorResponse(VolleyError error) {
  184.  
  185. }
  186.  
  187. })
  188. {
  189.  
  190. };
  191. AppController.getInstance().addToRequestQueue(req,json_req);
Add Comment
Please, Sign In to add comment