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