Search in sources :

Example 1 with RideComparatorByDateAndTimeReverse

use of br.ufrj.caronae.comparators.RideComparatorByDateAndTimeReverse in project caronae-android by caronae.

the class RidesHistoryFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_rides_history, container, false);
    ButterKnife.bind(this, view);
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", getContext().getString(R.string.wait), true, true);
    CaronaeAPI.service(getContext()).getRidesHistory().enqueue(new Callback<List<RideHistoryForJson>>() {

        @Override
        public void onResponse(Call<List<RideHistoryForJson>> call, Response<List<RideHistoryForJson>> response) {
            if (response.isSuccessful()) {
                List<RideHistoryForJson> historyRides = response.body();
                if (historyRides == null || historyRides.isEmpty()) {
                    norides_tv.setVisibility(View.VISIBLE);
                    pd.dismiss();
                    return;
                }
                for (RideForJson rideHistory : historyRides) {
                    rideHistory.setDbId(rideHistory.getId().intValue());
                    rideHistory.setTime(Util.formatTime(rideHistory.getTime()));
                    rideHistory.setDate(Util.formatBadDateWithYear(rideHistory.getDate()));
                }
                Collections.sort(historyRides, new RideComparatorByDateAndTimeReverse());
                myRidesList.setAdapter(new RidesHistoryAdapter(historyRides, (MainAct) getActivity()));
                myRidesList.setHasFixedSize(true);
                myRidesList.setLayoutManager(new LinearLayoutManager(getActivity()));
                pd.dismiss();
            } else {
                Util.treatResponseFromServer(response);
                norides_tv.setVisibility(View.VISIBLE);
                pd.dismiss();
                Util.toast(R.string.frag_rideshistory_errorGetRides);
                Log.e("getRidesHistory", response.message());
            }
        }

        @Override
        public void onFailure(Call<List<RideHistoryForJson>> call, Throwable t) {
            norides_tv.setVisibility(View.VISIBLE);
            pd.dismiss();
            Util.toast(R.string.frag_rideshistory_errorGetRides);
            Log.e("getRidesHistory", t.getMessage());
        }
    });
    return view;
}
Also used : RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) RidesHistoryAdapter(br.ufrj.caronae.adapters.RidesHistoryAdapter) List(java.util.List) ProgressDialog(android.app.ProgressDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RideComparatorByDateAndTimeReverse(br.ufrj.caronae.comparators.RideComparatorByDateAndTimeReverse)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 RidesHistoryAdapter (br.ufrj.caronae.adapters.RidesHistoryAdapter)1 RideComparatorByDateAndTimeReverse (br.ufrj.caronae.comparators.RideComparatorByDateAndTimeReverse)1 RideForJson (br.ufrj.caronae.models.modelsforjson.RideForJson)1 BindView (butterknife.BindView)1 List (java.util.List)1