Search in sources :

Example 1 with RideSearchFiltersForJson

use of br.ufrj.caronae.models.modelsforjson.RideSearchFiltersForJson in project caronae-android by caronae.

the class RideSearchFrag method searchBt.

@OnClick(R.id.search_bt)
public void searchBt() {
    String location = location_et.getText().toString();
    if (location.isEmpty()) {
        Util.toast(getString(R.string.frag_rideSearch_locationEmpty));
        return;
    } else {
        if (location.contains("+")) {
            location = neighborhoods;
        }
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
    String etDateString = date_et.getText().toString();
    Date todayDate = new Date();
    String todayString = simpleDateFormat.format(todayDate);
    try {
        todayDate = simpleDateFormat.parse(todayString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (etDateString.isEmpty()) {
        date_et.setText(todayString);
        etDateString = todayString;
    } else {
        try {
            Date etDate = simpleDateFormat.parse(etDateString);
            if (etDate.before(todayDate)) {
                Util.toast(getString(R.string.frag_rideoffersearch_pastdate));
                return;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    String time = time_et.getText().toString();
    if (time.isEmpty()) {
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm", Locale.US);
        String format = simpleDateFormat1.format(new Date());
        time_et.setText(format);
        time = format;
    }
    String center = center_et.getText().toString();
    if (center.equals(Util.getFundaoCenters()[0]) || center.equals("Cidade Universitária"))
        center = "";
    String campus = campi;
    boolean go = radioGroup.getCheckedRadioButtonId() == R.id.go_rb;
    RideSearchFiltersForJson rideSearchFilters = new RideSearchFiltersForJson(location, etDateString, time, center, campus, go, location_et.getText().toString());
    String lastRideSearchFilters = new Gson().toJson(rideSearchFilters);
    SharedPref.saveLastRideSearchFiltersPref(lastRideSearchFilters);
    rideSearchFilters.setDate(Util.formatBadDateWithYear(etDateString));
    Log.e("INPUT", "location: " + location);
    Log.e("INPUT", "data: " + etDateString);
    Log.e("INPUT", "hora: " + time);
    Log.e("INPUT", "center: " + center);
    Log.e("INPUT", "campus: " + campus);
    Log.e("INPUT", "locationResumeField: " + location_et.getText().toString());
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", getContext().getString(R.string.wait), true, true);
    CaronaeAPI.service(getContext()).listFiltered(rideSearchFilters).enqueue(new Callback<List<RideForJson>>() {

        @Override
        public void onResponse(Call<List<RideForJson>> call, Response<List<RideForJson>> response) {
            if (response.isSuccessful()) {
                List<RideForJson> rideOffers = response.body();
                if (rideOffers != null && !rideOffers.isEmpty()) {
                    Util.expandOrCollapse(lay, false);
                    anotherSearch_bt.setVisibility(View.VISIBLE);
                    Collections.sort(rideOffers, new RideOfferComparatorByDateAndTime());
                    for (RideForJson rideOffer : rideOffers) {
                        rideOffer.setDbId(rideOffer.getId().intValue());
                    }
                    adapter.makeList(rideOffers);
                } else {
                    Util.treatResponseFromServer(response);
                    Util.toast(R.string.frag_rideSearch_noRideFound);
                    adapter.makeList(new ArrayList<RideForJson>());
                }
                pd.dismiss();
            } else {
                pd.dismiss();
                Util.toast(R.string.frag_rideSearch_errorListFiltered);
                Log.e("listFiltered", response.message());
            }
        }

        @Override
        public void onFailure(Call<List<RideForJson>> call, Throwable t) {
            pd.dismiss();
            Util.toast(R.string.frag_rideSearch_errorListFiltered);
            Log.e("listFiltered", t.getMessage());
        }
    });
}
Also used : RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) ProgressDialog(android.app.ProgressDialog) Date(java.util.Date) RideOfferComparatorByDateAndTime(br.ufrj.caronae.comparators.RideOfferComparatorByDateAndTime) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) RideSearchFiltersForJson(br.ufrj.caronae.models.modelsforjson.RideSearchFiltersForJson) SimpleDateFormat(java.text.SimpleDateFormat) OnClick(butterknife.OnClick)

Example 2 with RideSearchFiltersForJson

use of br.ufrj.caronae.models.modelsforjson.RideSearchFiltersForJson in project caronae-android by caronae.

the class RideSearchFrag method loadLastFilters.

private void loadLastFilters(String lastRideSearchFilters) {
    RideSearchFiltersForJson rideSearchFilters = new Gson().fromJson(lastRideSearchFilters, RideSearchFiltersForJson.class);
    location_et.setText(rideSearchFilters.getLocationResumedField());
    neighborhoods = rideSearchFilters.getLocation();
    date_et.setText(rideSearchFilters.getDate());
    time_et.setText(rideSearchFilters.getTime());
    center_et.setText(rideSearchFilters.getCenter());
    boolean go = rideSearchFilters.isGo();
    radioGroup.check(go ? R.id.go_rb : R.id.back_rb);
}
Also used : Gson(com.google.gson.Gson) RideSearchFiltersForJson(br.ufrj.caronae.models.modelsforjson.RideSearchFiltersForJson)

Aggregations

RideSearchFiltersForJson (br.ufrj.caronae.models.modelsforjson.RideSearchFiltersForJson)2 Gson (com.google.gson.Gson)2 ProgressDialog (android.app.ProgressDialog)1 RideOfferComparatorByDateAndTime (br.ufrj.caronae.comparators.RideOfferComparatorByDateAndTime)1 RideForJson (br.ufrj.caronae.models.modelsforjson.RideForJson)1 OnClick (butterknife.OnClick)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1