use of app.insti.api.response.NewsFeedResponse 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.response.NewsFeedResponse in project IITB-App by wncc.
the class FeedFragment method updateFeed.
private void updateFeed() {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getNewsFeed(Utils.getSessionIDHeader()).enqueue(new Callback<NewsFeedResponse>() {
@Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) {
Utils.eventCache.setList(response.body().getEvents());
displayEvents(Utils.eventCache);
}
// Server Error
feedSwipeRefreshLayout.setRefreshing(false);
}
@Override
public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
// Network Error
feedSwipeRefreshLayout.setRefreshing(false);
}
});
}
Aggregations