Search in sources :

Example 1 with CanvasColor

use of com.instructure.canvasapi.model.CanvasColor in project instructure-android by instructure.

the class HomeActivity method setupCallbacks.

private void setupCallbacks() {
    avatarTarget = new Target() {

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
            avatar.setImageBitmap(bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable drawable) {
            avatar.setImageResource(R.drawable.ic_cv_student);
        }

        @Override
        public void onPrepareLoad(Drawable drawable) {
        }
    };
    userCallback = new UserCallback(this) {

        @Override
        public void cachedUser(User user) {
            if (user != null && user.getAvatarURL() != null) {
                Picasso.with(getContext()).load(user.getAvatarURL()).into(avatarTarget);
                userName.setText(user.getName());
            }
        }

        @Override
        public void user(User user, Response response) {
            Picasso.with(getContext()).load(user.getAvatarURL()).into(avatarTarget);
            userName.setText(user.getName());
        }
    };
    courseColorsCallback = new CanvasCallback<CanvasColor>(this) {

        @Override
        public void cache(CanvasColor canvasColor) {
        }

        @Override
        public void firstPage(CanvasColor canvasColor, LinkHeaders linkHeaders, Response response) {
            if (response.getStatus() == 200) {
                // Replaces the current cache with the updated fresh one from the api.
                CanvasContextColor.addToCache(canvasColor);
                // Sends a broadcast so the course grid can refresh it's colors if needed.
                // When first logging in this will probably get called/return after the courses.
                Intent intent = new Intent(com.instructure.pandautils.utils.Const.COURSE_THING_CHANGED);
                Bundle extras = new Bundle();
                extras.putBoolean(com.instructure.pandautils.utils.Const.COURSE_COLOR, true);
                intent.putExtras(extras);
                LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
            }
        }
    };
}
Also used : User(com.instructure.canvasapi.model.User) LinkHeaders(com.instructure.canvasapi.utilities.LinkHeaders) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) Response(retrofit.client.Response) UserCallback(com.instructure.canvasapi.utilities.UserCallback) Target(com.squareup.picasso.Target) Bitmap(android.graphics.Bitmap) CanvasColor(com.instructure.canvasapi.model.CanvasColor) Picasso(com.squareup.picasso.Picasso)

Aggregations

Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 CanvasColor (com.instructure.canvasapi.model.CanvasColor)1 User (com.instructure.canvasapi.model.User)1 LinkHeaders (com.instructure.canvasapi.utilities.LinkHeaders)1 UserCallback (com.instructure.canvasapi.utilities.UserCallback)1 Picasso (com.squareup.picasso.Picasso)1 Target (com.squareup.picasso.Target)1 Response (retrofit.client.Response)1