Search in sources :

Example 1 with FileCallback

use of im.actor.core.viewmodel.FileCallback 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 FileCallback

use of im.actor.core.viewmodel.FileCallback 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 FileCallback

use of im.actor.core.viewmodel.FileCallback in project actor-platform by actorapp.

the class DownloadManager method startDownload.

public void startDownload(FileReference fileReference) {
    if (LOG) {
        Log.d(TAG, "Starting download #" + fileReference.getFileId());
    }
    Downloaded downloaded1 = downloaded.getValue(fileReference.getFileId());
    if (downloaded1 != null) {
        // Already downloaded
        return;
    }
    QueueItem queueItem = findItem(fileReference.getFileId());
    if (queueItem == null) {
        if (LOG) {
            Log.d(TAG, "- Adding to queue");
        }
        queueItem = new QueueItem(fileReference);
        queueItem.isStopped = false;
        queue.add(0, queueItem);
    } else {
        if (LOG) {
            Log.d(TAG, "- Promoting in queue");
        }
        if (queueItem.isStopped) {
            queueItem.isStopped = false;
            for (final FileCallback callback : getSubscribers(fileReference.getFileId())) {
                im.actor.runtime.Runtime.dispatch(() -> callback.onDownloading(0));
            }
        }
        promote(fileReference.getFileId());
    }
    checkQueue();
}
Also used : FileCallback(im.actor.core.viewmodel.FileCallback) Downloaded(im.actor.core.modules.file.entity.Downloaded)

Example 4 with FileCallback

use of im.actor.core.viewmodel.FileCallback in project actor-platform by actorapp.

the class DownloadManager method onDownloaded.

public void onDownloaded(final long fileId, final FileSystemReference reference) {
    if (LOG) {
        Log.d(TAG, "onDownloaded file #" + fileId);
    }
    QueueItem queueItem = findItem(fileId);
    if (queueItem == null) {
        return;
    }
    if (!queueItem.isStarted) {
        return;
    }
    downloaded.addOrUpdateItem(new Downloaded(queueItem.fileReference.getFileId(), queueItem.fileReference.getFileSize(), reference.getDescriptor()));
    queue.remove(queueItem);
    queueItem.taskRef.send(PoisonPill.INSTANCE);
    for (final WeakCallbackHolder weakReference : globalCallbacks) {
        final FileEventCallback callback = weakReference.getCallbackWeakReference().get();
        if (callback != null) {
            im.actor.runtime.Runtime.dispatch(() -> callback.onDownloaded(fileId));
        }
    }
    for (final FileCallback fileCallback : getSubscribers(fileId)) {
        im.actor.runtime.Runtime.dispatch(() -> fileCallback.onDownloaded(reference));
    }
    checkQueue();
}
Also used : FileCallback(im.actor.core.viewmodel.FileCallback) Downloaded(im.actor.core.modules.file.entity.Downloaded) FileEventCallback(im.actor.core.viewmodel.FileEventCallback)

Example 5 with FileCallback

use of im.actor.core.viewmodel.FileCallback in project actor-platform by actorapp.

the class DownloadManager method onDownloadProgress.

public void onDownloadProgress(long fileId, final float progress) {
    if (LOG) {
        Log.d(TAG, "onDownloadProgress file #" + fileId + " " + progress);
    }
    QueueItem queueItem = findItem(fileId);
    if (queueItem == null) {
        return;
    }
    if (!queueItem.isStarted) {
        return;
    }
    queueItem.progress = progress;
    for (final FileCallback fileCallback : getSubscribers(fileId)) {
        im.actor.runtime.Runtime.dispatch(() -> fileCallback.onDownloading(progress));
    }
}
Also used : FileCallback(im.actor.core.viewmodel.FileCallback)

Aggregations

FileCallback (im.actor.core.viewmodel.FileCallback)9 FileSystemReference (im.actor.runtime.files.FileSystemReference)3 FileReference (im.actor.core.entity.FileReference)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 Activity (android.app.Activity)1 Context (android.content.Context)1 Paint (android.graphics.Paint)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextPaint (android.text.TextPaint)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)1 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)1 AvatarImage (im.actor.core.entity.AvatarImage)1 AnimationContent (im.actor.core.entity.content.AnimationContent)1 DocumentContent (im.actor.core.entity.content.DocumentContent)1 VideoContent (im.actor.core.entity.content.VideoContent)1