Search in sources :

Example 1 with AnimationContent

use of im.actor.core.entity.content.AnimationContent in project actor-platform by actorapp.

the class PhotoHolder method bindData.

@Override
protected void bindData(Message message, long readDate, long receiveDate, boolean isNewMessage, PreprocessedData preprocessedData) {
    // Update model
    DocumentContent fileMessage = (DocumentContent) message.getContent();
    // Update bubble
    if (message.getSenderId() == myUid()) {
        messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_out);
    } else {
        messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_in);
    }
    // Update state
    if (message.getSenderId() == myUid()) {
        stateIcon.setVisibility(View.VISIBLE);
        switch(message.getMessageState()) {
            case ERROR:
                stateIcon.setResource(R.drawable.msg_error);
                stateIcon.setTint(COLOR_ERROR);
                break;
            default:
            case PENDING:
                stateIcon.setResource(R.drawable.msg_clock);
                stateIcon.setTint(COLOR_PENDING);
                break;
            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;
        }
    } else {
        stateIcon.setVisibility(View.GONE);
    }
    // Update time
    setTimeAndReactions(time);
    Log.d(TAG, "isNewMessage: " + isNewMessage);
    // Update size
    if (isNewMessage) {
        int w, h;
        if (message.getContent() instanceof PhotoContent) {
            w = ((PhotoContent) message.getContent()).getW();
            h = ((PhotoContent) message.getContent()).getH();
            isPhoto = true;
            isAnimation = false;
            duration.setVisibility(View.GONE);
        } else if (message.getContent() instanceof AnimationContent) {
            w = ((AnimationContent) message.getContent()).getW();
            h = ((AnimationContent) message.getContent()).getH();
            isPhoto = true;
            isAnimation = true;
            duration.setVisibility(View.VISIBLE);
            duration.setText("");
        } else if (message.getContent() instanceof VideoContent) {
            w = ((VideoContent) message.getContent()).getW();
            h = ((VideoContent) message.getContent()).getH();
            isPhoto = false;
            isAnimation = false;
            duration.setVisibility(View.VISIBLE);
            duration.setText(messenger().getFormatter().formatDuration(((VideoContent) message.getContent()).getDuration()));
        } else {
            throw new RuntimeException("Unsupported content");
        }
        int maxHeight = context.getResources().getDisplayMetrics().heightPixels - Screen.dp(96 + 32);
        maxHeight = Math.min(Screen.dp(360), maxHeight);
        int maxWidth = context.getResources().getDisplayMetrics().widthPixels - Screen.dp(32 + 48);
        maxWidth = Math.min(Screen.dp(360), maxWidth);
        float scale = Math.min(maxWidth / (float) w, maxHeight / (float) h);
        int bubbleW = (int) (scale * w);
        int bubbleH = (int) (scale * h);
        previewView.setLayoutParams(new FrameLayout.LayoutParams(bubbleW, bubbleH));
        overlay.setLayoutParams(new FrameLayout.LayoutParams(bubbleW, bubbleH));
    }
    // Update view
    boolean needRebind = false;
    if (isNewMessage) {
        // Resetting old content state
        // imageKitView.noRequest();
        fastThumbLoader.cancel();
        // Resetting binding
        if (downloadFileVM != null) {
            downloadFileVM.detach();
            downloadFileVM = null;
        }
        if (uploadFileVM != null) {
            uploadFileVM.detach();
            uploadFileVM = null;
        }
        needRebind = true;
    }
    Log.d(TAG, "needRebind by new: " + needRebind);
    updated = false;
    //        int updatedCounter = fileMessage.getUpdatedCounter();
    //        Log.d(TAG, "oldRid: " + currenrRid);
    //        Log.d(TAG, "newRid: " + currentMessage.getRid());
    //        Log.d(TAG, "oldCounter: " + lastUpdatedIndex);
    //        Log.d(TAG, "newCounter: " + updatedCounter);
    //        if (currenrRid == currentMessage.getRid() && lastUpdatedIndex != updatedCounter) {
    //            updated = true;
    //            needRebind = true;
    //            lastUpdatedIndex = updatedCounter;
    //        }
    currenrRid = currentMessage.getRid();
    Log.d(TAG, "updated: " + updated);
    if (needRebind) {
        anim = null;
        if (!updated) {
            playRequested = false;
        }
        // Resetting progress state
        progressContainer.setVisibility(View.GONE);
        progressView.setVisibility(View.GONE);
        progressValue.setVisibility(View.GONE);
        progressIcon.setVisibility(View.GONE);
        if (fileMessage.getSource() instanceof FileRemoteSource) {
            boolean autoDownload = false;
            if (fileMessage instanceof PhotoContent) {
                autoDownload = messenger().isImageAutoDownloadEnabled();
            } else if (fileMessage instanceof AnimationContent) {
                autoDownload = messenger().isAnimationAutoPlayEnabled();
            } else if (fileMessage instanceof VideoContent) {
                autoDownload = messenger().isVideoAutoDownloadEnabled();
            }
            if (!updated) {
                previewView.setImageURI(null);
            }
            downloadFileVM = messenger().bindFile(((FileRemoteSource) fileMessage.getSource()).getFileReference(), autoDownload, new DownloadVMCallback(fileMessage));
        } else if (fileMessage.getSource() instanceof FileLocalSource) {
            uploadFileVM = messenger().bindUpload(message.getRid(), new UploadVMCallback());
            if (isPhoto) {
                Uri uri = Uri.fromFile(new File(((FileLocalSource) fileMessage.getSource()).getFileDescriptor()));
                bindImage(uri);
            } else {
                if (!updated) {
                    previewView.setImageURI(null);
                    Log.d(TAG, "rebind video - setImageURI(null)!");
                }
                //TODO: better approach?
                if (fileMessage.getFastThumb() != null && !updated) {
                    fastThumbLoader.request(fileMessage.getFastThumb().getImage());
                    Log.d(TAG, "rebind video- new thumb!");
                }
            }
        } else {
            throw new RuntimeException("Unknown file source type: " + fileMessage.getSource());
        }
    }
}
Also used : VideoContent(im.actor.core.entity.content.VideoContent) AnimationContent(im.actor.core.entity.content.AnimationContent) Uri(android.net.Uri) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) DocumentContent(im.actor.core.entity.content.DocumentContent) FrameLayout(android.widget.FrameLayout) FileLocalSource(im.actor.core.entity.content.FileLocalSource) File(java.io.File) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 2 with AnimationContent

use of im.actor.core.entity.content.AnimationContent 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 3 with AnimationContent

use of im.actor.core.entity.content.AnimationContent in project actor-platform by actorapp.

the class SenderActor method onFileUploaded.

private void onFileUploaded(long rid, FileReference fileReference) {
    PendingMessage msg = findPending(rid);
    if (msg == null) {
        return;
    }
    pendingMessages.getPendingMessages().remove(msg);
    AbsContent nContent;
    if (msg.getContent() instanceof PhotoContent) {
        PhotoContent basePhotoContent = (PhotoContent) msg.getContent();
        nContent = PhotoContent.createRemotePhoto(fileReference, basePhotoContent.getW(), basePhotoContent.getH(), basePhotoContent.getFastThumb());
    } else if (msg.getContent() instanceof VideoContent) {
        VideoContent baseVideoContent = (VideoContent) msg.getContent();
        nContent = VideoContent.createRemoteVideo(fileReference, baseVideoContent.getW(), baseVideoContent.getH(), baseVideoContent.getDuration(), baseVideoContent.getFastThumb());
    } else if (msg.getContent() instanceof VoiceContent) {
        VoiceContent baseVoiceContent = (VoiceContent) msg.getContent();
        nContent = VoiceContent.createRemoteAudio(fileReference, baseVoiceContent.getDuration());
    } else if (msg.getContent() instanceof AnimationContent) {
        AnimationContent baseAnimcationContent = (AnimationContent) msg.getContent();
        nContent = AnimationContent.createRemoteAnimation(fileReference, baseAnimcationContent.getW(), baseAnimcationContent.getH(), baseAnimcationContent.getFastThumb());
    } else if (msg.getContent() instanceof DocumentContent) {
        DocumentContent baseDocContent = (DocumentContent) msg.getContent();
        nContent = DocumentContent.createRemoteDocument(fileReference, baseDocContent.getFastThumb());
    } else {
        return;
    }
    pendingMessages.getPendingMessages().add(new PendingMessage(msg.getPeer(), msg.getRid(), nContent));
    context().getMessagesModule().getRouter().onContentChanged(msg.getPeer(), msg.getRid(), nContent);
    performSendContent(msg.getPeer(), rid, nContent);
    fileUplaodingWakeLocks.remove(rid).releaseLock();
}
Also used : VideoContent(im.actor.core.entity.content.VideoContent) VoiceContent(im.actor.core.entity.content.VoiceContent) DocumentContent(im.actor.core.entity.content.DocumentContent) AbsContent(im.actor.core.entity.content.AbsContent) AnimationContent(im.actor.core.entity.content.AnimationContent) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 4 with AnimationContent

use of im.actor.core.entity.content.AnimationContent in project actor-platform by actorapp.

the class SenderActor method performSendContent.

// Sending content
private void performSendContent(final Peer peer, final long rid, AbsContent content) {
    WakeLock wakeLock = im.actor.runtime.Runtime.makeWakeLock();
    ApiMessage message;
    if (content instanceof TextContent) {
        message = new ApiTextMessage(((TextContent) content).getText(), ((TextContent) content).getMentions(), ((TextContent) content).getTextMessageEx());
    } else if (content instanceof DocumentContent) {
        DocumentContent documentContent = (DocumentContent) content;
        FileRemoteSource source = (FileRemoteSource) documentContent.getSource();
        ApiDocumentEx documentEx = null;
        if (content instanceof PhotoContent) {
            PhotoContent photoContent = (PhotoContent) content;
            documentEx = new ApiDocumentExPhoto(photoContent.getW(), photoContent.getH());
        } else if (content instanceof VideoContent) {
            VideoContent videoContent = (VideoContent) content;
            documentEx = new ApiDocumentExVideo(videoContent.getW(), videoContent.getH(), videoContent.getDuration());
        } else if (content instanceof AnimationContent) {
            AnimationContent animationContent = (AnimationContent) content;
            documentEx = new ApiDocumentExAnimation(animationContent.getW(), animationContent.getH());
        } else if (content instanceof VoiceContent) {
            VoiceContent voiceContent = (VoiceContent) content;
            documentEx = new ApiDocumentExVoice(voiceContent.getDuration());
        }
        ApiFastThumb fastThumb = null;
        if (documentContent.getFastThumb() != null) {
            fastThumb = new ApiFastThumb(documentContent.getFastThumb().getW(), documentContent.getFastThumb().getH(), documentContent.getFastThumb().getImage());
        }
        message = new ApiDocumentMessage(source.getFileReference().getFileId(), source.getFileReference().getAccessHash(), source.getFileReference().getFileSize(), source.getFileReference().getFileName(), documentContent.getMimeType(), fastThumb, documentEx);
    } else if (content instanceof LocationContent) {
        message = new ApiJsonMessage(((LocationContent) content).getRawJson());
    } else if (content instanceof ContactContent) {
        message = new ApiJsonMessage(((ContactContent) content).getRawJson());
    } else if (content instanceof JsonContent) {
        message = new ApiJsonMessage(((JsonContent) content).getRawJson());
    } else if (content instanceof StickerContent) {
        message = ((ContentRemoteContainer) content.getContentContainer()).getMessage();
    } else {
        return;
    }
    performSendApiContent(peer, rid, message, wakeLock);
}
Also used : ApiFastThumb(im.actor.core.api.ApiFastThumb) ApiDocumentEx(im.actor.core.api.ApiDocumentEx) ApiDocumentExVoice(im.actor.core.api.ApiDocumentExVoice) StickerContent(im.actor.core.entity.content.StickerContent) LocationContent(im.actor.core.entity.content.LocationContent) WakeLock(im.actor.runtime.power.WakeLock) VideoContent(im.actor.core.entity.content.VideoContent) ApiTextMessage(im.actor.core.api.ApiTextMessage) JsonContent(im.actor.core.entity.content.JsonContent) AnimationContent(im.actor.core.entity.content.AnimationContent) ContactContent(im.actor.core.entity.content.ContactContent) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) VoiceContent(im.actor.core.entity.content.VoiceContent) DocumentContent(im.actor.core.entity.content.DocumentContent) ApiMessage(im.actor.core.api.ApiMessage) ApiDocumentExPhoto(im.actor.core.api.ApiDocumentExPhoto) ApiDocumentExAnimation(im.actor.core.api.ApiDocumentExAnimation) ApiDocumentMessage(im.actor.core.api.ApiDocumentMessage) ContentRemoteContainer(im.actor.core.entity.content.internal.ContentRemoteContainer) ApiDocumentExVideo(im.actor.core.api.ApiDocumentExVideo) TextContent(im.actor.core.entity.content.TextContent) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 5 with AnimationContent

use of im.actor.core.entity.content.AnimationContent in project actor-platform by actorapp.

the class JsContent method createContent.

public static JsContent createContent(AbsContent src, int sender) {
    JsMessenger messenger = JsMessenger.getInstance();
    JsContent content;
    if (src instanceof TextContent) {
        TextContent textContent = (TextContent) src;
        if (textContent.getTextMessageEx() instanceof ApiTextModernMessage) {
            ApiTextModernMessage modernMessage = (ApiTextModernMessage) textContent.getTextMessageEx();
            String text = modernMessage.getText();
            JsParagraphStyle paragraphStyle = JsParagraphStyle.create(modernMessage.getStyle());
            JsArray<JsAttach> attaches = JsArray.createArray().cast();
            for (ApiTextModernAttach srcAttach : modernMessage.getAttaches()) {
                JsArray<JsAttachField> fields = JsArray.createArray().cast();
                for (ApiTextModernField f : srcAttach.getFields()) {
                    boolean isShort = f.isShort() != null ? f.isShort() : true;
                    fields.push(JsAttachField.create(f.getTitle(), f.getValue(), isShort));
                }
                attaches.push(JsAttach.create(srcAttach.getTitle(), srcAttach.getTitleUrl(), srcAttach.getText(), JsParagraphStyle.create(srcAttach.getStyle()), fields));
            }
            content = JsContentTextModern.create(text, paragraphStyle, attaches);
        } else {
            content = JsContentText.create(((TextContent) src).getText());
        }
    } else if (src instanceof ServiceContent) {
        content = JsContentService.create(messenger.getFormatter().formatFullServiceMessage(sender, (ServiceContent) src, false));
    } else if (src instanceof DocumentContent) {
        DocumentContent doc = (DocumentContent) src;
        String fileName = doc.getName();
        String fileExtension = doc.getExt();
        String fileSize = messenger.getFormatter().formatFileSize(doc.getSource().getSize());
        String fileUrl = null;
        if (doc.getSource() instanceof FileRemoteSource) {
            fileUrl = messenger.getFileUrl(((FileRemoteSource) doc.getSource()).getFileReference());
        }
        boolean isUploading = doc.getSource() instanceof FileLocalSource;
        String thumb = null;
        if (doc.getFastThumb() != null) {
            String thumbBase64 = Base64Utils.toBase64(doc.getFastThumb().getImage());
            thumb = "data:image/jpg;base64," + thumbBase64;
        }
        if (src instanceof PhotoContent && thumb != null) {
            PhotoContent photoContent = (PhotoContent) src;
            content = JsContentPhoto.create(fileName, fileExtension, fileSize, photoContent.getW(), photoContent.getH(), thumb, fileUrl, isUploading);
        } else if (src instanceof AnimationContent) {
            AnimationContent animationContent = (AnimationContent) src;
            content = JsContentAnimation.create(fileName, fileExtension, fileSize, animationContent.getW(), animationContent.getH(), thumb, fileUrl, isUploading);
        } else if (src instanceof VoiceContent) {
            VoiceContent voiceContent = (VoiceContent) src;
            content = JsContentVoice.create(fileName, fileExtension, fileSize, fileUrl, isUploading, voiceContent.getDuration());
        } else {
            content = JsContentDocument.create(fileName, fileExtension, fileSize, thumb, fileUrl, isUploading);
        }
    } else if (src instanceof StickerContent) {
        StickerContent sticker = (StickerContent) src;
        ImageLocation stickerImage = sticker.getImage256();
        if (sticker.getImage512() != null) {
            stickerImage = sticker.getImage512();
        }
        String fileUrl = messenger.getFileUrl(stickerImage.getReference());
        String fileSize = messenger.getFormatter().formatFileSize(stickerImage.getReference().getFileSize());
        content = JsContentSticker.create(stickerImage.getReference().getFileName(), ".webp", fileSize, stickerImage.getWidth(), stickerImage.getHeight(), null, fileUrl, false);
    } else if (src instanceof ContactContent) {
        ContactContent contactContent = (ContactContent) src;
        JsArrayString phones = JsArray.createArray().cast();
        JsArrayString emails = JsArray.createArray().cast();
        for (String s : contactContent.getEmails()) {
            emails.push(s);
        }
        for (String s : contactContent.getPhones()) {
            phones.push(s);
        }
        content = JsContentContact.create(contactContent.getName(), contactContent.getPhoto64(), phones, emails);
    } else if (src instanceof LocationContent) {
        LocationContent locationContent = (LocationContent) src;
        content = JsContentLocation.create(locationContent.getLongitude(), locationContent.getLatitude(), locationContent.getStreet(), locationContent.getPlace());
    } else {
        content = JsContentUnsupported.create();
    }
    return content;
}
Also used : LocationContent(im.actor.core.entity.content.LocationContent) ApiTextModernField(im.actor.core.api.ApiTextModernField) AnimationContent(im.actor.core.entity.content.AnimationContent) JsArrayString(com.google.gwt.core.client.JsArrayString) ContactContent(im.actor.core.entity.content.ContactContent) ImageLocation(im.actor.core.entity.ImageLocation) ApiTextModernMessage(im.actor.core.api.ApiTextModernMessage) JsMessenger(im.actor.core.js.JsMessenger) ServiceContent(im.actor.core.entity.content.ServiceContent) FileLocalSource(im.actor.core.entity.content.FileLocalSource) PhotoContent(im.actor.core.entity.content.PhotoContent) StickerContent(im.actor.core.entity.content.StickerContent) JsArrayString(com.google.gwt.core.client.JsArrayString) ApiTextModernAttach(im.actor.core.api.ApiTextModernAttach) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) VoiceContent(im.actor.core.entity.content.VoiceContent) DocumentContent(im.actor.core.entity.content.DocumentContent) TextContent(im.actor.core.entity.content.TextContent)

Aggregations

AnimationContent (im.actor.core.entity.content.AnimationContent)6 DocumentContent (im.actor.core.entity.content.DocumentContent)5 PhotoContent (im.actor.core.entity.content.PhotoContent)5 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)4 VideoContent (im.actor.core.entity.content.VideoContent)4 FileLocalSource (im.actor.core.entity.content.FileLocalSource)3 VoiceContent (im.actor.core.entity.content.VoiceContent)3 ApiDocumentMessage (im.actor.core.api.ApiDocumentMessage)2 ApiJsonMessage (im.actor.core.api.ApiJsonMessage)2 ApiMessage (im.actor.core.api.ApiMessage)2 ApiTextMessage (im.actor.core.api.ApiTextMessage)2 ContactContent (im.actor.core.entity.content.ContactContent)2 LocationContent (im.actor.core.entity.content.LocationContent)2 StickerContent (im.actor.core.entity.content.StickerContent)2 TextContent (im.actor.core.entity.content.TextContent)2 PendingMessage (im.actor.core.modules.messaging.actions.entity.PendingMessage)2 Uri (android.net.Uri)1 FrameLayout (android.widget.FrameLayout)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ApiDocumentEx (im.actor.core.api.ApiDocumentEx)1