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