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;
}
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;
}
Aggregations