Search in sources :

Example 1 with TeachersAdapter

use of dz.easy.androidclient.Adapters.TeachersAdapter in project easy by MehdiBenmesa.

the class RendezVousActivity method getTeachers.

private void getTeachers() {
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_TEACHERS, null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            JSONArray teachers = response;
            if (GRID_LAYOUT) {
                lstView.setLayoutManager(new GridLayoutManager(RendezVousActivity.this, 2));
            } else {
                lstView.setLayoutManager(new LinearLayoutManager(RendezVousActivity.this));
            }
            lstView.setHasFixedSize(true);
            // Use this now
            lstView.addItemDecoration(new MaterialViewPagerHeaderDecorator());
            lstView.setAdapter(new TeachersAdapter(teachers, (TeachersAdapter.AdapterInterface) RendezVousActivity.this));
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) TeachersAdapter(dz.easy.androidclient.Adapters.TeachersAdapter) CustomRequestArray(dz.easy.androidclient.Util.CustomRequestArray) GridLayoutManager(android.support.v7.widget.GridLayoutManager) JSONArray(org.json.JSONArray) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterialViewPagerHeaderDecorator(com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)

Example 2 with TeachersAdapter

use of dz.easy.androidclient.Adapters.TeachersAdapter in project easy by MehdiBenmesa.

the class RendezVousActivity method getTeachersSearcheed.

private void getTeachersSearcheed(final String newTextS) {
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_TEACHERS, null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            JSONArray teachers = response;
            if (GRID_LAYOUT) {
                lstView.setLayoutManager(new GridLayoutManager(RendezVousActivity.this, 2));
            } else {
                lstView.setLayoutManager(new LinearLayoutManager(RendezVousActivity.this));
            }
            lstView.setHasFixedSize(true);
            // Use this now
            lstView.addItemDecoration(new MaterialViewPagerHeaderDecorator());
            // Search action
            JSONArray lstFound = new JSONArray();
            JSONObject item = null;
            for (int i = 0; i < teachers.length(); i++) {
                try {
                    item = teachers.getJSONObject(i);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (item.getString("name").contains(newTextS) || item.getString("lastname").contains(newTextS)) {
                        lstFound.put(item);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            /*ArrayAdapter adapter = new ArrayAdapter(RendeVous.this, android.R.layout.simple_list_item_1, lstFound);
          lstView.setAdapter(adapter);*/
            lstView.setAdapter(new TeachersAdapter(lstFound, (TeachersAdapter.AdapterInterface) RendezVousActivity.this));
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : VolleyError(com.android.volley.VolleyError) TeachersAdapter(dz.easy.androidclient.Adapters.TeachersAdapter) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Response(com.android.volley.Response) CustomRequestArray(dz.easy.androidclient.Util.CustomRequestArray) GridLayoutManager(android.support.v7.widget.GridLayoutManager) JSONObject(org.json.JSONObject) MaterialViewPagerHeaderDecorator(com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)

Example 3 with TeachersAdapter

use of dz.easy.androidclient.Adapters.TeachersAdapter in project easy by MehdiBenmesa.

the class RendezVousFragment method onReceiveResult.

@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
    switch(resultCode) {
        case STATUS_RUNNING:
            dialogListner.showDialog();
            break;
        case STATUS_FINISHED:
            /* Hide progress & extract result from bundle */
            dialogListner.hideDialog();
            switch(resultData.getString("action")) {
                case GET_RENDEZVOUS_MANAGER:
                    String jsonStringManager = resultData.getString("result");
                    JSONArray response = null;
                    try {
                        response = new JSONArray(jsonStringManager);
                        recyclerViewRendeVous.setAdapter(new TeachersAdapter(response, (TeachersAdapter.AdapterInterface) this));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    /*
<<<<<<< HEAD
            recyclerViewRendeVous.setHasFixedSize(true);

            //Use this now
            recyclerViewRendeVous.addItemDecoration(new MaterialViewPagerHeaderDecorator());
            recyclerViewRendeVous.setAdapter(new TestRecyclerViewAdapter(response,(TestRecyclerViewAdapter.AdapterInterface) RendezVousFragment.this));


          }
        }, new Response.ErrorListener() {
      *
        @Override
            public void onErrorResponse(VolleyError error) {
            */
                    break;
                case GET_RENDEZVOUS_STUDENT:
                    String jsonStringStudent = resultData.getString("result");
                    JSONArray responseStudent = null;
                    try {
                        responseStudent = new JSONArray(jsonStringStudent);
                    // recyclerViewRendeVous.setAdapter(new TeachersAdapter(responseStudent));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    break;
                case GET_RENDEZVOUS_TEACHER:
                    String jsonStringTeacher = resultData.getString("result");
                    JSONArray responseTeacher = null;
                    try {
                        responseTeacher = new JSONArray(jsonStringTeacher);
                    // recyclerViewRendeVous.setAdapter(new TeachersAdapter(responseTeacher));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    break;
            }
            break;
        case STATUS_ERROR:
            /* Handle the error */
            String error = resultData.getString(Intent.EXTRA_TEXT);
            Toast.makeText(getContext(), error, Toast.LENGTH_LONG).show();
            break;
    }
}
Also used : TeachersAdapter(dz.easy.androidclient.Adapters.TeachersAdapter) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

TeachersAdapter (dz.easy.androidclient.Adapters.TeachersAdapter)3 JSONArray (org.json.JSONArray)3 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 Response (com.android.volley.Response)2 VolleyError (com.android.volley.VolleyError)2 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)2 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)1