use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class RoomListCell method getLastMessage.
private void getLastMessage(RealmRoom room, AppCompatTextView lastMessageTv) {
SpannableStringBuilder builder = new SpannableStringBuilder();
if (room.getActionState() != null && room.getActionStateUserId() != AccountManager.getInstance().getCurrentUser().getId()) {
SpannableString typingSpannableString = new SpannableString(room.getActionState());
typingSpannableString.setSpan(new ForegroundColorSpan(Theme.getInstance().getAccentColor(lastMessageTv.getContext())), 0, room.getActionState().length(), 0);
builder.append(typingSpannableString);
} else if (room.getDraft() != null && !TextUtils.isEmpty(room.getDraft().getMessage())) {
String draft = getResources().getString(R.string.txt_draft) + " ";
SpannableString redSpannable = new SpannableString(draft);
redSpannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(lastMessageTv.getContext(), R.color.red)), 0, draft.length(), 0);
String draftMessage = room.getDraft().getMessage();
SpannableString message = new SpannableString(draftMessage);
message.setSpan(new ForegroundColorSpan(Theme.getInstance().getSendMessageTextColor(lastMessageTv.getContext())), 0, message.length(), 0);
builder.append(redSpannable);
builder.append(message);
} else {
boolean haveAttachment = false;
boolean haveSenderName = false;
boolean nameIsPersian = false;
RealmRoomMessage lastMessage;
if (room.getLastMessage() != null) {
if (room.getLastMessage().getForwardMessage() != null) {
lastMessage = room.getLastMessage().getForwardMessage();
} else {
lastMessage = room.getLastMessage();
}
if (lastMessage.isDeleted()) {
String deletedMessage = getResources().getString(R.string.deleted_message);
SpannableString deletedSpannable = new SpannableString(deletedMessage);
deletedSpannable.setSpan(new ForegroundColorSpan(Theme.getInstance().getSendMessageTextColor(lastMessageTv.getContext())), 0, deletedMessage.length(), 0);
builder.append(deletedSpannable);
lastMessageTv.setText(builder, TextView.BufferType.SPANNABLE);
return;
}
if (lastMessage.getMessage() != null) {
String attachmentTag = null;
String senderNameTag = null;
SpannableString attachmentSpannable = null;
SpannableString senderNameSpannable = null;
SpannableString lastMessageSpannable;
SpannableString senderNameQuoteSpannable = null;
if (room.getType() == GROUP && lastMessage.getMessageType() != ProtoGlobal.RoomMessageType.LOG) {
if (lastMessage.isAuthorMe() && room.getLastMessage().getForwardMessage() == null) {
senderNameTag = getResources().getString(R.string.txt_you);
senderNameSpannable = new SpannableString(senderNameTag);
} else {
if (room.getLastMessage().isAuthorMe()) {
senderNameTag = getResources().getString(R.string.txt_you);
senderNameSpannable = new SpannableString(senderNameTag);
} else {
try {
RealmRegisteredInfo realmRegisteredInfo;
if (room.getLastMessage().getForwardMessage() != null)
realmRegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(room.getRealm(), room.getLastMessage().getUserId());
else
realmRegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(room.getRealm(), lastMessage.getUserId());
if (realmRegisteredInfo != null && realmRegisteredInfo.getDisplayName() != null) {
senderNameTag = realmRegisteredInfo.getDisplayName();
senderNameSpannable = new SpannableString(senderNameTag);
nameIsPersian = Character.getDirectionality(realmRegisteredInfo.getDisplayName().charAt(0)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
}
} catch (Exception e) {
Log.e(getClass().getName(), "room list last message: ", e);
}
}
}
if (senderNameSpannable != null) {
haveSenderName = true;
senderNameSpannable.setSpan(new ForegroundColorSpan(Theme.getInstance().getAccentColor(lastMessageTv.getContext())), 0, senderNameTag.length(), 0);
}
}
switch(lastMessage.getMessageType()) {
case IMAGE_TEXT:
attachmentTag = AppUtils.getEmojiByUnicode(IMAGE);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case GIF_TEXT:
attachmentTag = AppUtils.getEmojiByUnicode(GIF);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case FILE_TEXT:
attachmentTag = AppUtils.getEmojiByUnicode(FILE);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case VIDEO_TEXT:
attachmentTag = AppUtils.getEmojiByUnicode(VIDEO);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case AUDIO_TEXT:
attachmentTag = AppUtils.getEmojiByUnicode(MUSIC);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case GIF:
attachmentTag = getResources().getString(R.string.gif_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case VOICE:
attachmentTag = getResources().getString(R.string.voice_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case LOG:
attachmentTag = HelperLogMessage.deserializeLog(lastMessageTv.getContext(), lastMessage.getLogs(), false).toString();
attachmentSpannable = new SpannableString(attachmentTag);
break;
case AUDIO:
attachmentTag = (lastMessage.getAttachment().getName() == null) ? AppUtils.getEmojiByUnicode(MUSIC) + " AUDIO " : AppUtils.getEmojiByUnicode(MUSIC) + lastMessage.getAttachment().getName();
attachmentSpannable = new SpannableString(attachmentTag);
break;
case FILE:
attachmentTag = getResources().getString(R.string.file_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case IMAGE:
attachmentTag = getResources().getString(R.string.image_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case VIDEO:
attachmentTag = getResources().getString(R.string.video_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case WALLET:
builder.append(AppUtils.getEmojiByUnicode(WALLET));
if (lastMessage.getRoomMessageWallet() != null) {
String type = lastMessage.getRoomMessageWallet().getType();
if (type.equals(CARD_TO_CARD.toString())) {
attachmentTag = getResources().getString(R.string.card_to_card_message);
} else if (type.equals(TOPUP.toString())) {
attachmentTag = getResources().getString(R.string.topUp_message);
} else if (type.equals(BILL.toString())) {
attachmentTag = getResources().getString(R.string.bill_message);
} else if (type.equals(PAYMENT.toString())) {
attachmentTag = getResources().getString(R.string.payment_message);
} else if (type.equals(MONEY_TRANSFER.toString())) {
attachmentTag = getResources().getString(R.string.wallet_message);
} else {
attachmentTag = getResources().getString(R.string.unknown_message);
}
} else
attachmentTag = getResources().getString(R.string.wallet_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case CONTACT:
attachmentTag = getResources().getString(R.string.contact_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case STICKER:
attachmentTag = getResources().getString(R.string.sticker_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
case LOCATION:
attachmentTag = getResources().getString(R.string.location_message);
attachmentSpannable = new SpannableString(attachmentTag);
break;
}
if (attachmentSpannable != null) {
haveAttachment = true;
attachmentSpannable.setSpan(new ForegroundColorSpan(Theme.getInstance().getAccentColor(lastMessageTv.getContext())), 0, attachmentTag.length(), 0);
}
if (haveSenderName) {
senderNameQuoteSpannable = new SpannableString(haveAttachment ? ":" : nameIsPersian ? ": " : ": ");
senderNameQuoteSpannable.setSpan(new ForegroundColorSpan(Theme.getInstance().getAccentColor(lastMessageTv.getContext())), 0, senderNameQuoteSpannable.length(), 0);
}
String message;
if (lastMessage.getMessage().length() > 70) {
message = lastMessage.getMessage().substring(0, 70) + "...";
} else
message = lastMessage.getMessage();
ArrayList<Tuple<Integer, Integer>> boldPlaces = AbstractMessage.getBoldPlaces(message);
message = AbstractMessage.removeBoldMark(message, boldPlaces);
// if (HelperCalander.isPersianUnicode)
// message = HelperCalander.convertToUnicodeFarsiNumber(message);
lastMessageSpannable = new SpannableString(/*subStringInternal(*/
message);
lastMessageSpannable.setSpan(new ForegroundColorSpan(Theme.getInstance().getSendMessageTextColor(lastMessageTv.getContext())), 0, lastMessageSpannable.length(), 0);
if (haveSenderName) {
if (haveAttachment) {
builder.append(senderNameSpannable).append(senderNameQuoteSpannable).append(attachmentSpannable).append(" ").append(lastMessageSpannable);
} else
builder.append(senderNameSpannable).append(senderNameQuoteSpannable).append(lastMessageSpannable);
} else {
if (haveAttachment) {
builder.append(attachmentSpannable).append(lastMessageSpannable);
} else
builder.append(lastMessageSpannable);
}
}
}
}
lastMessageTv.setText(EmojiManager.getInstance().replaceEmoji(builder, lastMessageTv.getPaint().getFontMetricsInt(), -1, false), TextView.BufferType.SPANNABLE);
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class MusicPlayer method getMusicName.
private static String getMusicName(long messageId, String name) {
try {
if (isVoice) {
String voiceName = "";
RealmRoomMessage realmRoomMessage = DbManager.getInstance().doRealmTask(realm -> {
return RealmRoomMessage.getFinalMessage(realm.where(RealmRoomMessage.class).equalTo("messageId", messageId).findFirst());
});
if (realmRoomMessage != null) {
if (realmRoomMessage.getUserId() != 0) {
if (realmRoomMessage.getUserId() == AccountManager.getInstance().getCurrentUser().getId()) {
voiceName = G.context.getResources().getString(R.string.you);
} else {
voiceName = RealmRegisteredInfo.getNameWithId(realmRoomMessage.getUserId());
}
} else if (realmRoomMessage.getAuthorRoomId() != 0) {
voiceName = RealmRoom.detectTitle(realmRoomMessage.getAuthorRoomId());
}
return G.fragmentActivity.getResources().getString(R.string.recorded_by) + " " + voiceName;
}
}
if (name == null) {
name = "";
}
if (name.length() > 0) {
return musicName = name;
} else if (musicPath != null && musicPath.length() > 0) {
return musicPath.substring(musicPath.lastIndexOf("/") + 1);
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class MusicPlayer method startPlayer.
public static void startPlayer(final String name, String musicPath, String roomName, long roomId, final boolean updateList, final String messageID) {
if (!inChangeStreamType) {
// G.handler.postDelayed(new Runnable() {
// @Override
// public void run() {
// // canDoAction = true;
// }
// }, 1000);
isVoice = false;
isPause = false;
if (messageID != null && messageID.length() > 0) {
try {
RealmRoomMessage realmRoomMessage = DbManager.getInstance().doRealmTask(realm -> {
return RealmRoomMessage.getFinalMessage(realm.where(RealmRoomMessage.class).equalTo("messageId", Long.parseLong(messageID)).findFirst());
});
if (realmRoomMessage != null) {
String type = realmRoomMessage.getMessageType().toString();
if (type.equals("VOICE")) {
isVoice = true;
}
}
} catch (Exception e) {
HelperLog.getInstance().setErrorLog(e);
}
}
if (isVoice) {
try {
Intent intent = new Intent(context, MusicPlayer.class);
intent.putExtra("ACTION", STOPFOREGROUND_ACTION);
context.startService(intent);
} catch (RuntimeException e) {
try {
getNotificationManager().cancel(notificationId);
} catch (NullPointerException e1) {
}
}
}
updateFastAdapter(MusicPlayer.messageId);
MusicPlayer.messageId = messageID;
MusicPlayer.musicPath = musicPath;
MusicPlayer.roomName = roomName;
mediaThumpnail = null;
MusicPlayer.roomId = roomId;
}
if (MusicPlayer.downloadNextMusic(messageId)) {
if (FragmentMediaPlayer.fastItemAdapter != null) {
FragmentMediaPlayer.fastItemAdapter.notifyAdapterDataSetChanged();
}
}
try {
if (mp != null) {
mp.setOnCompletionListener(null);
mp.stop();
mp.reset();
mp.release();
}
musicName = getMusicName(Long.parseLong(messageID), name);
mp = new MediaPlayer();
if (layoutTripMusic != null) {
layoutTripMusic.setVisibility(View.VISIBLE);
playerStateChangeListener.setValue(true);
MusicPlayer.playerStatusObservable.setValue(PLAY);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
mp.setDataSource(musicPath);
if (isNearDistance) {
mp.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
} else {
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
mp.prepare();
mp.start();
if (currentDuration > 0) {
mp.seekTo(currentDuration);
currentDuration = 0;
}
getMusicArtist();
updateFastAdapter(MusicPlayer.messageId);
musicTime = milliSecondsToTimer((long) mp.getDuration());
if (isVoice) {
// txt_music_info.setVisibility(View.GONE);
} else {
// txt_music_info.setVisibility(View.VISIBLE);
// txt_music_info.setText(musicInfoTitle);
}
updateName = new UpdateName() {
@Override
public void rename() {
musicName = getMusicName(Long.parseLong(messageID), name);
}
};
updateProgress();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
OnCompleteMusic();
}
});
if (onComplete != null) {
onComplete.complete(true, "update", "");
}
} catch (Exception e) {
e.printStackTrace();
}
if (!inChangeStreamType) {
updateNotification();
}
if (!isShowMediaPlayer) {
if (onCompleteChat != null) {
onCompleteChat.complete(true, "pause", "");
}
} else if (onComplete != null) {
onComplete.complete(true, "pause", "");
}
if (updateList || downloadNewItem) {
fillMediaList(true);
downloadNewItem = false;
}
if (HelperCalander.isPersianUnicode) {
// txt_music_time.setText(HelperCalander.convertToUnicodeFarsiNumber(txt_music_time.getText().toString()));
}
isMusicPlyerEnable = true;
inChangeStreamType = false;
if (MusicPlayer.chatLayout != null) {
MusicPlayer.chatLayout.setVisibility(View.VISIBLE);
}
if (MusicPlayer.mainLayout != null) {
MusicPlayer.mainLayout.setVisibility(View.VISIBLE);
}
if (MusicPlayer.shearedMediaLayout != null) {
MusicPlayer.shearedMediaLayout.setVisibility(View.VISIBLE);
}
EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.MEDIA_PLAYER_STATE_CHANGED, true);
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class UploadService method sendVoice.
private void sendVoice(final String savedPath, final Long mRoomId) {
ProtoGlobal.Room.Type chatType = RealmRoom.detectType(mRoomId);
RealmRoomMessage roomMessage = RealmRoomMessage.makeVoiceMessage(mRoomId, chatType, savedPath, "");
new Thread(() -> {
DbManager.getInstance().doRealmTransaction(realm1 -> {
realm1.copyToRealmOrUpdate(roomMessage);
RealmRoom.setLastMessageWithRoomMessage(realm1, mRoomId, roomMessage);
});
}).start();
UploadObject fileObject = UploadObject.createForMessage(roomMessage, chatType);
if (fileObject != null)
Uploader.getInstance().upload(fileObject);
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class ResendMessage method resend.
private void resend(final boolean all) {
if (!RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
return;
}
DbManager.getInstance().doRealmTask(realm -> {
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
for (MessageObject message : mMessages) {
if (all) {
RealmRoomMessage.setStatus(realm, message.id, ProtoGlobal.RoomMessageStatus.SENDING);
} else {
if (message.id == mSelectedMessageID) {
RealmRoomMessage.setStatus(realm, message.id, ProtoGlobal.RoomMessageStatus.SENDING);
break;
}
}
}
}
}, () -> {
if (all) {
mListener.resendAllMessages();
} else {
mListener.resendMessage();
}
for (int i = 0; i < mMessages.size(); i++) {
final int j = i;
if (all) {
if (FragmentChat.allowResendMessage(mMessages.get(j).id)) {
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
DbManager.getInstance().doRealmTask(realm1 -> {
RealmRoomMessage roomMessage = realm1.where(RealmRoomMessage.class).equalTo("messageId", mMessages.get(j).id).findFirst();
MessageObject resendMessageObject = MessageObject.create(roomMessage);
if (resendMessageObject != null) {
RealmRoom realmRoom = realm1.where(RealmRoom.class).equalTo("id", resendMessageObject.roomId).findFirst();
if (realmRoom != null) {
if (resendMessageObject.attachment == null) {
ProtoGlobal.Room.Type roomType = realmRoom.getType();
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(roomType, resendMessageObject.roomId, resendMessageObject);
} else {
if (resendMessageObject.additional != null && resendMessageObject.additional.type == 4) {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(realmRoom.getType(), resendMessageObject.roomId, resendMessageObject);
} else {
RealmRoomMessage message = realm.copyFromRealm(roomMessage);
UploadObject fileObject = UploadObject.createForMessage(message, realmRoom.getType());
if (fileObject != null) {
Uploader.getInstance().upload(fileObject);
}
}
}
}
}
});
}
}, 1000 * j);
}
} else {
if (mMessages.get(j).id == mSelectedMessageID) {
if (FragmentChat.allowResendMessage(mSelectedMessageID)) {
RealmRoomMessage roomMessage = realm.where(RealmRoomMessage.class).equalTo("messageId", mMessages.get(j).id).findFirst();
MessageObject resendMessageObject = MessageObject.create(roomMessage);
if (resendMessageObject != null) {
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", resendMessageObject.roomId).findFirst();
if (realmRoom != null) {
ProtoGlobal.Room.Type roomType = realmRoom.getType();
if (resendMessageObject.attachment == null) {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(roomType, resendMessageObject.roomId, resendMessageObject);
} else {
if (resendMessageObject.additional != null && resendMessageObject.additional.type == 4) {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(realmRoom.getType(), resendMessageObject.roomId, resendMessageObject);
} else {
RealmRoomMessage message = realm.copyFromRealm(roomMessage);
UploadObject fileObject = UploadObject.createForMessage(message, realmRoom.getType());
if (fileObject != null) {
Uploader.getInstance().upload(fileObject);
}
}
}
}
}
break;
}
}
}
}
});
});
}
Aggregations