use of net.iGap.realm.RealmGroupRoom in project iGap-Android by KianIranian-STDG.
the class FragmentChat method initMain.
private void initMain() {
HelperGetMessageState.clearMessageViews();
initPinedMessage();
viewMicRecorder = rootView.findViewById(R.id.layout_mic_recorde);
prgWaiting = rootView.findViewById(R.id.chl_prgWaiting);
AppUtils.setProgresColler(prgWaiting);
voiceRecord = new VoiceRecord(G.fragmentActivity, viewMicRecorder, viewAttachFile, this);
prgWaiting.setVisibility(View.VISIBLE);
txtEmptyMessages = rootView.findViewById(R.id.empty_messages);
if (isBot) {
txtEmptyMessages.setText(G.fragmentActivity.getResources().getString(R.string.empty_text_dr_bot));
txtChannelMute.setText(R.string.start);
iconChannelMute.setText("");
}
lastDateCalendar.clear();
locationManager = (LocationManager) G.fragmentActivity.getSystemService(LOCATION_SERVICE);
/**
* Hint: don't need to get info here. currently do this action in {{@link #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");
* }
*/
/**
* get userId . use in chat set action.
*/
RealmUserInfo realmUserInfo = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmUserInfo.class).findFirst();
});
if (realmUserInfo == null) {
// finish();
finishChat();
return;
}
userId = realmUserInfo.getUserId();
managedRoom = getRoom();
if (managedRoom != null) {
// room exist
title = managedRoom.getTitle();
initialize = managedRoom.getInitials();
color = managedRoom.getColor();
isChatReadOnly = managedRoom.getReadOnly();
unreadCount = managedRoom.getUnreadCount();
savedScrollMessageId = managedRoom.getLastScrollPositionMessageId();
savedScrollDocumentId = managedRoom.getLastScrollPositionDocumentId();
firstVisiblePositionOffset = managedRoom.getLastScrollPositionOffset();
if (messageId != 0) {
savedScrollMessageId = messageId;
savedScrollDocumentId = documentId;
firstVisiblePositionOffset = 0;
}
if (chatType == CHAT) {
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
if (realmRegisteredInfo != null) {
initialize = realmRegisteredInfo.getInitials();
color = realmRegisteredInfo.getColor();
phoneNumber = realmRegisteredInfo.getPhoneNumber();
if (realmRegisteredInfo.getId() == Config.drIgapPeerId) {
// if (realmRegisteredInfo.getUsername().equalsIgnoreCase("")) {
initDrBot();
}
} else {
title = managedRoom.getTitle();
initialize = managedRoom.getInitials();
color = managedRoom.getColor();
userStatus = G.fragmentActivity.getResources().getString(R.string.last_seen_recently);
}
} else if (chatType == GROUP) {
RealmGroupRoom realmGroupRoom = managedRoom.getGroupRoom();
groupRole = realmGroupRoom.getRole();
groupParticipantsCountLabel = realmGroupRoom.getParticipantsCountLabel();
} else if (chatType == CHANNEL) {
RealmChannelRoom realmChannelRoom = managedRoom.getChannelRoom();
channelRole = realmChannelRoom.getRole();
channelParticipantsCountLabel = realmChannelRoom.getParticipantsCountLabel();
}
} else {
// chatPeerId = extras.getLong("peerId");
chatType = CHAT;
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
if (realmRegisteredInfo != null) {
title = realmRegisteredInfo.getDisplayName();
initialize = realmRegisteredInfo.getInitials();
color = realmRegisteredInfo.getColor();
lastSeen = realmRegisteredInfo.getLastSeen();
userStatus = realmRegisteredInfo.getStatus();
}
}
initComponent();
initAppbarSelected();
getDraft();
getUserInfo();
insertSharedData();
if (structIGSticker != null) {
G.handler.postDelayed(() -> sendStickerAsMessage(structIGSticker), 1000);
}
RealmRoomMessage rm = null;
RealmResults<RealmRoomMessage> result = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoomMessage.class).equalTo("roomId", mRoomId).findAll();
});
if (result.size() > 0) {
rm = result.last();
if (rm != null && rm.getMessage() != null) {
if (rm.getRealmAdditional() != null && (rm.getRealmAdditional().getAdditionalType() == Additional.WEB_VIEW.getAdditional())) {
String additionalData = rm.getRealmAdditional().getAdditionalData();
if (!additionalData.isEmpty())
openWebViewForSpecialUrlChat(additionalData);
}
}
}
FragmentShearedMedia.goToPositionFromShardMedia = new FragmentShearedMedia.GoToPositionFromShardMedia() {
@Override
public void goToPosition(Long messageId, long documentId) {
if (messageId != 0) {
savedScrollMessageId = messageId;
savedScrollDocumentId = documentId;
firstVisiblePositionOffset = 0;
if (goToPositionWithAnimation(savedScrollMessageId, 2000)) {
savedScrollMessageId = 0;
savedScrollDocumentId = 0;
} else {
RealmRoomMessage rm = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoomMessage.class).equalTo("messageId", messageId).findFirst();
});
rm = RealmRoomMessage.getFinalMessage(rm);
if (rm != null) {
resetMessagingValue();
savedScrollMessageId = FragmentChat.messageId = messageId;
savedScrollDocumentId = FragmentChat.documentId = documentId;
firstVisiblePositionOffset = 0;
getMessages();
}
}
}
}
};
sendChatTracker();
}
use of net.iGap.realm.RealmGroupRoom in project iGap-Android by KianIranian-STDG.
the class FragmentGroupProfileViewModel method init.
public void init(FragmentGroupProfile fragmentGroupProfile, long roomId, boolean isNotJoin) {
this.fragment = fragmentGroupProfile;
this.roomId = roomId;
this.isNotJoin = isNotJoin;
// group info
realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("id", roomId).findFirst();
});
if (realmRoom == null || realmRoom.getGroupRoom() == null) {
goBack.setValue(true);
return;
}
RealmGroupRoom realmGroupRoom = realmRoom.getGroupRoom();
groupName.setValue(realmRoom.getTitle());
groupNumber.setValue(HelperCalander.isPersianUnicode ? HelperCalander.convertToUnicodeFarsiNumber(realmGroupRoom.getParticipantsCountLabel()) : realmGroupRoom.getParticipantsCountLabel());
role = realmGroupRoom.getRole();
isPrivate = realmGroupRoom.isPrivate();
initials = realmRoom.getInitials();
color = realmRoom.getColor();
isUnMuteNotification.set(realmRoom.getMute());
inviteLink.set(realmGroupRoom.getInvite_link());
linkUsername = realmGroupRoom.getUsername();
if (realmGroupRoom.getDescription() != null && !realmGroupRoom.getDescription().isEmpty()) {
haveDescription.set(View.VISIBLE);
groupDescription.setValue(realmGroupRoom.getDescription());
} else {
haveDescription.set(View.GONE);
}
setTextGroupLik();
// OWNER,ADMIN,MODERATOR,MEMBER can add member to group
showLeaveGroup.set(role != GroupChatRole.OWNER ? View.VISIBLE : View.GONE);
showMoreMenu.setValue(!isNotJoin);
FragmentShearedMedia.getCountOfSharedMedia(roomId);
onGroupAddMemberCallback();
if (realmRoom != null) {
realmRoom.addChangeListener((realmModel, changeSet) -> {
if (changeSet != null) {
if (changeSet.isDeleted()) {
goToRoomListPage.setValue(true);
} else if (((RealmRoom) realmModel).isValid()) {
isUnMuteNotification.set(realmRoom.getMute());
String countText = ((RealmRoom) realmModel).getSharedMediaCount();
groupName.postValue(realmRoom.getTitle());
groupDescription.postValue(realmRoom.getGroupRoom().getDescription());
if (HelperCalander.isPersianUnicode) {
countText = HelperCalander.convertToUnicodeFarsiNumber(countText);
}
if (countText == null || countText.length() == 0) {
noMediaSharedVisibility.set(View.GONE);
} else {
String[] countList = countText.split("\n");
int countOFImage = Integer.parseInt(countList[0]);
int countOFVIDEO = Integer.parseInt(countList[1]);
int countOFAUDIO = Integer.parseInt(countList[2]);
int countOFVOICE = Integer.parseInt(countList[3]);
int countOFGIF = Integer.parseInt(countList[4]);
int countOFFILE = Integer.parseInt(countList[5]);
int countOFLink = Integer.parseInt(countList[6]);
if (countOFImage > 0 || countOFVIDEO > 0 || countOFAUDIO > 0 || countOFVOICE > 0 || countOFGIF > 0 || countOFFILE > 0 || countOFLink > 0) {
noMediaSharedVisibility.set(View.VISIBLE);
if (countOFImage > 0) {
sharedPhotoVisibility.set(View.VISIBLE);
sharedPhotoCount.set(countOFImage);
} else {
sharedPhotoVisibility.set(View.GONE);
}
if (countOFVIDEO > 0) {
sharedVideoVisibility.set(View.VISIBLE);
sharedVideoCount.set(countOFVIDEO);
} else {
sharedVideoVisibility.set(View.GONE);
}
if (countOFAUDIO > 0) {
sharedAudioVisibility.set(View.VISIBLE);
sharedAudioCount.set(countOFAUDIO);
} else {
sharedAudioVisibility.set(View.GONE);
}
if (countOFVOICE > 0) {
sharedVoiceVisibility.set(View.VISIBLE);
sharedVoiceCount.set(countOFVOICE);
} else {
sharedVoiceVisibility.set(View.GONE);
}
if (countOFGIF > 0) {
sharedGifVisibility.set(View.VISIBLE);
sharedGifCount.set(countOFGIF);
} else {
sharedGifVisibility.set(View.GONE);
}
if (countOFFILE > 0) {
sharedFileVisibility.set(View.VISIBLE);
sharedFileCount.set(countOFFILE);
} else {
sharedFileVisibility.set(View.GONE);
}
if (countOFLink > 0) {
sharedLinkVisibility.set(View.VISIBLE);
sharedLinkCount.set(countOFLink);
} else {
sharedLinkVisibility.set(View.GONE);
}
} else {
noMediaSharedVisibility.set(View.GONE);
}
}
}
}
});
} else {
noMediaSharedVisibility.set(View.GONE);
}
}
Aggregations