Search in sources :

Example 1 with UpdatableList

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());
            }
        }
    });
}
Also used : UpdatableList(app.insti.UpdatableList) List(java.util.List) UpdatableList(app.insti.UpdatableList) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 2 with UpdatableList

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());
            }
        }
    });
}
Also used : UpdatableList(app.insti.UpdatableList) List(java.util.List) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

UpdatableList (app.insti.UpdatableList)2 RetrofitInterface (app.insti.api.RetrofitInterface)2 List (java.util.List)2