use of com.box.androidsdk.content.models.BoxDownload 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