use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class FragmentChat method onResume.
@Override
public void onResume() {
isPaused = false;
super.onResume();
if (showKeyboardOnResume || (keyboardViewVisible && keyboardView != null && keyboardView.getCurrentMode() == KeyboardView.MODE_KEYBOARD)) {
showPopup(KeyboardView.MODE_KEYBOARD);
openKeyboardInternal(edtChat);
}
if (FragmentShearedMedia.list != null && FragmentShearedMedia.list.size() > 0) {
deleteSelectedMessageFromAdapter(FragmentShearedMedia.list);
FragmentShearedMedia.list.clear();
}
canUpdateAfterDownload = true;
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
if (getActivity() == null || getActivity().isFinishing() || !isAdded()) {
return;
}
initLayoutHashNavigationCallback();
showSpamBar();
updateShowItemInScreen();
if (isGoingFromUserLink) {
new RequestClientSubscribeToRoom().clientSubscribeToRoom(mRoomId);
}
DbManager.getInstance().doRealmTask(realm -> {
final RealmRoom room = realm.where(RealmRoom.class).equalTo("id", mRoomId).findFirst();
if (room != null) {
if (G.connectionState == ConnectionState.CONNECTING || G.connectionState == ConnectionState.WAITING_FOR_NETWORK) {
setConnectionText(G.connectionState);
} else {
if (room.getType() != CHAT) {
/**
* set member count
* set this code in onResume for update this value when user
* come back from profile activities
*/
String members = null;
if (room.getType() == GROUP && room.getGroupRoom() != null) {
members = room.getGroupRoom().getParticipantsCountLabel();
} else if (room.getType() == CHANNEL && room.getChannelRoom() != null) {
members = room.getChannelRoom().getParticipantsCountLabel();
}
final String finalMembers = members;
if (finalMembers != null) {
if (finalMembers != null && HelperString.isNumeric(finalMembers) && Integer.parseInt(finalMembers) == 1) {
mToolbar.setSubTitle(finalMembers + " " + G.fragmentActivity.getResources().getString(R.string.one_member_chat));
} else {
mToolbar.setSubTitle(finalMembers + " " + G.fragmentActivity.getResources().getString(R.string.member_chat));
}
if (HelperCalander.isPersianUnicode)
mToolbar.setSubTitle(convertToUnicodeFarsiNumber(mToolbar.getSubTitleText()));
}
} else {
RealmRegisteredInfo realmRegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(realm, room.getChatRoom().getPeerId());
if (realmRegisteredInfo != null) {
setUserStatus(realmRegisteredInfo.getStatus(), realmRegisteredInfo.getLastSeen());
}
}
}
}
/**
* hint: should use from this method here because we need checkAction
* changeState after set members count for avoid from hide action if exist
*/
checkAction();
if (room != null) {
mToolbar.setTitle(EmojiManager.getInstance().replaceEmoji(room.getTitle(), null));
}
});
try {
mediaContainer.didLayoutChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
}, Config.LOW_START_PAGE_TIME);
mRoomIdStatic = mRoomId;
lastChatRoomId = mRoomId;
titleStatic = title;
G.onUserInfoResponse = this;
G.onSetAction = this;
G.onUserUpdateStatus = this;
G.onLastSeenUpdateTiming = this;
G.onChatDelete = this;
G.onConnectionChangeStateChat = this;
HelperNotification.getInstance().cancelNotification();
G.onBotClick = this;
/*finishActivity = new FinishActivity() {
@Override
public void finishActivity() {
// ActivityChat.this.finish();
finishChat();
}
};*/
initCallbacks();
HelperNotification.getInstance().isChatRoomNow = true;
onUpdateUserOrRoomInfo = messageId -> {
if (messageId != null && messageId.length() > 0) {
G.handler.post(() -> {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
if (linearLayoutManager != null) {
int start = linearLayoutManager.findFirstVisibleItemPosition();
if (start < 0) {
start = 0;
}
for (int i = start; i < mAdapter.getItemCount() && i < start + 15; i++) {
try {
MessageObject messageObject = mAdapter.getItem(i).messageObject;
if (messageObject != null && (String.valueOf(messageObject.id)).equals(messageId)) {
mAdapter.notifyItemChanged(i);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
};
if (isCloudRoom) {
avatarItem.setVisibility(View.VISIBLE);
avatarItem.setImageResource(R.drawable.ic_cloud_space_blue);
} else {
setAvatar();
}
if (mForwardMessages == null) {
rootView.findViewById(R.id.ac_ll_forward).setVisibility(View.GONE);
}
RealmRoom realmRoom = getRoom();
if (realmRoom != null) {
isMuteNotification = realmRoom.getMute();
if (!isBot) {
txtChannelMute.setText(isMuteNotification ? R.string.unmute : R.string.mute);
iconChannelMute.setText(isMuteNotification ? R.string.icon_speaker : R.string.icon_mute);
}
if (!mToolbar.isSearchFieldVisible()) {
iconMute.setVisibility(isMuteNotification ? View.VISIBLE : View.GONE);
}
}
registerListener();
// enable attachment popup camera if was visible
if (mAttachmentPopup != null && mAttachmentPopup.isShowing) {
if (ContextCompat.checkSelfPermission(G.fragmentActivity, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.ON_CAMERA_PERMISSION_GRANTED);
}
}
onLinkClick = v -> {
if (keyboardViewVisible) {
hideKeyboard();
}
};
}
use of net.iGap.structs.MessageObject 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);
}
use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class FragmentChat method onFailedMessageClick.
@Override
public void onFailedMessageClick(View view, final MessageObject messageObject, final int pos) {
// TODO: 12/28/20 MESSAGE_REFACTOR_NEED_TEST
final List<MessageObject> failedMessages = mAdapter.getFailedMessages();
hideKeyboard();
new ResendMessage(G.fragmentActivity, new IResendMessage() {
@Override
public void deleteMessage() {
if (pos >= 0 && mAdapter.getAdapterItemCount() > pos) {
mAdapter.remove(pos);
removeLayoutTimeIfNeed();
}
}
@Override
public void resendMessage() {
for (int i = 0; i < failedMessages.size(); i++) {
if (failedMessages.get(i).id == messageObject.id) {
if (failedMessages.get(i).getAttachment() != null) {
if (!Uploader.getInstance().isCompressingOrUploading(messageObject.id + "")) {
UploadObject fileObject = UploadObject.createForMessage(messageObject, chatType);
if (fileObject != null) {
Uploader.getInstance().upload(fileObject);
}
}
}
break;
}
}
mAdapter.updateMessageStatus(messageObject.id, ProtoGlobal.RoomMessageStatus.SENDING);
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.notifyItemChanged(mAdapter.findPositionByMessageId(messageObject.id));
}
}, 300);
}
@Override
public void resendAllMessages() {
for (int i = 0; i < failedMessages.size(); i++) {
final int j = i;
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.updateMessageStatus(failedMessages.get(j).id, ProtoGlobal.RoomMessageStatus.SENDING);
}
}, 1000 * i);
}
}
@Override
public void copyMessage() {
copyMessageToClipboard(messageObject, false);
}
}, messageObject.id, failedMessages);
}
use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class FragmentChat method sendNewMessageCardToCard.
private void sendNewMessageCardToCard(String amount, String cardNumber, String description) {
String mplCardNumber = cardNumber.replace("-", "");
int mplAmount = Integer.parseInt(amount.replace(",", ""));
JsonArray rootJsonArray = new JsonArray();
JsonArray dataJsonArray = new JsonArray();
JsonObject valueObject = new JsonObject();
valueObject.addProperty("cardNumber", mplCardNumber);
valueObject.addProperty("amount", mplAmount);
valueObject.addProperty("userId", AccountManager.getInstance().getCurrentUser().getId());
JsonObject rootObject = new JsonObject();
rootObject.addProperty("label", "Card to Card");
rootObject.addProperty("imageUrl", "");
rootObject.addProperty("actionType", "27");
rootObject.add("value", valueObject);
dataJsonArray.add(rootObject);
rootJsonArray.add(dataJsonArray);
final RealmRoomMessage roomMessage = RealmRoomMessage.makeTextMessage(mRoomId, description, replyMessageId(), rootJsonArray.toString(), AdditionalType.CARD_TO_CARD_MESSAGE);
final MessageObject messageObject = MessageObject.create(roomMessage);
if (messageObject != null) {
edtChat.setText("");
lastMessageId = messageObject.id;
mAdapter.add(new CardToCardItem(mAdapter, chatType, FragmentChat.this).setMessage(messageObject).withIdentifier(SUID.id().get()));
clearReplyView();
scrollToEnd();
if (!description.isEmpty()) {
G.handler.postDelayed(() -> {
if (!messageObject.deleted) {
getSendMessageUtil().build(chatType, mRoomId, messageObject);
}
}, 1000);
} else {
getSendMessageUtil().build(chatType, mRoomId, messageObject);
}
} else {
Toast.makeText(context, R.string.please_write_your_message, Toast.LENGTH_LONG).show();
}
}
use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.
the class DownloadObject method createForRoomMessage.
public static DownloadObject createForRoomMessage(MessageObject messageObject) {
final MessageObject finalMessage = RealmRoomMessage.getFinalMessage(messageObject);
if (finalMessage == null || finalMessage.attachment == null) {
return null;
}
DownloadObject struct = new DownloadObject();
struct.selector = FILE_VALUE;
struct.key = createKey(finalMessage.attachment.cacheId, struct.selector);
struct.mainCacheId = finalMessage.attachment.cacheId;
struct.fileToken = finalMessage.attachment.token;
struct.fileName = finalMessage.attachment.name;
struct.fileSize = finalMessage.attachment.size;
struct.mimeType = struct.extractMime(struct.fileName);
struct.publicUrl = struct.getPublicUrl(finalMessage.attachment.publicUrl);
struct.priority = HttpRequest.PRIORITY.PRIORITY_MEDIUM;
String path = suitableAppFilePath(ProtoGlobal.RoomMessageType.forNumber(finalMessage.messageType));
struct.destFile = new File(path + "/" + struct.mainCacheId + "_" + struct.mimeType);
struct.tempFile = new File(G.context.getCacheDir() + "/" + struct.key);
struct.messageType = ProtoGlobal.RoomMessageType.valueOf(finalMessage.messageType);
if (struct.tempFile.exists()) {
struct.offset = struct.tempFile.length();
if (struct.offset > 0 && struct.fileSize > 0) {
struct.progress = (int) ((struct.offset * 100) / struct.fileSize);
}
}
return struct;
}
Aggregations