use of net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO in project iGap-Android by KianIranian-STDG.
the class FragmentChat method startPageFastInitialize.
/**
* set just important item to view in onCreate and load another objects in onResume
* actions : set app color, load avatar, set background, set title, set status chat or member for group or channel
*/
private void startPageFastInitialize() {
Bundle extras = getArguments();
if (extras != null) {
mRoomId = extras.getLong("RoomId");
isGoingFromUserLink = extras.getBoolean("GoingFromUserLink");
isNotJoin = extras.getBoolean("ISNotJoin");
userName = extras.getString("UserName");
messageId = extras.getLong("MessageId");
documentId = extras.getLong("DocumentId");
chatPeerId = extras.getLong("peerId");
}
attachFile = new AttachFile(G.fragmentActivity);
RealmRoom realmRoom = getRoom();
pageSettings();
// avi = (AVLoadingIndicatorView) rootView.findViewById(R.id.avi);
verifiedIcon.setVisibility(View.GONE);
/**
* need this info for load avatar
*/
if (realmRoom != null) {
chatType = realmRoom.getType();
if (chatType == CHAT) {
chatPeerId = realmRoom.getChatRoom().getPeerId();
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
if (realmRegisteredInfo != null) {
title = realmRegisteredInfo.getDisplayName();
lastSeen = realmRegisteredInfo.getLastSeen();
userStatus = realmRegisteredInfo.getStatus();
isBot = realmRegisteredInfo.isBot();
if (isBot) {
if (getMessagesCount() == 0) {
layoutMute.setVisibility(View.VISIBLE);
txtChannelMute.setText(R.string.start);
iconChannelMute.setText("");
View layoutAttach = rootView.findViewById(R.id.layout_attach_file);
layoutAttach.setVisibility(View.GONE);
layoutMute.setOnClickListener(v -> {
if (!isChatReadOnly) {
edtChat.setText("/Start");
imvSendButton.performClick();
removeStartButton();
}
});
isShowStartButton = true;
}
}
if (realmRegisteredInfo.isVerified()) {
verifiedIcon.setVisibility(View.VISIBLE);
}
} else {
/**
* when userStatus isn't EXACTLY lastSeen time not used so don't need
* this time and also this time not exist in room info
*/
title = realmRoom.getTitle();
userStatus = G.fragmentActivity.getResources().getString(R.string.last_seen_recently);
}
} else {
mRoomId = realmRoom.getId();
title = realmRoom.getTitle();
if (chatType == GROUP && realmRoom.getGroupRoom() != null) {
groupParticipantsCountLabel = realmRoom.getGroupRoom().getParticipantsCountLabel();
isPublicGroup = roomIsPublic = !realmRoom.getGroupRoom().isPrivate();
} else if (chatType == CHANNEL && realmRoom.getChannelRoom() != null) {
groupParticipantsCountLabel = realmRoom.getChannelRoom().getParticipantsCountLabel();
showVoteChannel = realmRoom.getChannelRoom().isReactionStatus();
if (realmRoom.getChannelRoom().isVerified()) {
verifiedIcon.setVisibility(View.VISIBLE);
}
roomIsPublic = !realmRoom.getChannelRoom().isPrivate();
}
}
if (chatType == CHAT) {
setUserStatus(userStatus, lastSeen);
} else if ((chatType == GROUP) || (chatType == CHANNEL)) {
if (groupParticipantsCountLabel != null) {
if (HelperString.isNumeric(groupParticipantsCountLabel) && Integer.parseInt(groupParticipantsCountLabel) == 1) {
mToolbar.setSubTitle(groupParticipantsCountLabel + " " + G.fragmentActivity.getResources().getString(R.string.one_member_chat));
} else {
mToolbar.setSubTitle(groupParticipantsCountLabel + " " + G.fragmentActivity.getResources().getString(R.string.member_chat));
}
// avi.setVisibility(View.GONE);
}
}
} else if (chatPeerId != 0) {
/**
* when user start new chat this block will be called
*/
chatType = CHAT;
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
title = realmRegisteredInfo.getDisplayName();
lastSeen = realmRegisteredInfo.getLastSeen();
userStatus = realmRegisteredInfo.getStatus();
setUserStatus(userStatus, lastSeen);
}
if (title != null) {
mToolbar.setTitle(EmojiManager.getInstance().replaceEmoji(title, null));
}
/**
* change english number to persian number
*/
if (HelperCalander.isPersianUnicode) {
mToolbar.setTitle(EmojiManager.getInstance().replaceEmoji(mToolbar.getTitleTextView().getText().toString(), mToolbar.getTitleTextView().getPaint().getFontMetricsInt()));
mToolbar.setSubTitle(convertToUnicodeFarsiNumber(mToolbar.getSubTitleText()));
}
/**
* hint: don't check isCloudRoom with (( RealmRoom.isCloudRoom(mRoomId, realm); ))
* because in first time room not exist in RealmRoom and value is false always.
* so just need to check this value with chatPeerId
*/
if (chatPeerId == AccountManager.getInstance().getCurrentUser().getId()) {
isCloudRoom = true;
}
viewAttachFile = rootView.findViewById(R.id.layout_attach_file);
iconMute = mToolbar.getMuteIcon();
if (realmRoom != null) {
iconMute.setVisibility(realmRoom.getMute() ? View.VISIBLE : View.GONE);
isMuteNotification = realmRoom.getMute();
isChatReadOnly = realmRoom.getReadOnly();
}
// gone video , voice button call then if status was ok visible them
// mHelperToolbar.getSecondRightButton().setVisibility(View.GONE);
callItem.setVisibility(View.GONE);
if (isChatReadOnly) {
viewAttachFile.setVisibility(View.GONE);
(rootView.findViewById(R.id.chl_recycler_view_chat)).setPadding(0, 0, 0, 0);
} else if (chatType == CHAT && AccountManager.getInstance().getCurrentUser().getId() != chatPeerId && !isBot) {
// gone or visible view call
RealmCallConfig callConfig = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmCallConfig.class).findFirst();
});
if (callConfig != null) {
if (callConfig.isVoice_calling()) {
// mHelperToolbar.getSecondRightButton().setVisibility(View.VISIBLE);
callItem.setVisibility(View.VISIBLE);
} else {
callItem.setVisibility(View.VISIBLE);
// mHelperToolbar.getSecondRightButton().setVisibility(View.GONE);
}
} else {
new RequestSignalingGetConfiguration().signalingGetConfiguration();
}
}
createMoreItems();
manageExtraLayout();
}
use of net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO in project iGap-Android by KianIranian-STDG.
the class FragmentChat method sendMessage.
/**
* *************************** Messaging ***************************
*/
private void sendMessage(int requestCode, String filePath) {
String message;
if (getWrittenMessage().length() > Config.MAX_TEXT_ATTACHMENT_LENGTH)
message = getWrittenMessage().substring(0, Config.MAX_TEXT_ATTACHMENT_LENGTH);
else
message = getWrittenMessage();
String mainMessage = getWrittenMessage();
if (filePath == null || (filePath.length() == 0 && requestCode != AttachFile.request_code_contact_phone)) {
clearReplyView();
return;
}
showPopup(-1);
if (isShowLayoutUnreadMessage) {
removeLayoutUnreadMessage();
}
long messageId = AppUtils.makeRandomId();
final long updateTime = TimeUtils.currentLocalTime();
ProtoGlobal.RoomMessageType messageType = null;
String fileName;
long duration = 0;
long fileSize;
int[] imageDimens = { 0, 0 };
final long senderID = AccountManager.getInstance().getCurrentUser().getId();
/**
* check if path is uri detect real path from uri
*/
String path = getFilePathFromUri(Uri.parse(filePath));
if (path != null) {
filePath = path;
}
if (requestCode == AttachFile.requestOpenGalleryForVideoMultipleSelect && filePath.toLowerCase().endsWith(".gif")) {
requestCode = AttachFile.requestOpenGalleryForImageMultipleSelect;
}
fileName = new File(filePath).getName();
fileSize = new File(filePath).length();
RealmRoomMessage roomMessage = new RealmRoomMessage();
StructMessageInfo structMessageInfoNew = new StructMessageInfo(roomMessage);
switch(requestCode) {
case IntentRequests.REQ_CROP:
case AttachFile.requestOpenGalleryForImageMultipleSelect:
if (!filePath.toLowerCase().endsWith(".gif")) {
if (isMessageWrote()) {
messageType = IMAGE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.IMAGE;
}
} else {
if (isMessageWrote()) {
messageType = GIF_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.GIF;
}
}
imageDimens = AndroidUtils.getImageDimens(filePath);
break;
case AttachFile.request_code_TAKE_PICTURE:
if (AndroidUtils.getImageDimens(filePath)[0] == 0 && AndroidUtils.getImageDimens(filePath)[1] == 0) {
G.handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Picture Not Loaded", Toast.LENGTH_SHORT).show();
}
});
return;
}
imageDimens = AndroidUtils.getImageDimens(filePath);
if (isMessageWrote()) {
messageType = IMAGE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.IMAGE;
}
break;
case AttachFile.requestOpenGalleryForVideoMultipleSelect:
case request_code_VIDEO_CAPTURED:
// mainVideoPath
duration = AndroidUtils.getAudioDuration(G.fragmentActivity, filePath) / 1000;
if (isMessageWrote()) {
messageType = VIDEO_TEXT;
} else {
messageType = VIDEO;
}
break;
case AttachFile.request_code_pic_audi:
duration = AndroidUtils.getAudioDuration(G.fragmentActivity, filePath) / 1000;
if (isMessageWrote()) {
messageType = ProtoGlobal.RoomMessageType.AUDIO_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.AUDIO;
}
String songArtist = AndroidUtils.getAudioArtistName(filePath);
long songDuration = AndroidUtils.getAudioDuration(G.fragmentActivity, filePath);
structMessageInfoNew.setSongArtist(songArtist);
structMessageInfoNew.setSongLength(songDuration);
break;
case AttachFile.request_code_pic_file:
case AttachFile.request_code_open_document:
if (isMessageWrote()) {
messageType = ProtoGlobal.RoomMessageType.FILE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.FILE;
}
break;
case AttachFile.request_code_contact_phone:
if (latestUri == null) {
break;
}
messageType = CONTACT;
ContactUtils contactUtils = new ContactUtils(G.fragmentActivity, latestUri);
String name = contactUtils.retrieveName();
String number = contactUtils.retrieveNumber();
structMessageInfoNew.setContactValues(name, "", number);
break;
case AttachFile.request_code_paint:
imageDimens = AndroidUtils.getImageDimens(filePath);
if (isMessageWrote()) {
messageType = IMAGE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.IMAGE;
}
break;
}
final ProtoGlobal.RoomMessageType finalMessageType = messageType;
final String finalFilePath = filePath;
final String finalFileName = fileName;
final long finalDuration = duration;
final long finalFileSize = fileSize;
final int[] finalImageDimens = imageDimens;
roomMessage.setMessageId(messageId);
roomMessage.setMessageType(finalMessageType);
roomMessage.setMessage(message);
DbManager.getInstance().doRealmTask(realm -> {
RealmRoomMessage.addTimeIfNeed(roomMessage, realm);
});
RealmRoomMessage.isEmojiInText(roomMessage, message);
roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
roomMessage.setRoomId(mRoomId);
RealmAttachment realmAttachment = new RealmAttachment();
realmAttachment.setId(messageId);
realmAttachment.setLocalFilePath(finalFilePath);
realmAttachment.setWidth(finalImageDimens[0]);
realmAttachment.setHeight(finalImageDimens[1]);
realmAttachment.setSize(finalFileSize);
realmAttachment.setName(finalFileName);
realmAttachment.setDuration(finalDuration);
if (messageType != CONTACT) {
roomMessage.setAttachment(realmAttachment);
}
roomMessage.setUserId(senderID);
roomMessage.setAuthorHash(RealmUserInfo.getCurrentUserAuthorHash());
roomMessage.setShowMessage(true);
roomMessage.setCreateTime(updateTime);
if (isReply()) {
MessageObject replyLayoutObject = (MessageObject) mReplayLayout.getTag();
RealmRoomMessage replyMessage = new RealmRoomMessage();
replyMessage.setUserId(replyLayoutObject.userId);
replyMessage.setUpdateTime(replyLayoutObject.updateTime);
replyMessage.setStatusVersion(replyLayoutObject.statusVersion);
replyMessage.setShowTime(replyLayoutObject.needToShow);
replyMessage.setRoomId(replyLayoutObject.roomId);
replyMessage.setPreviousMessageId(replyLayoutObject.previousMessageId);
replyMessage.setFutureMessageId(replyLayoutObject.futureMessageId);
replyMessage.setMessageId(replyLayoutObject.id);
replyMessage.setEdited(replyLayoutObject.edited);
replyMessage.setDeleted(replyLayoutObject.deleted);
replyMessage.setCreateTime(replyLayoutObject.createTime);
replyMessage.setMessage(replyLayoutObject.message);
replyMessage.setMessageType(ProtoGlobal.RoomMessageType.forNumber(replyLayoutObject.messageType));
replyMessage.setStatus(ProtoGlobal.RoomMessageStatus.forNumber(replyLayoutObject.status).toString());
if (replyLayoutObject.getAttachment() != null) {
AttachmentObject attachmentObject = replyLayoutObject.getAttachment();
RealmAttachment replyToAttachment = new RealmAttachment();
replyToAttachment.setId(replyLayoutObject.id);
replyToAttachment.setLocalFilePath(attachmentObject.filePath);
replyToAttachment.setWidth(attachmentObject.width);
replyToAttachment.setHeight(attachmentObject.height);
replyToAttachment.setSize(attachmentObject.size);
replyToAttachment.setName(attachmentObject.name);
replyToAttachment.setDuration(attachmentObject.duration);
replyMessage.setAttachment(replyToAttachment);
}
// TODO: 1/13/21 MESSAGE_REFACTOR
roomMessage.setReplyTo(replyMessage);
}
long replyMessageId = 0;
if (roomMessage.getReplyTo() != null) {
if (roomMessage.getReplyTo().getMessageId() < 0) {
replyMessageId = roomMessage.getReplyTo().getMessageId() * (-1);
} else {
replyMessageId = roomMessage.getReplyTo().getMessageId();
}
}
if (chatType == CHANNEL) {
RealmChannelExtra realmChannelExtra = new RealmChannelExtra();
realmChannelExtra.setMessageId(messageId);
if (RealmRoom.showSignature(mRoomId)) {
realmChannelExtra.setSignature(AccountManager.getInstance().getCurrentUser().getName());
} else {
realmChannelExtra.setSignature("");
}
realmChannelExtra.setThumbsUp("0");
realmChannelExtra.setThumbsDown("0");
realmChannelExtra.setViewsLabel("1");
roomMessage.setChannelExtra(realmChannelExtra);
}
if (finalMessageType == CONTACT) {
if (latestUri != null) {
ContactUtils contactUtils = new ContactUtils(G.fragmentActivity, latestUri);
String name = contactUtils.retrieveName();
String number = contactUtils.retrieveNumber();
RealmRoomMessageContact realmRoomMessageContact = new RealmRoomMessageContact();
realmRoomMessageContact.setId(AppUtils.makeRandomId());
realmRoomMessageContact.setFirstName(name);
realmRoomMessageContact.setLastName("");
RealmList<RealmString> listString = new RealmList<>();
RealmString phoneRealmStr = new RealmString();
phoneRealmStr.setString(number);
listString.add(phoneRealmStr);
realmRoomMessageContact.setPhones(listString);
roomMessage.setRoomMessageContact(realmRoomMessageContact);
}
}
String makeThumbnailFilePath = "";
if (finalMessageType == VIDEO || finalMessageType == VIDEO_TEXT) {
// mainVideoPath
makeThumbnailFilePath = finalFilePath;
}
if (finalMessageType == VIDEO || finalMessageType == VIDEO_TEXT) {
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(makeThumbnailFilePath, MediaStore.Video.Thumbnails.MINI_KIND);
if (bitmap != null) {
roomMessage.getAttachment().setLocalThumbnailPath(AndroidUtils.saveBitmap(bitmap));
roomMessage.getAttachment().setWidth(bitmap.getWidth());
roomMessage.getAttachment().setHeight(bitmap.getHeight());
}
}
new Thread(() -> {
DbManager.getInstance().doRealmTransaction(realm1 -> {
RealmRoom room = realm1.where(RealmRoom.class).equalTo("id", mRoomId).findFirst();
if (room != null) {
room.setDeleted(false);
}
RealmRoom.setLastMessageWithRoomMessage(realm1, roomMessage.getRoomId(), realm1.copyToRealmOrUpdate(roomMessage));
});
}).start();
if (finalMessageType == CONTACT) {
ChatSendMessageUtil messageUtil = getSendMessageUtil().newBuilder(chatType, finalMessageType, mRoomId).message(message);
messageUtil.contact(structMessageInfoNew.realmRoomMessage.getRoomMessageContact().getFirstName(), structMessageInfoNew.realmRoomMessage.getRoomMessageContact().getLastName(), structMessageInfoNew.realmRoomMessage.getRoomMessageContact().getPhones().first().getString());
if (isReply()) {
messageUtil.replyMessage(replyMessageId);
}
messageUtil.sendMessage(Long.toString(messageId));
}
if (isReply()) {
mReplayLayout.setTag(null);
G.handler.post(new Runnable() {
@Override
public void run() {
mReplayLayout.setVisibility(View.GONE);
}
});
}
G.handler.post(new Runnable() {
@Override
public void run() {
switchAddItem(new ArrayList<>(Collections.singletonList(structMessageInfoNew)), false);
if (mainMessage.length() > message.length()) {
sendNewMessage(mainMessage.substring(message.length()));
}
}
});
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
scrollToEnd();
}
}, 100);
}
Aggregations