Search in sources :

Example 6 with FileRemoteSource

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

the class AudioHolder method bindData.

@Override
protected void bindData(final Message message, long readDate, long receiveDate, boolean isUpdated, PreprocessedData preprocessedData) {
    VoiceContent audioMsg = (VoiceContent) message.getContent();
    if (message.getSenderId() == myUid()) {
        //            messageBubble.getBackground().setColorFilter(messageBubble.getContext().getResources().getColor(R.color.conv_bubble), PorterDuff.Mode.MULTIPLY);
        messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_out);
    } else {
        messageBubble.setBackgroundResource(R.drawable.conv_bubble_media_in);
        messageBubble.getBackground().setColorFilter(null);
    }
    // Update state
    if (message.getSenderId() == myUid()) {
        stateIcon.setVisibility(View.VISIBLE);
        switch(message.getMessageState()) {
            case ERROR:
                stateIcon.setResource(R.drawable.msg_error);
                stateIcon.setTint(errorColor);
                break;
            default:
            case PENDING:
                stateIcon.setResource(R.drawable.msg_clock);
                stateIcon.setTint(waitColor);
                break;
            case SENT:
                if (message.getSortDate() <= readDate) {
                    stateIcon.setResource(R.drawable.msg_check_2);
                    stateIcon.setTint(readColor);
                } else if (message.getSortDate() <= receiveDate) {
                    stateIcon.setResource(R.drawable.msg_check_2);
                    stateIcon.setTint(deliveredColor);
                } else {
                    stateIcon.setResource(R.drawable.msg_check_1);
                    stateIcon.setTint(sentColor);
                }
                break;
        }
    } else {
        stateIcon.setVisibility(View.GONE);
    }
    // Update time
    setTimeAndReactions(time);
    currentDuration = ((VoiceContent) message.getContent()).getDuration();
    duration.setText(ActorSDK.sharedActor().getMessenger().getFormatter().formatDuration((int) (currentDuration / 1000)));
    // Update view
    boolean needRebind = false;
    if (isUpdated) {
        // Resetting binding
        if (downloadFileVM != null) {
            downloadFileVM.detach();
            downloadFileVM = null;
        }
        if (uploadFileVM != null) {
            uploadFileVM.detach();
            uploadFileVM = null;
        }
        needRebind = true;
    }
    if (needRebind) {
        if (audioMsg.getSource() instanceof FileRemoteSource) {
            boolean autoDownload = false;
            if (audioMsg instanceof VoiceContent) {
                autoDownload = messenger().isAudioAutoDownloadEnabled();
            }
            downloadFileVM = ActorSDK.sharedActor().getMessenger().bindFile(((FileRemoteSource) audioMsg.getSource()).getFileReference(), autoDownload, new DownloadVMCallback(audioMsg));
        } else if (audioMsg.getSource() instanceof FileLocalSource) {
            uploadFileVM = ActorSDK.sharedActor().getMessenger().bindUpload(message.getRid(), new UploadVMCallback());
            currentAudio = ((FileLocalSource) audioMsg.getSource()).getFileDescriptor();
            stop();
            bindPlayButton();
        } else {
            throw new RuntimeException("Unknown file source type: " + audioMsg.getSource());
        }
    }
}
Also used : VoiceContent(im.actor.core.entity.content.VoiceContent) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) FileLocalSource(im.actor.core.entity.content.FileLocalSource)

Example 7 with FileRemoteSource

use of im.actor.core.entity.content.FileRemoteSource 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)

Example 8 with FileRemoteSource

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

the class JsBindingModule method onFileLoaded.

@Override
public void onFileLoaded(HashSet<Long> fileId) {
    if (dialogsList != null) {
        for (JsDisplayListBind<JsDialog, Dialog> b : dialogsList.getActiveBinds()) {
            b.startReconverting();
            for (Dialog dialog : b.getRawItems()) {
                if (checkAvatar(dialog.getDialogAvatar(), fileId)) {
                    b.forceReconvert(dialog.getEngineId());
                }
            }
            b.stopReconverting();
        }
    }
    if (dialogsGroupedList != null) {
        ArrayList<DialogGroup> groups = context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().get();
        if (groups != null) {
            outer: for (DialogGroup g : groups) {
                for (DialogSmall ds : g.getDialogs()) {
                    if (checkAvatar(ds.getAvatar(), fileId)) {
                        context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().forceNotify();
                        break outer;
                    }
                }
            }
        }
    }
    if (contactsList != null) {
        for (JsDisplayListBind<JsContact, Contact> b : contactsList.getActiveBinds()) {
            b.startReconverting();
            for (Contact contact : b.getRawItems()) {
                if (checkAvatar(contact.getAvatar(), fileId)) {
                    b.forceReconvert(contact.getEngineId());
                }
            }
            b.stopReconverting();
        }
    }
    for (JsDisplayList<JsMessage, Message> messageList : messageLists.values()) {
        for (JsDisplayListBind<JsMessage, Message> b : messageList.getActiveBinds()) {
            b.startReconverting();
            for (Message message : b.getRawItems()) {
                UserVM user = context().getUsersModule().getUsers().get(message.getSenderId());
                if (checkAvatar(user.getAvatar().get(), fileId)) {
                    b.forceReconvert(message.getEngineId());
                    continue;
                }
                if (message.getContent() instanceof DocumentContent) {
                    DocumentContent doc = (DocumentContent) message.getContent();
                    if (doc.getSource() instanceof FileRemoteSource) {
                        if (fileId.contains(((FileRemoteSource) doc.getSource()).getFileReference().getFileId())) {
                            b.forceReconvert(message.getEngineId());
                        }
                    }
                }
                if (message.getContent() instanceof StickerContent) {
                    StickerContent content = (StickerContent) message.getContent();
                    if (content.getImage512() != null) {
                        long stickerFileId = content.getImage512().getReference().getFileId();
                        if (fileId.contains(stickerFileId)) {
                            b.forceReconvert(message.getEngineId());
                        }
                    } else if (content.getImage256() != null) {
                        long stickerFileId = content.getImage256().getReference().getFileId();
                        if (fileId.contains(stickerFileId)) {
                            b.forceReconvert(message.getEngineId());
                        }
                    }
                }
            }
            b.stopReconverting();
        }
    }
    for (JsBindedValue<JsUser> u : users.values()) {
        int uid = u.get().getUid();
        UserVM userVM = context().getUsersModule().getUsers().get(uid);
        if (checkAvatar(userVM.getAvatar().get(), fileId)) {
            u.changeValue(JsUser.fromUserVM(userVM, messenger));
        }
    }
    for (JsBindedValue<JsGroup> g : groups.values()) {
        int gid = g.get().getGid();
        GroupVM groupVM = context().getGroupsModule().getGroupsCollection().get(gid);
        if (checkAvatar(groupVM.getAvatar().get(), fileId)) {
            g.changeValue(JsGroup.fromGroupVM(groupVM, messenger));
        }
    }
    //
    if (stickers != null) {
        outer: for (StickerPack stickerPack : messenger.getAvailableStickersVM().getOwnStickerPacks().get()) {
            for (Sticker s : stickerPack.getStickers()) {
                if (s.getImage256() != null && fileId.contains(s.getImage256().getFileId())) {
                    messenger.getAvailableStickersVM().getOwnStickerPacks().forceNotify();
                    break outer;
                }
            }
        }
    }
}
Also used : JsMessage(im.actor.core.js.entity.JsMessage) Message(im.actor.core.entity.Message) StickerPack(im.actor.core.entity.StickerPack) JsMessage(im.actor.core.js.entity.JsMessage) Sticker(im.actor.core.entity.Sticker) JsSticker(im.actor.core.js.entity.JsSticker) JsDialog(im.actor.core.js.entity.JsDialog) JsDialog(im.actor.core.js.entity.JsDialog) Dialog(im.actor.core.entity.Dialog) JsUser(im.actor.core.js.entity.JsUser) DialogSmall(im.actor.core.viewmodel.DialogSmall) StickerContent(im.actor.core.entity.content.StickerContent) GroupVM(im.actor.core.viewmodel.GroupVM) JsContact(im.actor.core.js.entity.JsContact) JsContact(im.actor.core.js.entity.JsContact) Contact(im.actor.core.entity.Contact) UserVM(im.actor.core.viewmodel.UserVM) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) DocumentContent(im.actor.core.entity.content.DocumentContent) JsDialogGroup(im.actor.core.js.entity.JsDialogGroup) DialogGroup(im.actor.core.viewmodel.DialogGroup) JsGroup(im.actor.core.js.entity.JsGroup)

Aggregations

FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)8 FileLocalSource (im.actor.core.entity.content.FileLocalSource)6 DocumentContent (im.actor.core.entity.content.DocumentContent)5 PhotoContent (im.actor.core.entity.content.PhotoContent)5 AnimationContent (im.actor.core.entity.content.AnimationContent)4 StickerContent (im.actor.core.entity.content.StickerContent)3 VideoContent (im.actor.core.entity.content.VideoContent)3 VoiceContent (im.actor.core.entity.content.VoiceContent)3 FileReference (im.actor.core.entity.FileReference)2 ContactContent (im.actor.core.entity.content.ContactContent)2 LocationContent (im.actor.core.entity.content.LocationContent)2 TextContent (im.actor.core.entity.content.TextContent)2 FileCallback (im.actor.core.viewmodel.FileCallback)2 UploadFileCallback (im.actor.core.viewmodel.UploadFileCallback)2 FileSystemReference (im.actor.runtime.files.FileSystemReference)2 ImageLoadException (im.actor.sdk.util.images.common.ImageLoadException)2 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 FrameLayout (android.widget.FrameLayout)1