use of net.iGap.realm.RealmRegisteredInfo in project iGap-Android by KianIranian-STDG.
the class MyInfoWindow method onOpen.
public void onOpen(final Object arg) {
/**
* change latest clicked user marker color to GRAY and new clicker to GREEN
*/
if (latestClickedMarker != null) {
latestClickedMarker.setIcon(FragmentiGapMap.avatarMark(latestClickedUserId, FragmentiGapMap.MarkerColor.GRAY));
}
marker.setIcon(FragmentiGapMap.avatarMark(userId, FragmentiGapMap.MarkerColor.GREEN));
latestClickedMarker = marker;
latestClickedUserId = userId;
/**
* don't show dialog for mine user
*/
if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
return;
}
String displayName = DbManager.getInstance().doRealmTask(realm2 -> {
RealmRegisteredInfo realmRegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(realm2, userId);
if (realmRegisteredInfo == null) {
RealmRegisteredInfo.getRegistrationInfo(userId, new OnInfo() {
@Override
public void onInfo(Long registeredId) {
G.handler.post(new Runnable() {
@Override
public void run() {
onOpen(arg);
}
});
}
});
return null;
}
return realmRegisteredInfo.getDisplayName();
});
if (displayName == null) {
return;
}
/* RealmCallConfig callConfig = realm.where(RealmCallConfig.class).findFirst();
if (callConfig != null) {
isCallEnable = callConfig.isVoice_calling();
isVideoCallEnable = callConfig.isVideo_calling();
}*/
final MaterialDialog dialog = new MaterialDialog.Builder(mActivity).customView(R.layout.map_user_info, true).build();
View view = dialog.getCustomView();
if (view == null) {
return;
}
DialogAnimation.animationDown(dialog);
dialog.show();
final CircleImageView avatar = view.findViewById(R.id.img_info_avatar_map);
final TextView txtClose = view.findViewById(R.id.txt_close_map);
final TextView txtBack = view.findViewById(R.id.txt_info_back_map);
final TextView txtOpenComment = view.findViewById(R.id.txt_open_comment_map);
final TextView txtChat = view.findViewById(R.id.txt_chat_map);
final TextView txtCall = view.findViewById(R.id.txt_call_map);
txtCall.setVisibility(isCallEnable ? View.VISIBLE : View.GONE);
final TextView txtVideoCall = view.findViewById(R.id.txt_video_call_map);
txtVideoCall.setVisibility(isVideoCallEnable ? View.VISIBLE : View.GONE);
TextView txtName = view.findViewById(R.id.txt_name_info_map);
final TextView txtComment = view.findViewById(R.id.txt_info_comment);
txtName.setText(displayName);
txtName.setTypeface(ResourcesCompat.getFont(txtName.getContext(), R.font.main_font_bold), Typeface.BOLD);
if (!G.isAppRtl) {
txtComment.setGravity(Gravity.RIGHT);
txtOpenComment.setRotation(90);
} else {
txtComment.setGravity(Gravity.LEFT);
txtOpenComment.setRotation(270);
}
txtClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
txtBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txtBack.setVisibility(View.GONE);
txtClose.setVisibility(View.VISIBLE);
txtChat.setVisibility(View.VISIBLE);
if (isCallEnable) {
txtCall.setVisibility(View.VISIBLE);
}
if (isVideoCallEnable) {
txtVideoCall.setVisibility(View.VISIBLE);
}
txtOpenComment.setVisibility(View.VISIBLE);
txtComment.setMaxLines(1);
txtComment.setEllipsize(TextUtils.TruncateAt.END);
}
});
txtChat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
HelperPublicMethod.goToChatRoom(userId, new HelperPublicMethod.OnComplete() {
@Override
public void complete() {
// new HelperFragment(mActivity.getSupportFragmentManager(),fragmentiGapMap).remove();
}
}, null);
}
});
txtCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CallSelectFragment.call(userId, false, ProtoSignalingOffer.SignalingOffer.Type.VOICE_CALLING);
}
});
txtVideoCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CallSelectFragment.call(userId, false, ProtoSignalingOffer.SignalingOffer.Type.VIDEO_CALLING);
}
});
txtComment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (hasComment && comment != null) {
txtClose.setVisibility(View.GONE);
txtChat.setVisibility(View.GONE);
txtCall.setVisibility(View.GONE);
txtVideoCall.setVisibility(View.GONE);
txtOpenComment.setVisibility(View.GONE);
txtBack.setVisibility(View.VISIBLE);
txtComment.setMaxLines(Integer.MAX_VALUE);
txtComment.setEllipsize(null);
}
}
});
txtOpenComment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txtComment.performClick();
}
});
avatarHandler.getAvatar(new ParamWithAvatarType(avatar, userId).avatarType(AvatarHandler.AvatarType.USER).showMain());
if (hasComment) {
G.onGeoGetComment = new OnGeoGetComment() {
@Override
public void onGetComment(long userId, final String commentR) {
comment = commentR;
G.handler.post(new Runnable() {
@Override
public void run() {
txtComment.setText(commentR);
}
});
}
};
txtComment.setText(G.fragmentActivity.getResources().getString(R.string.comment_waiting));
new RequestGeoGetComment().getComment(userId);
} else {
txtComment.setText(G.fragmentActivity.getResources().getString(R.string.comment_no));
}
// for show old comment
//
// RealmGeoNearbyDistance realmGeoNearbyDistance = realm.where(RealmGeoNearbyDistance.class).equalTo("userId", userId).findFirst();
// if (realmGeoNearbyDistance != null && hasComment) {
// if (realmGeoNearbyDistance.getComment() != null && !realmGeoNearbyDistance.getComment().isEmpty()) {
// txtComment.setText(realmGeoNearbyDistance.getComment());
// }
// }
//
// if (hasComment) {
// txtComment.setText(G.fragmentActivity.getResources().getString(R.string.comment_waiting));
// new RequestGeoGetComment().getComment(userId);
// } else {
// txtComment.setText(G.fragmentActivity.getResources().getString(R.string.comment_no));
// }
}
use of net.iGap.realm.RealmRegisteredInfo in project iGap-Android by KianIranian-STDG.
the class LastSeenTimeUtil method updateLastSeenTime.
/**
* check lastSeen time and send to callback
*/
private static synchronized void updateLastSeenTime(Context context) {
DbManager.getInstance().doRealmTask(realm -> {
ArrayList<Long> userIdList = new ArrayList<>();
for (Iterator<Map.Entry<Long, Long>> it = hashMapLastSeen.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Long, Long> entry = it.next();
long userId = entry.getKey();
long value = entry.getValue();
RealmRegisteredInfo realmRegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(realm, userId);
if (realmRegisteredInfo != null) {
if (realmRegisteredInfo.getStatus() != null && realmRegisteredInfo.getMainStatus() != null && !realmRegisteredInfo.getMainStatus().equals(ProtoGlobal.RegisteredUser.Status.ONLINE.toString()) && !realmRegisteredInfo.getMainStatus().equals(ProtoGlobal.RegisteredUser.Status.LONG_TIME_AGO.toString())) {
String showLastSeen;
if (timeOut(realmRegisteredInfo.getLastSeen() * DateUtils.SECOND_IN_MILLIS)) {
showLastSeen = computeDays(context, realmRegisteredInfo.getLastSeen(), true);
userIdList.add(userId);
} else {
showLastSeen = getMinute(realmRegisteredInfo.getLastSeen());
}
if (G.onLastSeenUpdateTiming != null) {
G.onLastSeenUpdateTiming.onLastSeenUpdate(userId, showLastSeen);
}
} else {
userIdList.add(userId);
}
}
}
// i separate hashMap remove from iterator , because i guess remove in that iterator make bug in app , but i'm not insuring
for (long userId : userIdList) {
hashMapLastSeen.remove(userId);
}
userIdList.clear();
});
if (hashMapLastSeen.size() > 0) {
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
updateLastSeenTime(context);
}
}, Config.LAST_SEEN_DELAY_CHECKING);
}
}
use of net.iGap.realm.RealmRegisteredInfo in project iGap-Android by KianIranian-STDG.
the class FragmentContactsProfileViewModel method mainStart.
private void mainStart() {
if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || roomId == 0) {
RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
});
if (realmRoom != null) {
shearedId = realmRoom.getId();
}
} else {
shearedId = roomId;
}
if (!RealmRoom.isNotificationServices(roomId)) {
isShowReportView.set(true);
} else {
isShowReportView.set(false);
}
if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
cloudVisibility.postValue(true);
} else
cloudVisibility.postValue(false);
registeredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, userId);
});
if (registeredInfo != null) {
registeredInfo.addChangeListener((RealmObjectChangeListener<RealmRegisteredInfo>) (realmModel, changeSet) -> {
if (changeSet != null) {
for (int i = 0; i < changeSet.getChangedFields().length; i++) {
if (changeSet.getChangedFields()[i].equals("blockUser")) {
userBlockState.set(realmModel.isBlockUser() ? R.string.un_block_user : R.string.block);
}
}
}
});
isBot = registeredInfo.isBot();
if (isBot || userId == AccountManager.getInstance().getCurrentUser().getId()) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
callVisibility.setValue(View.VISIBLE);
menuVisibility.setValue(View.VISIBLE);
videoCallVisibility.setValue(View.VISIBLE);
}
isBlockUser = registeredInfo.isBlockUser();
userBlockState.set(isBlockUser ? R.string.un_block_user : R.string.block);
registeredInfo.addChangeListener(element -> isBlockUser = registeredInfo.isBlockUser());
DbManager.getInstance().doRealmTask(realm -> {
if (registeredInfo.getLastAvatar(realm) != null) {
String mainFilePath = registeredInfo.getLastAvatar(realm).getFile().getLocalFilePath();
if (mainFilePath != null && new File(mainFilePath).exists()) {
// if main image is exist showing that
avatarPath = mainFilePath;
} else {
avatarPath = registeredInfo.getLastAvatar(realm).getFile().getLocalThumbnailPath();
}
avatarList = registeredInfo.getAvatars(realm);
}
});
}
RealmContacts realmUser = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("id", userId).findFirst();
});
if (registeredInfo != null) {
if (registeredInfo.getDisplayName() != null && !registeredInfo.getDisplayName().equals("")) {
contactName.setValue(registeredInfo.getDisplayName());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
if (registeredInfo.getBio() == null || registeredInfo.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(registeredInfo.getBio());
}
username.set(registeredInfo.getUsername());
phone.set(registeredInfo.getPhoneNumber());
phoneNumber = "+" + registeredInfo.getPhoneNumber();
firstName = registeredInfo.getFirstName();
lastName = registeredInfo.getLastName();
lastSeenValue = registeredInfo.getLastSeen();
color = registeredInfo.getColor();
initials = registeredInfo.getInitials();
userStatus = registeredInfo.getStatus();
isVerified = registeredInfo.isVerified();
} else if (realmUser != null) {
if (realmUser.getDisplay_name() != null && !realmUser.getDisplay_name().equals("")) {
contactName.setValue(realmUser.getDisplay_name());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
username.set(realmUser.getUsername());
phone.set(Long.toString(realmUser.getPhone()));
phoneNumber = "+" + realmUser.getPhone();
firstName = realmUser.getFirst_name();
lastName = realmUser.getLast_name();
lastSeenValue = realmUser.getLast_seen();
color = realmUser.getColor();
initials = realmUser.getInitials();
isVerified = realmUser.isVerified();
if (realmUser.getBio() == null || realmUser.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(realmUser.getBio());
}
}
if (isVerified) {
verifyTextVisibility.set(View.VISIBLE);
} else {
verifyTextVisibility.set(View.INVISIBLE);
}
// todo: fixed it two times check it and first and her
if (userId != 134 && AccountManager.getInstance().getCurrentUser().getId() != userId) {
RealmCallConfig callConfig = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmCallConfig.class).findFirst();
});
if (callConfig != null) {
if (isBot) {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
if (callConfig.isVoice_calling()) {
callVisibility.setValue(View.VISIBLE);
}
if (callConfig.isVideo_calling()) {
videoCallVisibility.setValue(View.VISIBLE);
}
}
} else {
new RequestSignalingGetConfiguration().signalingGetConfiguration();
}
} else {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
RealmContacts realmContacts = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("phone", Long.parseLong(phone.get())).findFirst();
});
/**
* if this user isn't in my contacts don't show phone number
*/
if (realmContacts == null && enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString())) {
showNumber.set(false);
disableDeleteContact = true;
menuVisibility.setValue(View.GONE);
}
if (!G.isAppRtl) {
textsGravity.set(Gravity.LEFT);
} else {
textsGravity.set(Gravity.RIGHT);
}
setUserStatus(userStatus, lastSeenValue);
setAvatar.setValue(userId != AccountManager.getInstance().getCurrentUser().getId());
// todo: change it
FragmentShearedMedia.getCountOfSharedMedia(shearedId);
if (registeredInfo == null) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
}
use of net.iGap.realm.RealmRegisteredInfo in project iGap-Android by KianIranian-STDG.
the class CallManager method setupCallerInfo.
private void setupCallerInfo(long callPeerId) {
currentCallerInfo = new CallerInfo();
DbManager.getInstance().doRealmTask(realm -> {
RealmRegisteredInfo realmRegisteredInfo = realm.where(RealmRegisteredInfo.class).equalTo("id", callPeerId).findFirst();
if (realmRegisteredInfo != null) {
currentCallerInfo.name = realmRegisteredInfo.getDisplayName();
currentCallerInfo.color = realmRegisteredInfo.getColor();
}
currentCallerInfo.userId = callPeerId;
});
}
use of net.iGap.realm.RealmRegisteredInfo in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method updateOwnViews.
public void updateOwnViews(List<ProtoStoryGetOwnStoryViews.GroupedViews> groupedViews) {
CountDownLatch countdown = new CountDownLatch(1);
storageQueue.postRunnable(() -> {
try {
database.executeTransaction(realm -> {
int counter = 0;
for (int i = 0; i < groupedViews.size(); i++) {
// for (int j = 0; j < groupedViews.get(i).getStoryViewsList().size(); j++) {
// if (groupedViews.get(i).getStoryViewsList().get(j).getUserId() != AccountManager.getInstance().getCurrentUser().getId()) {
// counter++;
// }
// }
RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", groupedViews.get(i).getStoryId()).findFirst();
if (realmStoryProto != null) {
// realmStoryProto.setViewCount(counter);
boolean isExist = false;
for (int j = 0; j < groupedViews.get(i).getStoryViewsList().size(); j++) {
RealmRegisteredInfo realmRegisteredInfo = database.where(RealmRegisteredInfo.class).equalTo("id", groupedViews.get(i).getStoryViewsList().get(j).getUserId()).findFirst();
RealmStoryViewInfo realmStoryViewInfo;
realmStoryViewInfo = realm.where(RealmStoryViewInfo.class).equalTo("id", groupedViews.get(i).getStoryId()).equalTo("userId", groupedViews.get(i).getStoryViewsList().get(j).getUserId()).findFirst();
if (realmStoryViewInfo == null) {
realmStoryViewInfo = realm.createObject(RealmStoryViewInfo.class);
} else {
isExist = true;
}
if (realmRegisteredInfo == null) {
realmStoryViewInfo.setDisplayName("");
new RequestUserInfo().userInfo(groupedViews.get(i).getStoryViewsList().get(j).getUserId());
} else {
realmStoryViewInfo.setDisplayName(realmRegisteredInfo.getDisplayName());
realmStoryViewInfo.setProfileColor(realmRegisteredInfo.getColor());
}
realmStoryViewInfo.setId(groupedViews.get(i).getStoryId());
realmStoryViewInfo.setUserId(groupedViews.get(i).getStoryViewsList().get(j).getUserId());
realmStoryViewInfo.setCreatedTime(groupedViews.get(i).getStoryViewsList().get(j).getViewedAt());
if (isExist) {
realmStoryProto.getRealmStoryViewInfos().remove(realmStoryViewInfo);
}
realmStoryProto.getRealmStoryViewInfos().add(realmStoryViewInfo);
isExist = false;
}
}
counter = 0;
}
});
G.runOnUiThread(() -> getEventManager().postEvent(EventManager.STORY_VIEWS_FETCHED));
countdown.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countdown.countDown();
}
});
try {
countdown.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations