Search in sources :

Example 1 with BoxAvatarView

use of com.box.androidsdk.content.views.BoxAvatarView in project box-android-sdk by box.

the class AuthenticatedAccountsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (getItemViewType(position) == CREATE_NEW_TYPE_ID) {
        return LayoutInflater.from(getContext()).inflate(R.layout.boxsdk_list_item_new_account, parent, false);
    }
    View rowView = LayoutInflater.from(getContext()).inflate(R.layout.boxsdk_list_item_account, parent, false);
    ViewHolder holder = (ViewHolder) rowView.getTag();
    if (holder == null) {
        holder = new ViewHolder();
        holder.titleView = (TextView) rowView.findViewById(R.id.box_account_title);
        holder.descriptionView = (TextView) rowView.findViewById(R.id.box_account_description);
        holder.initialsView = (BoxAvatarView) rowView.findViewById(R.id.box_account_initials);
        rowView.setTag(holder);
    }
    BoxAuthentication.BoxAuthenticationInfo info = getItem(position);
    if (info != null && info.getUser() != null) {
        boolean hasName = !SdkUtils.isEmptyString(info.getUser().getName());
        String title = hasName ? info.getUser().getName() : info.getUser().getLogin();
        holder.titleView.setText(title);
        if (hasName) {
            holder.descriptionView.setText(info.getUser().getLogin());
        }
        holder.initialsView.loadUser(info.getUser(), mAvatarController);
    } else {
        if (info != null) {
            BoxLogUtils.e("invalid account info", info.toJson());
        }
    }
    return rowView;
}
Also used : TextView(android.widget.TextView) BoxAvatarView(com.box.androidsdk.content.views.BoxAvatarView) View(android.view.View)

Example 2 with BoxAvatarView

use of com.box.androidsdk.content.views.BoxAvatarView in project box-android-sdk by box.

the class DefaultAvatarController method executeAvatarDownloadRequest.

@Override
public BoxFutureTask<BoxDownload> executeAvatarDownloadRequest(final String userId, BoxAvatarView avatarView) {
    final WeakReference<BoxAvatarView> avatarViewWeakReference = new WeakReference<BoxAvatarView>(avatarView);
    try {
        final File avatarFile = getAvatarFile(userId);
        if (mUnavailableAvatars.contains(avatarFile.getAbsolutePath())) {
            // no point trying if we tried before and it was unavailable.
            return null;
        }
        final BoxFutureTask<BoxDownload> avatarDownloadTask = getApiUser().getDownloadAvatarRequest(getAvatarDir(userId), userId).toTask();
        avatarDownloadTask.addOnCompletedListener(new BoxFutureTask.OnCompletedListener<BoxDownload>() {

            @Override
            public void onCompleted(BoxResponse<BoxDownload> response) {
                if (response.isSuccess()) {
                    BoxAvatarView avatarView = avatarViewWeakReference.get();
                    if (avatarView != null) {
                        avatarView.updateAvatar();
                    }
                } else {
                    if (response.getException() instanceof BoxException) {
                        if (((BoxException) response.getException()).getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
                            mUnavailableAvatars.add(getAvatarFile(userId).getAbsolutePath());
                        }
                    }
                    if (avatarFile != null) {
                        avatarFile.delete();
                    }
                }
            }
        });
        executeTask(avatarDownloadTask);
        return avatarDownloadTask;
    } catch (IOException e) {
        BoxLogUtils.e("unable to createFile ", e);
    }
    return null;
}
Also used : BoxException(com.box.androidsdk.content.BoxException) BoxAvatarView(com.box.androidsdk.content.views.BoxAvatarView) BoxDownload(com.box.androidsdk.content.models.BoxDownload) WeakReference(java.lang.ref.WeakReference) IOException(java.io.IOException) File(java.io.File) BoxRequestsFile(com.box.androidsdk.content.requests.BoxRequestsFile) BoxFutureTask(com.box.androidsdk.content.BoxFutureTask)

Aggregations

BoxAvatarView (com.box.androidsdk.content.views.BoxAvatarView)2 View (android.view.View)1 TextView (android.widget.TextView)1 BoxException (com.box.androidsdk.content.BoxException)1 BoxFutureTask (com.box.androidsdk.content.BoxFutureTask)1 BoxDownload (com.box.androidsdk.content.models.BoxDownload)1 BoxRequestsFile (com.box.androidsdk.content.requests.BoxRequestsFile)1 File (java.io.File)1 IOException (java.io.IOException)1 WeakReference (java.lang.ref.WeakReference)1