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;
}
Aggregations