use of im.actor.core.viewmodel.FileVMCallback in project actor-platform by actorapp.
the class AvatarView method bind.
public void bind(Avatar avatar, String title, int id) {
// Same avatar
if (avatar != null && getImage(avatar) != null && getImage(avatar).getFileReference().getFileId() == currentId) {
return;
}
getHierarchy().setPlaceholderImage(new AvatarPlaceholderDrawable(title, id, placeholderTextSize, getContext()));
if (bindedFile != null) {
bindedFile.detach();
bindedFile = null;
}
setImageURI(null);
if (avatar == null || getImage(avatar) == null) {
currentId = 0;
return;
}
currentId = getImage(avatar).getFileReference().getFileId();
bindedFile = messenger().bindFile(getImage(avatar).getFileReference(), true, new FileVMCallback() {
@Override
public void onNotDownloaded() {
}
@Override
public void onDownloading(float progress) {
}
@Override
public void onDownloaded(FileSystemReference reference) {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(reference.getDescriptor()))).setResizeOptions(new ResizeOptions(size, size)).build();
PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
setController(controller);
}
});
}
use of im.actor.core.viewmodel.FileVMCallback in project actor-platform by actorapp.
the class StickerView method bind.
public void bind(FileReference fileReference, int size) {
if (this.fileReference != null && this.fileReference.equals(fileReference)) {
return;
}
if (bindedFile != null) {
bindedFile.detach();
bindedFile = null;
}
setImageURI(null);
this.fileReference = fileReference;
bindedFile = messenger().bindFile(fileReference, true, new FileVMCallback() {
private boolean isFastThumbLoaded = false;
private void checkFastThumb() {
if (!isFastThumbLoaded) {
isFastThumbLoaded = true;
// if (sticker.getThumb() != null) {
// fastThumbLoader.request(sticker.getThumb());
// }
}
}
@Override
public void onNotDownloaded() {
checkFastThumb();
}
@Override
public void onDownloading(float progress) {
checkFastThumb();
}
@Override
public void onDownloaded(FileSystemReference reference) {
imageFile = new File(reference.getDescriptor());
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(imageFile)).setAutoRotateEnabled(true).build();
PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
setController(controller);
loaded = true;
}
});
}
use of im.actor.core.viewmodel.FileVMCallback in project actor-platform by actorapp.
the class ViewAvatarActivity method performBind.
private void performBind(Avatar avatar, AvatarUploadState uploadState) {
unbind();
if (uploadState != null && uploadState.isUploading()) {
if (uploadState.getDescriptor() != null) {
photoView.setImageURI(Uri.fromFile(new File(uploadState.getDescriptor())));
} else {
photoView.setImageURI(null);
}
showView(progress);
goneView(noPhoto);
return;
}
if (avatar == null || avatar.getFullImage() == null) {
photoView.setImageBitmap(null);
showView(noPhoto);
goneView(progress);
} else {
goneView(noPhoto);
// Large image
String file = messenger().findDownloadedDescriptor(avatar.getFullImage().getFileReference().getFileId());
if (file != null) {
try {
Bitmap bitmap = ImageLoading.loadBitmapOptimized(file);
photoView.setImageBitmap(bitmap);
photoView.setZoomable(true);
goneView(progress);
return;
} catch (ImageLoadException e) {
e.printStackTrace();
}
}
// Full image not available: showing progress
showView(progress);
// Trying to show preview first
boolean isAppliedPreview = false;
String largeFile = messenger().findDownloadedDescriptor(avatar.getLargeImage().getFileReference().getFileId());
if (largeFile != null) {
try {
Bitmap bitmap = ImageLoading.loadBitmapOptimized(largeFile);
photoView.setImageBitmap(bitmap);
photoView.setZoomable(false);
isAppliedPreview = true;
} catch (ImageLoadException e) {
e.printStackTrace();
}
}
if (!isAppliedPreview) {
String smallFile = messenger().findDownloadedDescriptor(avatar.getSmallImage().getFileReference().getFileId());
if (smallFile != null) {
try {
Bitmap bitmap = ImageLoading.loadBitmapOptimized(smallFile);
photoView.setImageBitmap(bitmap);
photoView.setZoomable(false);
} catch (ImageLoadException e) {
e.printStackTrace();
}
}
}
bindedDownloadFile = messenger().bindFile(avatar.getFullImage().getFileReference(), true, new FileVMCallback() {
@Override
public void onNotDownloaded() {
}
@Override
public void onDownloading(float progressV) {
}
@Override
public void onDownloaded(FileSystemReference reference) {
try {
Bitmap bitmap = ImageLoading.loadBitmapOptimized(reference.getDescriptor());
photoView.setImageBitmap(bitmap);
photoView.setZoomable(true);
showView(photoView);
goneView(progress);
} catch (ImageLoadException e) {
e.printStackTrace();
}
}
});
// receiver.request(new FullAvatarTask(avatar));
}
}
use of im.actor.core.viewmodel.FileVMCallback in project actor-platform by actorapp.
the class CoverAvatarView method bind.
public void bind(final Avatar avatar) {
// Same avatar
if (avatar != null && avatar.getSmallImage() != null && avatar.getSmallImage().getFileReference().getFileId() == currentId) {
return;
}
if (fileVM != null) {
fileVM.detach();
fileVM = null;
}
if (fullFileVM != null) {
fullFileVM.detach();
fullFileVM = null;
}
isLoaded = false;
smallDescriptor = null;
if (tryToSetFast(avatar)) {
return;
}
if (avatar != null && avatar.getSmallImage() != null) {
currentId = avatar.getSmallImage().getFileReference().getFileId();
fileVM = messenger().bindFile(avatar.getSmallImage().getFileReference(), true, new FileVMCallback() {
@Override
public void onNotDownloaded() {
}
@Override
public void onDownloading(float progress) {
}
@Override
public void onDownloaded(FileSystemReference reference) {
if (!isLoaded) {
smallDescriptor = reference.getDescriptor();
setImageURI(Uri.fromFile(new File(smallDescriptor)));
}
}
});
if (avatar.getFullImage() != null) {
fullFileVM = messenger().bindFile(avatar.getFullImage().getFileReference(), true, new FileVMCallback() {
@Override
public void onNotDownloaded() {
}
@Override
public void onDownloading(float progress) {
}
@Override
public void onDownloaded(FileSystemReference reference) {
isLoaded = true;
PipelineDraweeControllerBuilder dController = Fresco.newDraweeControllerBuilder();
if (smallDescriptor != null) {
dController.setLowResImageRequest(ImageRequest.fromUri(Uri.fromFile(new File(smallDescriptor))));
}
dController.setOldController(getController());
dController.setImageRequest(ImageRequest.fromUri(Uri.fromFile(new File(reference.getDescriptor()))));
setController(dController.build());
}
});
}
}
}
use of im.actor.core.viewmodel.FileVMCallback in project actor-platform by actorapp.
the class CallBackgroundAvatarView method bind.
public void bind(Avatar avatar) {
// Same avatar
if (avatar != null && getImage(avatar) != null && getImage(avatar).getFileReference().getFileId() == currentId) {
return;
}
fastThumbLoader = new FastThumbLoader(this);
fastThumbLoader.setBlur(10);
if (bindedFile != null) {
bindedFile.detach();
bindedFile = null;
}
setImageURI(null);
if (avatar == null || getImage(avatar) == null) {
currentId = 0;
return;
}
currentId = getImage(avatar).getFileReference().getFileId();
bindedFile = messenger().bindFile(getImage(avatar).getFileReference(), true, new FileVMCallback() {
@Override
public void onNotDownloaded() {
}
@Override
public void onDownloading(float progress) {
}
@Override
public void onDownloaded(FileSystemReference reference) {
blurActor.send(new BlurActor.RequestBlur(reference.getDescriptor(), 10, new BlurActor.BluredListener() {
@Override
public void onBlured(final File f) {
((BaseActivity) getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(f)).setResizeOptions(new ResizeOptions(Screen.getWidth(), Screen.getHeight())).build();
PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
setController(controller);
}
});
}
}));
}
});
}
Aggregations