Search in sources :

Example 1 with BoxCollaborator

use of com.box.androidsdk.content.models.BoxCollaborator in project box-android-sdk by box.

the class BoxAvatarView method updateAvatar.

protected void updateAvatar() {
    if (mUser == null || mAvatarController == null) {
        return;
    }
    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
        post(new Runnable() {

            @Override
            public void run() {
                updateAvatar();
            }
        });
        return;
    }
    final File avatarFile = mAvatarController.getAvatarFile(mUser.getId());
    if (avatarFile.exists()) {
        // load avatar file into view.
        mAvatar.setImageDrawable(Drawable.createFromPath(avatarFile.getAbsolutePath()));
        mAvatar.setVisibility(View.VISIBLE);
        mInitials.setVisibility(View.GONE);
    } else {
        String name = DEFAULT_NAME;
        if (mUser instanceof BoxCollaborator) {
            name = mUser.getName();
        } else if (SdkUtils.isBlank(name) && mUser instanceof BoxUser) {
            name = ((BoxUser) mUser).getLogin();
        }
        int numberOfCollab = 0;
        try {
            numberOfCollab = Integer.parseInt(name);
        } catch (NumberFormatException ex) {
        // do nothing
        }
        if (numberOfCollab == 0) {
            SdkUtils.setInitialsThumb(getContext(), mInitials, name);
        } else {
            SdkUtils.setCollabNumberThumb(getContext(), mInitials, numberOfCollab);
        }
        mAvatar.setVisibility(View.GONE);
        mInitials.setVisibility(View.VISIBLE);
        mAvatarDownloadTaskRef = new WeakReference<BoxFutureTask<BoxDownload>>(mAvatarController.executeAvatarDownloadRequest(mUser.getId(), this));
    }
}
Also used : File(java.io.File) BoxCollaborator(com.box.androidsdk.content.models.BoxCollaborator) BoxFutureTask(com.box.androidsdk.content.BoxFutureTask) BoxUser(com.box.androidsdk.content.models.BoxUser)

Aggregations

BoxFutureTask (com.box.androidsdk.content.BoxFutureTask)1 BoxCollaborator (com.box.androidsdk.content.models.BoxCollaborator)1 BoxUser (com.box.androidsdk.content.models.BoxUser)1 File (java.io.File)1