use of app.insti.UpdatableList in project IITB-App by wncc.
the class MainActivity method fetchNotifications.
/**
* Get the notifications from memory cache or network
*/
private void fetchNotifications() {
// Try memory cache
if (Utils.notificationCache != null) {
showNotifications();
return;
}
// Get from network
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getNotifications(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<List<Notification>>() {
@Override
public void onResponse(Call<List<Notification>> call, Response<List<Notification>> response) {
if (response.isSuccessful()) {
Utils.notificationCache = new UpdatableList<>();
Utils.notificationCache.setList(response.body());
showNotifications();
NotificationId.setCurrentCount(Utils.notificationCache.size());
ShortcutBadger.applyCount(getApplicationContext(), NotificationId.getCurrentCount());
}
}
});
}
use of app.insti.UpdatableList in project IITB-App by wncc.
the class NotificationsFragment method onStart.
@Override
public void onStart() {
super.onStart();
/* Show cached notifications */
if (Utils.notificationCache != null) {
showNotifications(Utils.notificationCache);
} else {
Utils.notificationCache = new UpdatableList<>();
}
/* Update notifications */
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getNotifications(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<List<Notification>>() {
@Override
public void onResponse(Call<List<Notification>> call, Response<List<Notification>> response) {
if (response.isSuccessful()) {
Utils.notificationCache.setList(response.body());
showNotifications(Utils.notificationCache);
NotificationId.setCurrentCount(Utils.notificationCache.size());
ShortcutBadger.applyCount(getContext(), NotificationId.getCurrentCount());
}
}
});
}
Aggregations