use of im.actor.core.entity.content.VoiceContent 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();
}
use of im.actor.core.entity.content.VoiceContent in project actor-platform by actorapp.
the class SenderActor method doSendAudio.
public void doSendAudio(Peer peer, String descriptor, String fileName, int fileSize, int duration) {
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
VoiceContent audioContent = VoiceContent.createLocalAudio(descriptor, fileName, fileSize, duration);
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, audioContent);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, audioContent));
savePending();
performUploadFile(rid, descriptor, fileName);
}
use of im.actor.core.entity.content.VoiceContent 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);
}
use of im.actor.core.entity.content.VoiceContent 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());
}
}
}
use of im.actor.core.entity.content.VoiceContent 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;
}
Aggregations