use of im.actor.core.entity.FileReference in project actor-platform by actorapp.
the class UploadTask method checkQueue.
private void checkQueue() {
if (isCompleted) {
return;
}
if (nextBlock == blocksCount && uploadCount == 0) {
if (LOG) {
Log.d(TAG, "Completing...");
}
long crc = crc32.getValue();
if (LOG) {
Log.d(TAG, "Src #" + crc);
Log.d(TAG, "Closing files...");
}
inputFile.close();
if (isWriteToDestProvider) {
outputFile.close();
}
request(new RequestCommitFileUpload(uploadConfig, fileName), new RpcCallback<ResponseCommitFileUpload>() {
@Override
public void onResult(ResponseCommitFileUpload response) {
if (LOG) {
Log.d(TAG, "Upload completed...");
}
FileReference location = new FileReference(response.getUploadedFileLocation(), fileName, srcReference.getSize());
if (isWriteToDestProvider || alreadyInTemp) {
FileSystemReference reference = Storage.commitTempFile(alreadyInTemp ? srcReference : destReference, location.getFileId(), location.getFileName());
reportComplete(location, reference);
} else {
reportComplete(location, srcReference);
}
}
@Override
public void onError(RpcException e) {
if (LOG) {
Log.w(TAG, "Upload complete error");
}
reportError();
}
});
return;
}
if (nextBlock < blocksCount && uploadCount < SIM_BLOCKS_COUNT) {
loadPart(nextBlock++);
}
}
use of im.actor.core.entity.FileReference 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.entity.FileReference 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.entity.FileReference in project actor-platform by actorapp.
the class StickerHolder method bindData.
@Override
protected void bindData(Message message, long readDate, long receiveDate, boolean isNewMessage, PreprocessedData preprocessedData) {
StickerContent content = (StickerContent) message.getContent();
ImageLocation image512 = content.getImage512();
if (image512 == null) {
return;
}
FileReference fileReference = image512.getReference();
sticker.bind(fileReference, StickerView.STICKER_FULL);
int w = image512.getWidth();
int h = image512.getHeight();
int maxHeight = context.getResources().getDisplayMetrics().heightPixels - Screen.dp(96 + 32);
maxHeight = Math.min(Screen.dp(200), maxHeight);
int maxWidth = context.getResources().getDisplayMetrics().widthPixels - Screen.dp(32 + 48);
maxWidth = Math.min(Screen.dp(200), maxWidth);
float scale = Math.min(maxWidth / (float) w, maxHeight / (float) h);
int bubbleW = (int) (scale * w);
int bubbleH = (int) (scale * h);
ViewGroup.LayoutParams params = sticker.getLayoutParams();
params.height = bubbleH;
params.width = bubbleW;
// Update state
if (message.getSenderId() == myUid()) {
stateIcon.setVisibility(View.VISIBLE);
switch(message.getMessageState()) {
case SENT:
if (message.getSortDate() <= readDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(COLOR_READ);
} else if (message.getSortDate() <= receiveDate) {
stateIcon.setResource(R.drawable.msg_check_2);
stateIcon.setTint(COLOR_RECEIVED);
} else {
stateIcon.setResource(R.drawable.msg_check_1);
stateIcon.setTint(COLOR_SENT);
}
break;
default:
case PENDING:
stateIcon.setResource(R.drawable.msg_clock);
stateIcon.setTint(COLOR_PENDING);
break;
case ERROR:
stateIcon.setResource(R.drawable.msg_error);
stateIcon.setTint(COLOR_ERROR);
break;
}
} else {
stateIcon.setVisibility(View.GONE);
}
// Update time
time.setText(DateFormatting.formatTime(message.getDate()));
}
use of im.actor.core.entity.FileReference in project actor-platform by actorapp.
the class GroupAvatarChangeActor method uploadCompleted.
public void uploadCompleted(final long rid, FileReference fileReference) {
if (!tasksMap.containsKey(rid)) {
return;
}
final int gid = tasksMap.get(rid);
long accessHash = getGroup(gid).getAccessHash();
if (currentTasks.get(gid) != rid) {
return;
}
api(new RequestEditGroupAvatar(new ApiGroupOutPeer(gid, accessHash), rid, new ApiFileLocation(fileReference.getFileId(), fileReference.getAccessHash()), ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseEditGroupAvatar -> updates().applyUpdate(responseEditGroupAvatar.getSeq(), responseEditGroupAvatar.getState(), new UpdateGroupAvatarChanged(gid, responseEditGroupAvatar.getAvatar()))).then(v -> avatarChanged(gid, rid)).failure(e -> {
if (!tasksMap.containsKey(rid)) {
return;
}
final int gid2 = tasksMap.get(rid);
if (currentTasks.get(gid2) != rid) {
return;
}
currentTasks.remove(gid2);
tasksMap.remove(rid);
context().getGroupsModule().getAvatarVM(gid2).getUploadState().change(new AvatarUploadState(null, false));
});
}
Aggregations