Search in sources :

Example 1 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference in project actor-platform by actorapp.

the class DocHolder method onClick.

@Override
public void onClick(final Message currentMessage) {
    if (document.getSource() instanceof FileRemoteSource) {
        FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
        final FileReference location = remoteSource.getFileReference();
        messenger().requestState(location.getFileId(), new FileCallback() {

            @Override
            public void onNotDownloaded() {
                messenger().startDownloading(location);
            }

            @Override
            public void onDownloading(float progress) {
                messenger().cancelDownloading(location.getFileId());
            }

            @Override
            public void onDownloaded(final FileSystemReference reference) {
                im.actor.runtime.Runtime.postToMainThread(new Runnable() {

                    @Override
                    public void run() {
                        if (document instanceof PhotoContent) {
                            Intents.openMedia(getAdapter().getMessagesFragment().getActivity(), fileIcon, reference.getDescriptor(), currentMessage.getSenderId());
                        } else {
                            try {
                                Activity activity = getAdapter().getMessagesFragment().getActivity();
                                activity.startActivity(Intents.openDoc(document.getName(), reference.getDescriptor()));
                            } catch (Exception e) {
                                Toast.makeText(getAdapter().getMessagesFragment().getActivity(), R.string.toast_unable_open, Toast.LENGTH_LONG).show();
                                e.printStackTrace();
                            }
                        }
                    }
                });
            }
        });
    } else if (document.getSource() instanceof FileLocalSource) {
        messenger().requestUploadState(currentMessage.getRid(), new UploadFileCallback() {

            @Override
            public void onNotUploading() {
                messenger().resumeUpload(currentMessage.getRid());
            }

            @Override
            public void onUploading(float progress) {
                messenger().pauseUpload(currentMessage.getRid());
            }

            @Override
            public void onUploaded() {
            // Nothing to do
            }
        });
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileCallback(im.actor.core.viewmodel.FileCallback) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) Activity(android.app.Activity) FileLocalSource(im.actor.core.entity.content.FileLocalSource) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileReference(im.actor.core.entity.FileReference) ImageLoadException(im.actor.sdk.util.images.common.ImageLoadException) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 2 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference in project actor-platform by actorapp.

the class PhotoHolder method onClick.

@Override
public void onClick(final Message currentMessage) {
    final DocumentContent document = (DocumentContent) currentMessage.getContent();
    if (document.getSource() instanceof FileRemoteSource) {
        FileRemoteSource remoteSource = (FileRemoteSource) document.getSource();
        final FileReference location = remoteSource.getFileReference();
        messenger().requestState(location.getFileId(), new FileCallback() {

            @Override
            public void onNotDownloaded() {
                messenger().startDownloading(location);
                playRequested = true;
            }

            @Override
            public void onDownloading(float progress) {
                messenger().cancelDownloading(location.getFileId());
            }

            @Override
            public void onDownloaded(final FileSystemReference reference) {
                im.actor.runtime.Runtime.postToMainThread(new Runnable() {

                    @Override
                    public void run() {
                        if (document instanceof PhotoContent) {
                            Intents.openMedia(getAdapter().getMessagesFragment().getActivity(), previewView, reference.getDescriptor(), currentMessage.getSenderId());
                        } else if (document instanceof VideoContent) {
                            playVideo(document, reference);
                        } else if (document instanceof AnimationContent) {
                            toggleAnimation();
                        }
                    }
                });
            }
        });
    } else if (document.getSource() instanceof FileLocalSource) {
        messenger().requestUploadState(currentMessage.getRid(), new UploadFileCallback() {

            @Override
            public void onNotUploading() {
                messenger().resumeUpload(currentMessage.getRid());
            }

            @Override
            public void onUploading(float progress) {
                messenger().pauseUpload(currentMessage.getRid());
            }

            @Override
            public void onUploaded() {
            // Nothing to do
            }
        });
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) VideoContent(im.actor.core.entity.content.VideoContent) AnimationContent(im.actor.core.entity.content.AnimationContent) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileCallback(im.actor.core.viewmodel.FileCallback) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) DocumentContent(im.actor.core.entity.content.DocumentContent) FileLocalSource(im.actor.core.entity.content.FileLocalSource) UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback) FileReference(im.actor.core.entity.FileReference) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 3 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference 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 4 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference 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 5 with FileSystemReference

use of im.actor.runtime.files.FileSystemReference in project actor-platform by actorapp.

the class DownloadManager method bindDownload.

public void bindDownload(final FileReference fileReference, boolean autoStart, final FileCallback callback) {
    if (LOG) {
        Log.d(TAG, "Binding file #" + fileReference.getFileId());
    }
    Downloaded downloaded1 = downloaded.getValue(fileReference.getFileId());
    if (downloaded1 != null) {
        FileSystemReference reference = Storage.fileFromDescriptor(downloaded1.getDescriptor());
        boolean isExist = reference.isExist();
        int fileSize = reference.getSize();
        if (isExist && fileSize == downloaded1.getFileSize()) {
            if (LOG) {
                Log.d(TAG, "- Downloaded");
            }
            final FileSystemReference fileSystemReference = Storage.fileFromDescriptor(downloaded1.getDescriptor());
            im.actor.runtime.Runtime.dispatch(() -> callback.onDownloaded(fileSystemReference));
            return;
        } else {
            if (LOG) {
                Log.d(TAG, "- File is corrupted");
                if (!isExist) {
                    Log.d(TAG, "- File not found");
                }
                if (fileSize != downloaded1.getFileSize()) {
                    Log.d(TAG, "- Incorrect file size. Expected: " + downloaded1.getFileSize() + ", got: " + fileSize);
                }
            }
            downloaded.removeItem(downloaded1.getFileId());
        }
    }
    QueueItem queueItem = findItem(fileReference.getFileId());
    if (queueItem == null) {
        if (LOG) {
            Log.d(TAG, "- Adding to queue");
        }
        queueItem = new QueueItem(fileReference);
        if (autoStart) {
            queueItem.isStopped = false;
            im.actor.runtime.Runtime.dispatch(() -> callback.onDownloading(0));
        } else {
            queueItem.isStopped = true;
            im.actor.runtime.Runtime.dispatch(() -> callback.onNotDownloaded());
        }
        queue.add(0, queueItem);
    } else {
        Log.d(TAG, "- Promoting in queue");
        promote(fileReference.getFileId());
        if (queueItem.isStopped) {
            im.actor.runtime.Runtime.dispatch(() -> callback.onNotDownloaded());
        } else {
            if (queueItem.isStarted) {
                final float progress = queueItem.progress;
                im.actor.runtime.Runtime.dispatch(() -> callback.onDownloading(progress));
            } else {
                im.actor.runtime.Runtime.dispatch(() -> callback.onDownloading(0));
            }
        }
    }
    getSubscribers(fileReference.getFileId()).add(callback);
    checkQueue();
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) Downloaded(im.actor.core.modules.file.entity.Downloaded)

Aggregations

FileSystemReference (im.actor.runtime.files.FileSystemReference)18 FileVMCallback (im.actor.core.viewmodel.FileVMCallback)6 File (java.io.File)6 SenderActor (im.actor.core.modules.messaging.actions.SenderActor)5 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)4 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)3 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)3 FileReference (im.actor.core.entity.FileReference)3 FileCallback (im.actor.core.viewmodel.FileCallback)3 SpannableStringBuilder (android.text.SpannableStringBuilder)2 FileLocalSource (im.actor.core.entity.content.FileLocalSource)2 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)2 PhotoContent (im.actor.core.entity.content.PhotoContent)2 Downloaded (im.actor.core.modules.file.entity.Downloaded)2 UploadFileCallback (im.actor.core.viewmodel.UploadFileCallback)2 ImageLoadException (im.actor.sdk.util.images.common.ImageLoadException)2 Activity (android.app.Activity)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1