Search in sources :

Example 1 with SearchRequest

use of com.usp.icmc.taemcasa.Busca.SearchRequest.SearchRequest in project TaEmCasa by Dionen.

the class SearchMenu method search.

public void search(final View view) {
    String animais = "0";
    String tipo_M_F = "2";
    String tipo_R_A = "2";
    String individual = "0";
    String perfil = "2";
    final Context context = view.getContext();
    EditText maxValue_camp = (EditText) getView().findViewById(R.id.edtMaxPreco);
    EditText minValue_camp = (EditText) getView().findViewById(R.id.edtMinPreco);
    CheckBox animals_camp = (CheckBox) getView().findViewById(R.id.checkboxAnimais);
    if (animals_camp.isChecked())
        animais = "1";
    ToggleButton apt_camp = (ToggleButton) getView().findViewById(R.id.toggleButtonApt);
    ToggleButton rep_camp = (ToggleButton) getView().findViewById(R.id.toggleButtonRep);
    if (apt_camp.isChecked() && !rep_camp.isChecked())
        tipo_R_A = "0";
    if (!apt_camp.isChecked() && rep_camp.isChecked())
        tipo_R_A = "1";
    CheckBox calmo_camp = (CheckBox) getView().findViewById(R.id.checkBoxCalmo);
    CheckBox agitado_camp = (CheckBox) getView().findViewById(R.id.checkBoxAgitado);
    if (calmo_camp.isChecked() && !agitado_camp.isChecked())
        perfil = "0";
    if (!calmo_camp.isChecked() && agitado_camp.isChecked())
        perfil = "1";
    RadioButton masculino = (RadioButton) getView().findViewById(R.id.masculina);
    RadioButton feminina = (RadioButton) getView().findViewById(R.id.feminina);
    if (masculino.isChecked())
        tipo_M_F = "0";
    if (feminina.isChecked())
        tipo_M_F = "1";
    CheckBox quartoIndividual = (CheckBox) getView().findViewById(R.id.quartoIndividual);
    if (quartoIndividual.isChecked())
        individual = "1";
    final MessagesToUser message = new MessagesToUser();
    Response.Listener<String> responseListener = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            JSONObject jsonResponse = null;
            // message.ToastMessage(response, context);
            try {
                jsonResponse = new JSONObject(response);
                boolean success = jsonResponse.getBoolean("success");
                if (success) {
                    Intent intent = new Intent(getActivity(), SearchListActivity.class);
                    JSONArray searchResponse = jsonResponse.getJSONArray("data");
                    ArrayList<Vaga> vagas = new ArrayList<>();
                    if (searchResponse.length() <= 0) {
                        message.ToastMessage("Não há vagas com esses critérios", context);
                    // return;
                    }
                    for (int i = 0; i < searchResponse.length(); i++) {
                        JSONObject atual = searchResponse.getJSONObject(i);
                        Vaga vaga = new Vaga();
                        Endereco end = new Endereco();
                        vaga.setPrice(atual.getString("vaga.preco"));
                        vaga.setTitle(atual.getString("republica.nome"));
                        end.setRua(atual.getString("republica.rua"));
                        end.setNumero(atual.getString("republica.numero"));
                        end.setComplemento(atual.getString("republica.complemento"));
                        end.setCidade(atual.getString("republica.cidade"));
                        end.setEstado(atual.getString("republica.estado"));
                        vaga.setAddress(end);
                        vagas.add(vaga);
                    }
                    intent.putExtra("vagas", vagas);
                    startActivity(intent);
                } else {
                    message.ToastMessage("Falha no request", context);
                }
            } catch (JSONException e) {
                e.printStackTrace();
                message.ToastMessage("Falha na conexão", context);
            }
        }
    };
    /* ENTRA NA DATABASE ONLINE */
    SearchRequest searchRequest = new SearchRequest(minValue_camp.getText().toString(), maxValue_camp.getText().toString(), tipo_M_F, individual, animais, tipo_R_A, perfil, responseListener);
    RequestQueue queue = Volley.newRequestQueue(getActivity());
    // Executa as tarefas requisitadas
    queue.add(searchRequest);
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) SearchRequest(com.usp.icmc.taemcasa.Busca.SearchRequest.SearchRequest) ToggleButton(android.widget.ToggleButton) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) Vaga(com.usp.icmc.taemcasa.Structures.Vaga) Endereco(com.usp.icmc.taemcasa.Structures.Endereco) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) CheckBox(android.widget.CheckBox) RequestQueue(com.android.volley.RequestQueue) MessagesToUser(com.usp.icmc.taemcasa.Utils.MessagesToUser)

Aggregations

Context (android.content.Context)1 Intent (android.content.Intent)1 CheckBox (android.widget.CheckBox)1 EditText (android.widget.EditText)1 RadioButton (android.widget.RadioButton)1 ToggleButton (android.widget.ToggleButton)1 RequestQueue (com.android.volley.RequestQueue)1 Response (com.android.volley.Response)1 SearchRequest (com.usp.icmc.taemcasa.Busca.SearchRequest.SearchRequest)1 Endereco (com.usp.icmc.taemcasa.Structures.Endereco)1 Vaga (com.usp.icmc.taemcasa.Structures.Vaga)1 MessagesToUser (com.usp.icmc.taemcasa.Utils.MessagesToUser)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1