Advertisement
Guest User

Untitled

a guest
May 25th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. public class dayActivities extends AppCompatActivity {
  2. private RecyclerView mRecyclerView;
  3. private JsonManager json;
  4. ArrayList<Tarea> list;
  5. RequestQueue requestQueue;
  6. String url="http://186.16.12.200:3000/agenda1";
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_day_activities);
  12.  
  13.  
  14. Bundle b = getIntent().getExtras();
  15. String date = b.getString("fecha");
  16. setTitle(getDate(date));
  17. requestQueue= Volley.newRequestQueue(getApplicationContext());;
  18.  
  19. mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
  20. mRecyclerView.setHasFixedSize(true);
  21. LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
  22. layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  23.  
  24. mRecyclerView.setLayoutManager(layoutManager);
  25. this.getData(date);
  26.  
  27.  
  28. }
  29. public void getData(String date){
  30. list=new ArrayList<Tarea>();
  31.  
  32. JsonArrayRequest arrReq = new JsonArrayRequest(Request.Method.GET, url + "?fecha=" + date,null,
  33. new Response.Listener<JSONArray>() {
  34. @Override
  35. public void onResponse(JSONArray response) {
  36. if (response.length() > 0) {
  37. // The user does have repos, so let's loop through them all.
  38. for (int i = 0; i < response.length(); i++) {
  39. try {
  40. // For each repo, add a new line to our repo list.
  41.  
  42. JSONObject jsonObj = response.getJSONObject(i);
  43.  
  44. Integer id = (Integer) jsonObj.get("id");
  45. String actividad = jsonObj.get("actividad").toString();
  46. String fecha = jsonObj.get("fecha").toString();
  47. String inicio = jsonObj.get("horaInicio").toString();
  48. String fin = jsonObj.get("horaFin").toString();
  49.  
  50. list.add(new Tarea(id,actividad,fecha,inicio,fin));
  51.  
  52. } catch (JSONException e) {
  53. // If there is an error then output this to the logs.
  54. Log.e("Volley", "Invalid JSON Object.");
  55. }
  56.  
  57. }
  58. mRecyclerView.setAdapter(new Adaptador(list));
  59. } else {
  60. // The user didn't have any repos.
  61. Log.e("Volley", "Not found");
  62. }
  63. }
  64. }, new Response.ErrorListener() {
  65. @Override
  66. public void onErrorResponse(VolleyError error) {
  67. Log.e("Volley", error.toString());
  68. error.printStackTrace();
  69. }
  70. });
  71. // Add the request we just defined to our request queue.
  72. // The request queue will automatically handle the request as soon as it can.
  73. requestQueue.add(arrReq);
  74.  
  75. }
  76. public String getDate(String fecha){
  77. String meses[]={"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto,","Septiembre","Octubre","Noviembre","Diciembre"};
  78. return fecha.substring(6)+" de "+meses[Integer.parseInt(fecha.substring(4,6))-1]+" del "+fecha.substring(0,4);
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement