Search in sources :

Example 1 with FileVMCallback

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);
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 2 with FileVMCallback

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;
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 3 with FileVMCallback

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));
    }
}
Also used : Bitmap(android.graphics.Bitmap) FileSystemReference(im.actor.runtime.files.FileSystemReference) File(java.io.File) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 4 with FileVMCallback

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());
                }
            });
        }
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback) PipelineDraweeControllerBuilder(com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)

Example 5 with FileVMCallback

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);
                        }
                    });
                }
            }));
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) FastThumbLoader(im.actor.sdk.controllers.conversation.view.FastThumbLoader) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Aggregations

FileVMCallback (im.actor.core.viewmodel.FileVMCallback)6 FileSystemReference (im.actor.runtime.files.FileSystemReference)6 File (java.io.File)5 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)3 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)3 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 PipelineDraweeControllerBuilder (com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)1 Avatar (im.actor.core.entity.Avatar)1 Notification (im.actor.core.entity.Notification)1 BaseActivity (im.actor.sdk.controllers.activity.BaseActivity)1 FastThumbLoader (im.actor.sdk.controllers.conversation.view.FastThumbLoader)1 ImageLoadException (im.actor.sdk.util.images.common.ImageLoadException)1