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
}
});
}
}
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
}
});
}
}
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();
}
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();
}
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));
}
}
Aggregations