Search in sources :

Example 1 with UploadFileCallback

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

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

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

the class UploadManager method resumeUpload.

public void resumeUpload(long rid) {
    QueueItem queueItem = findItem(rid);
    if (queueItem != null) {
        if (queueItem.isStarted) {
            return;
        }
        if (queueItem.isStopped) {
            queueItem.isStopped = false;
        }
        queueItem.progress = 0;
        ArrayList<UploadFileCallback> clist = callbacks.get(rid);
        if (clist != null) {
            for (final UploadFileCallback callback : clist) {
                im.actor.runtime.Runtime.dispatch(() -> callback.onUploading(0));
            }
        }
        checkQueue();
    }
}
Also used : UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback)

Example 4 with UploadFileCallback

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

the class UploadManager method pauseUpload.

public void pauseUpload(long rid) {
    QueueItem queueItem = findItem(rid);
    if (queueItem != null) {
        if (queueItem.isStarted) {
            queueItem.taskRef.send(PoisonPill.INSTANCE);
            queueItem.taskRef = null;
            queueItem.isStarted = false;
        }
        queueItem.isStopped = true;
        ArrayList<UploadFileCallback> clist = callbacks.get(rid);
        if (clist != null) {
            for (final UploadFileCallback callback : clist) {
                im.actor.runtime.Runtime.dispatch(() -> callback.onNotUploading());
            }
        }
    }
}
Also used : UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback)

Example 5 with UploadFileCallback

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

the class UploadManager method stopUpload.

public void stopUpload(long rid) {
    if (LOG) {
        Log.d(TAG, "Stopping upload #" + rid);
    }
    QueueItem queueItem = findItem(rid);
    if (queueItem == null) {
        if (LOG) {
            Log.d(TAG, "- Not present in queue");
        }
    } else {
        if (queueItem.isStarted) {
            if (LOG) {
                Log.d(TAG, "- Stopping actor");
            }
            queueItem.taskRef.send(PoisonPill.INSTANCE);
            queueItem.taskRef = null;
            queueItem.isStarted = false;
        }
        queue.remove(queueItem);
        ArrayList<UploadFileCallback> clist = callbacks.get(queueItem.rid);
        if (clist != null) {
            for (final UploadFileCallback callback : clist) {
                im.actor.runtime.Runtime.dispatch(() -> callback.onNotUploading());
            }
        }
    }
    checkQueue();
}
Also used : UploadFileCallback(im.actor.core.viewmodel.UploadFileCallback)

Aggregations

UploadFileCallback (im.actor.core.viewmodel.UploadFileCallback)8 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 FileCallback (im.actor.core.viewmodel.FileCallback)2 FileSystemReference (im.actor.runtime.files.FileSystemReference)2 Activity (android.app.Activity)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 Downloaded (im.actor.core.modules.file.entity.Downloaded)1 ImageLoadException (im.actor.sdk.util.images.common.ImageLoadException)1