use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class ComplaintsHomeFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_complaints_home, container, false);
RecyclerView recyclerViewHome = view.findViewById(R.id.recyclerViewHome);
homeListAdapter = new ComplaintsAdapter(getActivity(), uID, uProfileUrl);
swipeContainer = view.findViewById(R.id.swipeContainer);
error_message_home = view.findViewById(R.id.error_message_home);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
recyclerViewHome.setLayoutManager(llm);
recyclerViewHome.setHasFixedSize(true);
recyclerViewHome.setAdapter(homeListAdapter);
recyclerViewHome.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (networkBusy || currentIndex == -1)
return;
if (!recyclerView.canScrollVertically(1)) {
networkBusy = true;
swipeContainer.setRefreshing(true);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getAllComplaints(Utils.getSessionIDHeader(), currentIndex, 5).enqueue(new Callback<List<Venter.Complaint>>() {
@Override
public void onResponse(Call<List<Venter.Complaint>> call, Response<List<Venter.Complaint>> response) {
if (response.isSuccessful()) {
if (response.body() != null && !response.body().isEmpty()) {
complaints.addAll(response.body());
initialiseRecyclerView(complaints);
currentIndex += 5;
} else {
currentIndex = -1;
}
}
networkBusy = false;
swipeContainer.setRefreshing(false);
}
@Override
public void onFailure(Call<List<Venter.Complaint>> call, Throwable t) {
networkBusy = false;
swipeContainer.setRefreshing(false);
}
});
}
}
});
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
callServerToGetNearbyComplaints();
}
});
swipeContainer.setColorSchemeResources(R.color.colorPrimary);
if (!isCalled) {
swipeContainer.post(new Runnable() {
@Override
public void run() {
swipeContainer.setRefreshing(true);
callServerToGetNearbyComplaints();
}
});
isCalled = true;
}
return view;
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class ComplaintsHomeFragment method callServerToGetNearbyComplaints.
private void callServerToGetNearbyComplaints() {
try {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getAllComplaints(Utils.getSessionIDHeader(), 0, 5).enqueue(new Callback<List<Venter.Complaint>>() {
@Override
public void onResponse(@NonNull Call<List<Venter.Complaint>> call, @NonNull Response<List<Venter.Complaint>> response) {
if (response.isSuccessful()) {
if (response.body() != null && !(response.body().isEmpty())) {
complaints = response.body();
currentIndex = complaints.size();
initialiseRecyclerView(complaints);
} else {
error_message_home.setVisibility(View.VISIBLE);
error_message_home.setText(getString(R.string.no_complaints));
}
}
swipeContainer.setRefreshing(false);
}
@Override
public void onFailure(@NonNull Call<List<Venter.Complaint>> call, @NonNull Throwable t) {
swipeContainer.setRefreshing(false);
error_message_home.setVisibility(View.VISIBLE);
}
});
} catch (Exception e) {
e.printStackTrace();
swipeContainer.setRefreshing(false);
}
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class BodyFragment method updateBody.
private void updateBody() {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getBody(Utils.getSessionIDHeader(), min_body.getBodyID()).enqueue(new Callback<Body>() {
@Override
public void onResponse(Call<Body> call, Response<Body> response) {
if (response.isSuccessful()) {
Body bodyResponse = response.body();
Utils.bodyCache.updateCache(response.body());
if (!bodyDisplayed) {
body = bodyResponse;
displayBody();
}
bodySwipeRefreshLayout.setRefreshing(false);
}
}
@Override
public void onFailure(Call<Body> call, Throwable t) {
bodySwipeRefreshLayout.setRefreshing(false);
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class CalendarFragment method updateEvents.
private void updateEvents(CalendarDay calendarDay, final boolean setToday) {
// Do not make duplicate calls
if (haveMonths.contains(calendarDay)) {
if (!setToday) {
return;
} else {
setupCalendar(true);
}
}
haveMonths.add(calendarDay);
// Parsers
String ISO_FORMAT = "yyyy-MM-dd HH:mm:ss";
final TimeZone utc = TimeZone.getTimeZone("UTC");
final SimpleDateFormat isoFormatter = new SimpleDateFormat(ISO_FORMAT);
isoFormatter.setTimeZone(utc);
// Get the start date
final Date startDate;
try {
startDate = toDate(calendarDay);
} catch (ParseException ignored) {
return;
}
// Get start and end times
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
cal.add(Calendar.MONTH, -1);
final Date oneMonthBackDate = cal.getTime();
cal.add(Calendar.MONTH, 2);
final Date oneMonthOnDate = cal.getTime();
final String oneMonthBack = isoFormatter.format(oneMonthBackDate).toString();
final String oneMonthOn = isoFormatter.format(oneMonthOnDate).toString();
// Make the API call
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getEventsBetweenDates(Utils.getSessionIDHeader(), oneMonthBack, oneMonthOn).enqueue(new Callback<NewsFeedResponse>() {
@Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) {
if (getActivity() == null || getView() == null)
return;
// Concatenate the response
NewsFeedResponse newsFeedResponse = response.body();
List<Event> eventList = newsFeedResponse.getEvents();
if (eventList == null)
return;
// Concatenate
for (Event event : eventList) {
if (!events.contains(event))
events.add(event);
}
setupCalendar(setToday);
}
}
@Override
public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
// Network Error
Toast.makeText(getActivity(), "Failed to fetch events!", Toast.LENGTH_SHORT).show();
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class MapFragment method getAPILocations.
private void getAPILocations() {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getAllVenues().enqueue(new Callback<List<Venue>>() {
@Override
public void onResponse(Call<List<Venue>> call, Response<List<Venue>> response) {
if (response.isSuccessful()) {
if (getActivity() == null || getView() == null || getContext() == null)
return;
// Show the map and data
venues = response.body();
setupWithData(venues);
}
}
@Override
public void onFailure(Call<List<Venue>> call, Throwable t) {
// Do nothing
}
});
}
Aggregations