use of br.ufrj.caronae.adapters.MyActiveRidesAdapter in project caronae-android by caronae.
the class MyRidesListFrag method getActiveRides.
private void getActiveRides() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
CaronaeAPI.service(getContext()).getMyActiveRides().enqueue(new Callback<List<RideForJson>>() {
@Override
public void onResponse(Call<List<RideForJson>> call, Response<List<RideForJson>> response) {
if (response.isSuccessful()) {
List<RideForJson> rideWithUsersList = response.body();
if (rideWithUsersList == null || rideWithUsersList.isEmpty()) {
MyRidesFrag.hideProgressBar();
myRidesList.setAdapter(new MyActiveRidesAdapter(new ArrayList<RideForJson>(), (MainAct) getActivity()));
myRidesList.setHasFixedSize(true);
myRidesList.setLayoutManager(new LinearLayoutManager(getActivity()));
new LoadRides().execute();
return;
}
ActiveRide.deleteAll(ActiveRide.class);
// subscribe to ride id topic
for (RideForJson rideWithUsers : rideWithUsersList) {
int rideId = rideWithUsers.getId().intValue();
rideWithUsers.setDbId(rideId);
FirebaseTopicsHandler.subscribeFirebaseTopic(rideId + "");
new ActiveRide(rideWithUsers.getDbId(), rideWithUsers.isGoing(), rideWithUsers.getDate()).save();
}
Collections.sort(rideWithUsersList, new RideOfferComparatorByDateAndTime());
addAllActiveRidesToList(rideWithUsersList);
MyRidesFrag.hideProgressBar();
} else {
Util.treatResponseFromServer(response);
MyRidesFrag.hideProgressBar();
norides_tv.setVisibility(View.VISIBLE);
Util.toast(R.string.frag_myactiverides_errorGetActiveRides);
Log.e("getMyActiveRides", response.message());
}
new LoadRides().execute();
}
@Override
public void onFailure(Call<List<RideForJson>> call, Throwable t) {
MyRidesFrag.hideProgressBar();
norides_tv.setVisibility(View.VISIBLE);
Util.toast(R.string.frag_myactiverides_errorGetActiveRides);
new LoadRides().execute();
Log.e("getMyActiveRides", t.getMessage());
}
});
}
});
}
Aggregations