Search in sources :

Example 1 with ImageLocation

use of im.actor.core.entity.ImageLocation 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 2 with ImageLocation

use of im.actor.core.entity.ImageLocation 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

ImageLocation (im.actor.core.entity.ImageLocation)2 StickerContent (im.actor.core.entity.content.StickerContent)2 ViewGroup (android.view.ViewGroup)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ApiTextModernAttach (im.actor.core.api.ApiTextModernAttach)1 ApiTextModernField (im.actor.core.api.ApiTextModernField)1 ApiTextModernMessage (im.actor.core.api.ApiTextModernMessage)1 FileReference (im.actor.core.entity.FileReference)1 AnimationContent (im.actor.core.entity.content.AnimationContent)1 ContactContent (im.actor.core.entity.content.ContactContent)1 DocumentContent (im.actor.core.entity.content.DocumentContent)1 FileLocalSource (im.actor.core.entity.content.FileLocalSource)1 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)1 LocationContent (im.actor.core.entity.content.LocationContent)1 PhotoContent (im.actor.core.entity.content.PhotoContent)1 ServiceContent (im.actor.core.entity.content.ServiceContent)1 TextContent (im.actor.core.entity.content.TextContent)1 VoiceContent (im.actor.core.entity.content.VoiceContent)1 JsMessenger (im.actor.core.js.JsMessenger)1