Search in sources :

Example 1 with FileReference

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++);
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) RequestCommitFileUpload(im.actor.core.api.rpc.RequestCommitFileUpload) RpcException(im.actor.core.network.RpcException) FileReference(im.actor.core.entity.FileReference) ResponseCommitFileUpload(im.actor.core.api.rpc.ResponseCommitFileUpload)

Example 2 with FileReference

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
            }
        });
    }
}
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 3 with FileReference

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
            }
        });
    }
}
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 4 with FileReference

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()));
}
Also used : StickerContent(im.actor.core.entity.content.StickerContent) ViewGroup(android.view.ViewGroup) FileReference(im.actor.core.entity.FileReference) ImageLocation(im.actor.core.entity.ImageLocation)

Example 5 with FileReference

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));
    });
}
Also used : ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ResponseEditGroupAvatar(im.actor.core.api.rpc.ResponseEditGroupAvatar) ModuleContext(im.actor.core.modules.ModuleContext) ResponseSeqDate(im.actor.core.api.rpc.ResponseSeqDate) ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter) Void(im.actor.runtime.actors.messages.Void) RequestEditGroupAvatar(im.actor.core.api.rpc.RequestEditGroupAvatar) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) RandomUtils(im.actor.core.util.RandomUtils) HashMap(java.util.HashMap) Group(im.actor.core.entity.Group) RpcException(im.actor.core.network.RpcException) RequestRemoveGroupAvatar(im.actor.core.api.rpc.RequestRemoveGroupAvatar) ModuleActor(im.actor.core.modules.ModuleActor) Consumer(im.actor.runtime.function.Consumer) FileReference(im.actor.core.entity.FileReference) ApiFileLocation(im.actor.core.api.ApiFileLocation) UpdateGroupAvatarChangedObsolete(im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete) RpcCallback(im.actor.core.network.RpcCallback) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) UploadManager(im.actor.core.modules.file.UploadManager) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) SeqUpdate(im.actor.core.api.base.SeqUpdate) RequestEditGroupAvatar(im.actor.core.api.rpc.RequestEditGroupAvatar) ApiFileLocation(im.actor.core.api.ApiFileLocation) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer)

Aggregations

FileReference (im.actor.core.entity.FileReference)5 FileSystemReference (im.actor.runtime.files.FileSystemReference)3 FileLocalSource (im.actor.core.entity.content.FileLocalSource)2 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)2 PhotoContent (im.actor.core.entity.content.PhotoContent)2 RpcException (im.actor.core.network.RpcException)2 FileCallback (im.actor.core.viewmodel.FileCallback)2 UploadFileCallback (im.actor.core.viewmodel.UploadFileCallback)2 Activity (android.app.Activity)1 ViewGroup (android.view.ViewGroup)1 ApiFileLocation (im.actor.core.api.ApiFileLocation)1 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)1 SeqUpdate (im.actor.core.api.base.SeqUpdate)1 RequestCommitFileUpload (im.actor.core.api.rpc.RequestCommitFileUpload)1 RequestEditGroupAvatar (im.actor.core.api.rpc.RequestEditGroupAvatar)1 RequestRemoveGroupAvatar (im.actor.core.api.rpc.RequestRemoveGroupAvatar)1 ResponseCommitFileUpload (im.actor.core.api.rpc.ResponseCommitFileUpload)1 ResponseEditGroupAvatar (im.actor.core.api.rpc.ResponseEditGroupAvatar)1 ResponseSeqDate (im.actor.core.api.rpc.ResponseSeqDate)1 UpdateGroupAvatarChanged (im.actor.core.api.updates.UpdateGroupAvatarChanged)1