Search in sources :

Example 1 with WishlistRequest_GETALL

use of com.usp.icmc.taemcasa.Wishlist.WishlistResponse.WishlistRequest_GETALL in project TaEmCasa by Dionen.

the class WishlistActivity method downloadWishlist.

private void downloadWishlist() {
    final Context context = getContext();
    carregandoWishlist(getView());
    vagas.clear();
    Response.Listener<String> responseListener = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            JSONObject jsonResponse = null;
            layoutWishlist(getView());
            try {
                jsonResponse = new JSONObject(response);
                boolean success = jsonResponse.getBoolean("success");
                if (success) {
                    JSONArray wishlistResponse = jsonResponse.getJSONArray("data");
                    if (wishlistResponse.length() == 0)
                        vaziaWishlist(getView());
                    for (int i = 0; i < wishlistResponse.length(); i++) {
                        JSONObject atual = wishlistResponse.getJSONObject(i);
                        Vaga vaga = new Vaga();
                        Endereco end = new Endereco();
                        vaga.setPrice(atual.getString("vaga.preco"));
                        vaga.setTitle(atual.getString("republica.nome"));
                        vaga.setImagem(atual.getString("republica.imagem"));
                        end.setRua(atual.getString("republica.rua"));
                        end.setNumero(atual.getString("republica.numero"));
                        end.setComplemento(atual.getString("republica.complemento"));
                        end.setBairro(atual.getString("republica.bairro"));
                        end.setCidade(atual.getString("republica.cidade"));
                        end.setEstado(atual.getString("republica.estado"));
                        vaga.setAddress(end);
                        vagas.add(vaga);
                    }
                    adapter.notifyDataSetChanged();
                } else {
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    };
    /* ENTRA NA DATABASE ONLINE */
    WishlistRequest_GETALL wishlistRequest = new WishlistRequest_GETALL(getActivity().getIntent().getExtras().getString("user_id"), responseListener);
    RequestQueue queue = Volley.newRequestQueue(getContext());
    // Executa as tarefas requisitadas
    queue.add(wishlistRequest);
}
Also used : Context(android.content.Context) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Vaga(com.usp.icmc.taemcasa.Structures.Vaga) Endereco(com.usp.icmc.taemcasa.Structures.Endereco) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) WishlistRequest_GETALL(com.usp.icmc.taemcasa.Wishlist.WishlistResponse.WishlistRequest_GETALL)

Aggregations

Context (android.content.Context)1 RequestQueue (com.android.volley.RequestQueue)1 Response (com.android.volley.Response)1 Endereco (com.usp.icmc.taemcasa.Structures.Endereco)1 Vaga (com.usp.icmc.taemcasa.Structures.Vaga)1 WishlistRequest_GETALL (com.usp.icmc.taemcasa.Wishlist.WishlistResponse.WishlistRequest_GETALL)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1