use of br.ufrj.caronae.models.modelsforjson.RideForJson in project caronae-android by caronae.
the class RideOfferAct method configureActivityWithLink.
private void configureActivityWithLink() {
Uri uri = getIntent().getData();
final String rideId;
List<String> params = uri.getPathSegments();
if (params.size() == 1) {
rideId = params.get(0);
if (rideId.equals("carona")) {
Intent intent = new Intent(this, MainAct.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
} else
rideId = params.get(1);
mainLayout.setVisibility(View.GONE);
progressBarLayout.setVisibility(View.VISIBLE);
CaronaeAPI.service(this).getRide(rideId).enqueue(new Callback<RideForJson>() {
@Override
public void onResponse(Call<RideForJson> call, Response<RideForJson> response) {
if (response.isSuccessful()) {
RideForJson ride = response.body();
if (Util.getStringDateInMillis(ride.getTime() + " " + ride.getDate()) < (new Date()).getTime()) {
showCustomDialog(getResources().getString(R.string.ride_in_past_header), getResources().getString(R.string.ride_in_past_body));
} else {
ride.setDbId(Integer.parseInt(ride.getId() + ""));
configureActivityWithRide(ride, ride.getAvailableSlots() == 0);
mainLayout.setVisibility(View.VISIBLE);
progressBarLayout.setVisibility(View.GONE);
}
} else {
showCustomDialog(getResources().getString(R.string.ride_failure_header), getResources().getString(R.string.ride_failure_non_exist_body));
}
}
@Override
public void onFailure(Call<RideForJson> call, Throwable t) {
showCustomDialog(getResources().getString(R.string.ride_failure_header), getResources().getString(R.string.ride_failure_fail_body));
}
});
}
use of br.ufrj.caronae.models.modelsforjson.RideForJson in project caronae-android by caronae.
the class AllRidesFrag method listAllRides.
private void listAllRides(final int pageNum) {
final Snackbar snackbar = makeNoConexionSnack();
progressBar2.setVisibility(View.VISIBLE);
if (isAdded() && (getActivity() != null)) {
String going = null;
String neighborhoods = null;
String zone = null;
String hub = null;
String campus = null;
String filtersJsonString = SharedPref.getFiltersPref();
if (!filtersJsonString.equals(SharedPref.MISSING_PREF)) {
RideFiltersForJson rideFilters = new Gson().fromJson(filtersJsonString, RideFiltersForJson.class);
neighborhoods = rideFilters.getLocation();
if (!rideFilters.getCampus().equals("Todos os Campi")) {
hub = rideFilters.getCenter();
campus = rideFilters.getCampus();
}
zone = rideFilters.getZone();
}
CaronaeAPI.service(getContext()).listAllRides(pageNum + "", going, neighborhoods, zone, hub, "", campus).enqueue(new Callback<RideForJsonDeserializer>() {
@Override
public void onResponse(Call<RideForJsonDeserializer> call, Response<RideForJsonDeserializer> response) {
if (response.isSuccessful()) {
progressBar2.setVisibility(View.GONE);
RideForJsonDeserializer data = response.body();
List<RideForJson> rideOffers = data.getData();
if (rideOffers != null && !rideOffers.isEmpty()) {
Collections.sort(rideOffers, new RideOfferComparatorByDateAndTime());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
Date todayDate = new Date();
String todayString = simpleDateFormat.format(todayDate);
simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.US);
String time = simpleDateFormat.format(todayDate);
Iterator<RideForJson> it = rideOffers.iterator();
while (it.hasNext()) {
RideForJson rideOffer = it.next();
if (Util.formatBadDateWithYear(rideOffer.getDate()).equals(todayString) && Util.formatTime(rideOffer.getTime()).compareTo(time) < 0)
it.remove();
else {
rideOffer.setDbId(rideOffer.getId().intValue());
if (rideOffer.isGoing())
if (!checkIfRideIsInList(goingRides, rideOffer))
goingRides.add(rideOffer);
else if (!checkIfRideIsInList(notGoingRides, rideOffer))
notGoingRides.add(rideOffer);
}
}
}
if (isAdded()) {
viewPager.setAdapter(new AllRidesFragmentPagerAdapter(getChildFragmentManager(), goingRides, notGoingRides, App.getInst().getResources().getStringArray(R.array.tab_tags)));
tabLayout.setupWithViewPager(viewPager);
if (PAGE_WAS_GOING)
viewPager.setCurrentItem(0);
else
viewPager.setCurrentItem(1);
tabLayout.setBackground(ContextCompat.getDrawable(App.getInst(), R.drawable.transparency_gradient_top_botton));
configureTabIndicators();
}
} else {
Util.treatResponseFromServer(response);
progressBar2.setVisibility(View.GONE);
Log.e("listAllRides", response.message());
}
}
@Override
public void onFailure(Call<RideForJsonDeserializer> call, Throwable t) {
progressBar2.setVisibility(View.GONE);
Log.e("listAllRides", t.getMessage());
snackbar.setAction("CONECTAR", new View.OnClickListener() {
@Override
public void onClick(View v) {
listAllRides(pageNum);
}
});
}
});
} else {
Util.toast("Activity not atached");
return;
}
}
use of br.ufrj.caronae.models.modelsforjson.RideForJson in project caronae-android by caronae.
the class AllRidesListFrag method refreshRideList.
void refreshRideList(final int pageNumber) {
final long bytesSoFar = TrafficStats.getUidRxBytes(Process.myUid());
String going = null;
if (pageIdentifier == AllRidesFragmentPagerAdapter.PAGE_GOING)
going = "1";
else
going = "0";
String neighborhoods = null;
String zone = null;
String hub = null;
String campus = null;
String filtersJsonString = SharedPref.getFiltersPref();
if (!filtersJsonString.equals(SharedPref.MISSING_PREF)) {
RideFiltersForJson rideFilters = new Gson().fromJson(filtersJsonString, RideFiltersForJson.class);
neighborhoods = rideFilters.getLocation();
if (!rideFilters.getCampus().equals("Todos os Campi")) {
hub = rideFilters.getCenter();
campus = rideFilters.getCampus();
}
zone = rideFilters.getZone();
}
CaronaeAPI.service(getContext()).listAllRides(pageNumber + "", going, neighborhoods, zone, hub, "", campus).enqueue(new retrofit2.Callback<RideForJsonDeserializer>() {
@Override
public void onResponse(Call<RideForJsonDeserializer> call, Response<RideForJsonDeserializer> response) {
totalBytesConsumed = totalBytesConsumed + TrafficStats.getUidRxBytes(Process.myUid()) - bytesSoFar;
Log.e("CONSUMPTION", "Bytes Consumed: " + totalBytesConsumed);
switch(pageIdentifier) {
case 0:
Log.e("CONSUMPTION", "Tamanho da lista " + goingRides.size());
break;
case 1:
Log.e("CONSUMPTION", "Tamanho da lista " + notGoingRides.size());
break;
}
if (response.isSuccessful()) {
if (pageCounter == FIRST_PAGE_TO_LOAD) {
goingRides = new ArrayList<>();
notGoingRides = new ArrayList<>();
}
RideForJsonDeserializer data = response.body();
List<RideForJson> rideOffers = data.getData();
if (rideOffers != null && !rideOffers.isEmpty()) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
Date todayDate = new Date();
String todayString = simpleDateFormat.format(todayDate);
simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.US);
String time = simpleDateFormat.format(todayDate);
Iterator<RideForJson> it = rideOffers.iterator();
while (it.hasNext()) {
RideForJson rideOffer = it.next();
if (Util.formatBadDateWithYear(rideOffer.getDate()).equals(todayString) && Util.formatTime(rideOffer.getTime()).compareTo(time) < 0)
it.remove();
else {
rideOffer.setDbId(rideOffer.getId().intValue());
if (rideOffer.isGoing()) {
if (!checkIfRideIsInList(goingRides, rideOffer)) {
goingRides.add(rideOffer);
}
} else {
if (!checkIfRideIsInList(notGoingRides, rideOffer)) {
notGoingRides.add(rideOffer);
}
}
}
}
Collections.sort(goingRides, new RideOfferComparatorByDateAndTime());
Collections.sort(notGoingRides, new RideOfferComparatorByDateAndTime());
}
if (pageIdentifier == AllRidesFragmentPagerAdapter.PAGE_GOING) {
if (goingRides == null || goingRides.isEmpty()) {
} else {
adapter.makeList(goingRides);
scrollListener.resetState();
}
} else {
if (notGoingRides == null || notGoingRides.isEmpty()) {
} else {
adapter.makeList(notGoingRides);
scrollListener.resetState();
}
}
refreshLayout.setRefreshing(false);
} else {
Util.treatResponseFromServer(response);
Util.toast(R.string.frag_allrides_errorGetRides);
refreshLayout.setRefreshing(false);
Log.e("listAllRides", response.message());
}
scrollListener.resetState();
}
@Override
public void onFailure(Call<RideForJsonDeserializer> call, Throwable t) {
refreshLayout.setRefreshing(false);
Log.e("listAllRides", t.getMessage());
scrollListener.resetState();
}
});
if (filter != null) {
switch(pageNumber) {
case 0:
if (filteredGoingList.size() <= 8) {
loadOneMorePage();
}
if (filteredNotGoingList.size() <= 8) {
loadOneMorePage();
}
break;
case 1:
if (filteredGoingList.size() <= 8) {
loadOneMorePage();
}
if (filteredNotGoingList.size() <= 8) {
loadOneMorePage();
}
break;
}
}
}
use of br.ufrj.caronae.models.modelsforjson.RideForJson in project caronae-android by caronae.
the class AllRidesListFrag method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_all_rides_list, container, false);
ButterKnife.bind(this, view);
Bundle bundle = getArguments();
ArrayList<RideForJson> rideOffers = bundle.getParcelableArrayList("rides");
pageIdentifier = bundle.getInt("ID");
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
pageCounter = FIRST_PAGE_TO_LOAD;
for (int counter = FIRST_PAGE_TO_LOAD; counter <= pageCounter; counter++) {
refreshRideList(counter);
}
}
});
adapter = new RideOfferAdapter(new ArrayList<RideForJson>(), getContext(), getActivity().getFragmentManager());
mLayoutManager = new LinearLayoutManager(getContext());
rvRides.setLayoutManager(mLayoutManager);
scrollListener = new EndlessRecyclerViewScrollListener(mLayoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
loadOneMorePage();
}
};
rvRides.addOnScrollListener(scrollListener);
rvRides.setAdapter(adapter);
if (!(rideOffers == null || rideOffers.isEmpty())) {
adapter.makeList(rideOffers);
}
App.getBus().register(this);
// After setting layout manager, adapter, etc...
float offsetBottonPx = getResources().getDimension(R.dimen.recycler_view_botton_offset);
float offsetTopPx = getResources().getDimension(R.dimen.recycler_view_top_offset);
Util.OffsetDecoration OffsetDecoration = new Util.OffsetDecoration((int) offsetBottonPx, (int) offsetTopPx);
rvRides.addItemDecoration(OffsetDecoration);
animateListFadeIn();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(App.getInst());
sharedPreferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(SharedPref.RIDE_FILTER_PREF_KEY)) {
pageCounter = FIRST_PAGE_TO_LOAD;
refreshRideList(pageCounter);
}
}
});
return view;
}
use of br.ufrj.caronae.models.modelsforjson.RideForJson in project caronae-android by caronae.
the class AllRidesListFrag method updateAdapter.
@Subscribe
public void updateAdapter(ArrayList<Object> listFiltered) {
filteredGoingList.clear();
filteredNotGoingList.clear();
for (int rides = 1; rides < listFiltered.size(); rides++) {
RideForJson ride = (RideForJson) listFiltered.get(rides);
if (ride.isGoing()) {
filteredGoingList.add((RideForJson) listFiltered.get(rides));
} else {
filteredNotGoingList.add((RideForJson) listFiltered.get(rides));
}
}
if (pageIdentifier == AllRidesFragmentPagerAdapter.PAGE_GOING) {
if (filteredGoingList.size() == 0) {
filter = null;
adapter.makeList(goingRides);
Util.toast("Nenhuma carona encontrada para esta busca");
} else {
filter = (CharSequence) listFiltered.get(0);
adapter.makeList(filteredGoingList);
}
} else {
if (filteredNotGoingList.size() == 0) {
filter = null;
adapter.makeList(notGoingRides);
Util.toast("Nenhuma carona encontrada para esta busca");
} else {
filter = (CharSequence) listFiltered.get(0);
adapter.makeList(filteredNotGoingList);
}
}
}
Aggregations