Search in sources :

Example 1 with RealmRoom

use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method forwardMessageIfNeeded.

@CallSuper
protected void forwardMessageIfNeeded(VH holder) {
    NewChatItemHolder mHolder;
    if (holder instanceof NewChatItemHolder)
        mHolder = (NewChatItemHolder) holder;
    else
        return;
    /**
     * set forward container visible if message was forwarded, otherwise, gone it
     */
    View cslr_ll_forward22 = ((NewChatItemHolder) holder).getContentBloke().findViewById(R.id.cslr_ll_forward);
    if (cslr_ll_forward22 != null) {
        mHolder.getContentBloke().removeView(cslr_ll_forward22);
    }
    if (messageObject.forwardedMessage != null) {
        View forwardView = ViewMaker.getViewForward(((NewChatItemHolder) holder).getContext());
        forwardView.setOnLongClickListener(getLongClickPerform(holder));
        forwardView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (FragmentChat.isInSelectionMode) {
                    holder.itemView.performLongClick();
                } else {
                    // TODO: 12/29/20 MESSAGE_REFACTOR
                    if (messageObject.username != null && messageObject.username.length() > 0) {
                        // TODO: fixed this and do not use G.currentActivity
                        HelperUrl.checkUsernameAndGoToRoomWithMessageId(G.currentActivity, messageObject.username, HelperUrl.ChatEntry.profile, (messageObject.forwardedMessage.id * (-1)), messageObject.forwardedMessage.documentId);
                    }
                }
            }
        });
        AppCompatTextView txtPrefixForwardFrom = forwardView.findViewById(R.id.cslr_txt_prefix_forward);
        txtPrefixForwardFrom.setTypeface(ResourcesCompat.getFont(txtPrefixForwardFrom.getContext(), R.font.main_font));
        AppCompatTextView txtForwardFrom = forwardView.findViewById(R.id.cslr_txt_forward_from);
        txtForwardFrom.setTypeface(ResourcesCompat.getFont(txtPrefixForwardFrom.getContext(), R.font.main_font));
        /**
         * if forward message from chat or group , sender is user
         * but if message forwarded from channel sender is room
         */
        RealmRegisteredInfo info = DbManager.getInstance().doRealmTask(realm -> {
            return RealmRegisteredInfo.getRegistrationInfo(realm, messageObject.forwardedMessage.userId);
        });
        // TODO: 12/29/20 MESSAGE_REFACTOR
        if (info != null) {
            if (RealmRegisteredInfo.needUpdateUser(info.getId(), info.getCacheId())) {
                if (!updateForwardInfo.containsKey(info.getId())) {
                    updateForwardInfo.put(info.getId(), messageObject.id + "");
                }
            }
            txtForwardFrom.setText(EmojiManager.getInstance().replaceEmoji(info.getDisplayName(), txtForwardFrom.getPaint().getFontMetricsInt()));
            if (info.getUsername() != null)
                messageObject.username = info.getUsername();
            txtForwardFrom.setTextColor(theme.getForwardFromTextColor(txtForwardFrom.getContext()));
        } else if (messageObject.forwardedMessage.userId != 0) {
            if (RealmRegisteredInfo.needUpdateUser(messageObject.forwardedMessage.userId, null)) {
                if (!updateForwardInfo.containsKey(messageObject.forwardedMessage.userId)) {
                    updateForwardInfo.put(messageObject.forwardedMessage.userId, messageObject.id + "");
                }
            }
        } else {
            RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
                return realm.where(RealmRoom.class).equalTo("id", messageObject.forwardedMessage.roomId).findFirst();
            });
            if (realmRoom != null) {
                txtForwardFrom.setText(EmojiManager.getInstance().replaceEmoji(realmRoom.getTitle(), txtForwardFrom.getPaint().getFontMetricsInt()));
                txtForwardFrom.setTextColor(theme.getForwardFromTextColor(txtForwardFrom.getContext()));
                switch(realmRoom.getType()) {
                    case CHANNEL:
                        messageObject.username = realmRoom.getChannelRoom() != null ? realmRoom.getChannelRoom().getUsername() : "";
                        break;
                    case GROUP:
                        messageObject.username = realmRoom.getGroupRoom() != null ? realmRoom.getGroupRoom().getUsername() : "";
                        break;
                }
            } else {
                if (realmRoomForwardedFrom != null) {
                    switch(realmRoomForwardedFrom.getType()) {
                        case CHANNEL:
                            if (realmRoomForwardedFrom.getChannelRoom() != null && realmRoomForwardedFrom.getChannelRoom().getUsername() != null) {
                                messageObject.username = realmRoomForwardedFrom.getChannelRoom().getUsername();
                            } else {
                                messageObject.username = holder.itemView.getResources().getString(R.string.private_channel);
                            }
                            break;
                        case GROUP:
                            messageObject.username = realmRoomForwardedFrom.getGroupRoom().getUsername();
                            break;
                    }
                    if (RealmRoom.needUpdateRoomInfo(realmRoomForwardedFrom.getId())) {
                        if (!updateForwardInfo.containsKey(realmRoomForwardedFrom.getId())) {
                            updateForwardInfo.put(realmRoomForwardedFrom.getId(), messageObject.id + "");
                        }
                    }
                    txtForwardFrom.setText(EmojiManager.getInstance().replaceEmoji(realmRoomForwardedFrom.getTitle(), txtForwardFrom.getPaint().getFontMetricsInt()));
                    txtForwardFrom.setTextColor(theme.getForwardFromTextColor(txtForwardFrom.getContext()));
                } else {
                    if (RealmRoom.needUpdateRoomInfo(messageObject.forwardedMessage.roomId)) {
                        if (!updateForwardInfo.containsKey(messageObject.forwardedMessage.roomId)) {
                            updateForwardInfo.put(messageObject.forwardedMessage.roomId, messageObject.id + "");
                        }
                    }
                }
            }
        }
        // must call measure!
        txtPrefixForwardFrom.measure(0, 0);
        txtForwardFrom.measure(0, 0);
        int maxWith = txtPrefixForwardFrom.getMeasuredWidth() + txtForwardFrom.getMeasuredWidth() + i_Dp(R.dimen.dp32);
        if (minWith < maxWith) {
            minWith = maxWith;
        }
        mHolder.getContentBloke().setMinimumWidth(Math.min(minWith, G.maxChatBox));
        mHolder.getContentBloke().addView(forwardView, 0, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    }
}
Also used : NonNull(androidx.annotation.NonNull) FileLog(net.iGap.helper.FileLog) UploadObject(net.iGap.module.upload.UploadObject) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) IMAGE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE_VALUE) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) JSONException(org.json.JSONException) AdditionalType(net.iGap.module.additionalData.AdditionalType) HelperError(net.iGap.helper.HelperError) HelperFragment(net.iGap.helper.HelperFragment) Log(android.util.Log) ArrayMap(androidx.collection.ArrayMap) Realm(io.realm.Realm) HelperCalander(net.iGap.helper.HelperCalander) ChatSendMessageUtil(net.iGap.module.ChatSendMessageUtil) RealmRoom(net.iGap.realm.RealmRoom) Downloader(net.iGap.module.downloader.Downloader) Uploader(net.iGap.module.upload.Uploader) ViewMaker.i_Dp(net.iGap.adapter.items.chat.ViewMaker.i_Dp) Tuple(net.iGap.libs.Tuple) SHP_SETTING(net.iGap.module.SHP_SETTING) G.context(net.iGap.G.context) OnProgressUpdate(net.iGap.observers.interfaces.OnProgressUpdate) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) EventManager(net.iGap.observers.eventbus.EventManager) DownloadObject(net.iGap.module.downloader.DownloadObject) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) AttachmentObject(net.iGap.structs.AttachmentObject) HelperUrl(net.iGap.helper.HelperUrl) AbstractItem(com.mikepenz.fastadapter.items.AbstractItem) AccountManager(net.iGap.module.accountManager.AccountManager) ArrayList(java.util.ArrayList) OnMessageProgressClick(net.iGap.messageprogress.OnMessageProgressClick) ButtonActionType(net.iGap.module.additionalData.ButtonActionType) Toast(android.widget.Toast) LayoutCreator(net.iGap.helper.LayoutCreator) IMAGE_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE_TEXT_VALUE) HelperCheckInternetConnection(net.iGap.helper.HelperCheckInternetConnection) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) AUDIO(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO) SpannableString(android.text.SpannableString) MessageObject(net.iGap.structs.MessageObject) StyleSpan(android.text.style.StyleSpan) TextUtils(android.text.TextUtils) CallSuper(androidx.annotation.CallSuper) File(java.io.File) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) CardToCardHelper(net.iGap.helper.CardToCardHelper) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) AUDIO_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_VALUE) BetterLinkMovementMethod(me.saket.bettermovementmethod.BetterLinkMovementMethod) DbManager(net.iGap.module.accountManager.DbManager) FILE_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.FILE_TEXT_VALUE) LinearLayout(android.widget.LinearLayout) AppUtils(net.iGap.module.AppUtils) Spannable(android.text.Spannable) Theme(net.iGap.module.Theme) MessageProgress(net.iGap.messageprogress.MessageProgress) GIF_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.GIF_VALUE) G(net.iGap.G) LocalFileType(net.iGap.module.enums.LocalFileType) AndroidRuntimeException(android.util.AndroidRuntimeException) RealmUserInfo(net.iGap.realm.RealmUserInfo) JSONObject(org.json.JSONObject) AUDIO_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_TEXT_VALUE) IMessageItem(net.iGap.observers.interfaces.IMessageItem) Gson(com.google.gson.Gson) Locale(java.util.Locale) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) VIDEO_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO_VALUE) MessagesAdapter(net.iGap.adapter.MessagesAdapter) FILE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.FILE_VALUE) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) OnProgress(net.iGap.messageprogress.OnProgress) ViewGroup(android.view.ViewGroup) GIF_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.GIF_TEXT_VALUE) List(java.util.List) TextView(android.widget.TextView) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) MusicPlayer(net.iGap.module.MusicPlayer) G.isLocationFromBot(net.iGap.G.isLocationFromBot) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Typeface(android.graphics.Typeface) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) Context(android.content.Context) AndroidUtils(net.iGap.module.AndroidUtils) ResourcesCompat(androidx.core.content.res.ResourcesCompat) HelperGetMessageState(net.iGap.helper.HelperGetMessageState) MakeButtons(net.iGap.module.MakeButtons) HashMap(java.util.HashMap) Linkify(android.text.util.Linkify) TimeUtils(net.iGap.module.TimeUtils) AdditionalObject(net.iGap.structs.AdditionalObject) FragmentChat(net.iGap.fragments.FragmentChat) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmAdditional(net.iGap.realm.RealmAdditional) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) CardToCardValue(net.iGap.model.CardToCardValue) VOICE(net.iGap.proto.ProtoGlobal.RoomMessageType.VOICE) AUDIO_TEXT(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_TEXT) DialogAction(com.afollestad.materialdialogs.DialogAction) FragmentPaymentBill(net.iGap.fragments.FragmentPaymentBill) RequestManager(net.iGap.network.RequestManager) Color(android.graphics.Color) CountDownTimer(android.os.CountDownTimer) ButtonEntity(net.iGap.module.additionalData.ButtonEntity) ProtoGlobal(net.iGap.proto.ProtoGlobal) VIDEO_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO_TEXT_VALUE) VOICE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VOICE_VALUE) R(net.iGap.R) JSONArray(org.json.JSONArray) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) RealmRoom(net.iGap.realm.RealmRoom) ImageView(android.widget.ImageView) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) LinearLayout(android.widget.LinearLayout) CallSuper(androidx.annotation.CallSuper)

Example 2 with RealmRoom

use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method setMessage.

public AbstractMessage setMessage(MessageObject message) {
    // TODO: 12/29/20 MESSAGE_REFACTOR
    messageObject = message;
    attachment = messageObject.getAttachment();
    additional = messageObject.getAdditional();
    if ((messageObject.forwardedMessage != null)) {
        long messageId = messageObject.forwardedMessage.id;
        if (messageObject.forwardedMessage.id < 0) {
            messageId = messageId * (-1);
        }
        DbManager.getInstance().doRealmTask(realm -> {
            RealmRoom realmRoomForwardedFrom22 = realm.where(RealmRoom.class).equalTo("id", messageObject.forwardedMessage.roomId).findFirst();
            if (realmRoomForwardedFrom22 != null && realmRoomForwardedFrom22.isValid())
                realmRoomForwardedFrom = realm.copyFromRealm(realmRoomForwardedFrom22);
        });
    } else {
        realmRoomForwardedFrom = null;
    }
    if (messageObject.forwardedMessage != null) {
        myText = new SpannableString(messageObject.forwardedMessage.message);
    } else if (messageObject.message != null) {
        myText = new SpannableString(messageObject.message);
    } else {
        myText = new SpannableString("");
    }
    updateMessageText();
    return AbstractMessage.this;
}
Also used : SpannableString(android.text.SpannableString) RealmRoom(net.iGap.realm.RealmRoom)

Example 3 with RealmRoom

use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.

the class RoomListAdapter method createListener.

@Override
protected OrderedRealmCollectionChangeListener<RealmResults<RealmRoom>> createListener() {
    return (OrderedRealmCollectionChangeListener<RealmResults<RealmRoom>>) (collection, changeSet) -> {
        if (G.onUnreadChange != null) {
            int unreadCount = 0;
            for (RealmRoom room : collection) {
                if (!room.getMute() && !room.isDeleted() && room.getUnreadCount() > 0) {
                    unreadCount += room.getUnreadCount();
                }
            }
            G.onUnreadChange.onChange(unreadCount, false);
        }
        callBack.needShowEmptyView(getData() == null || getData().size() <= 0);
        if (changeSet.getState() == OrderedCollectionChangeSet.State.INITIAL) {
            callBack.needShowLoadProgress(false);
            notifyDataSetChanged();
            return;
        }
        // For deletions, the adapter has to be notified in reverse order.
        OrderedCollectionChangeSet.Range[] deletions = changeSet.getDeletionRanges();
        for (int i = deletions.length - 1; i >= 0; i--) {
            OrderedCollectionChangeSet.Range range = deletions[i];
            notifyItemRangeRemoved(range.startIndex, range.length);
        }
        if (deletions.length > 0 && selectedRoom.size() > 0) {
            selectedRoom.clear();
            callBack.needCheckMultiSelect();
        }
        OrderedCollectionChangeSet.Range[] insertions = changeSet.getInsertionRanges();
        for (OrderedCollectionChangeSet.Range range : insertions) {
            notifyItemRangeInserted(range.startIndex, range.length);
        }
        if (!updateOnModification) {
            return;
        }
        OrderedCollectionChangeSet.Range[] modifications = changeSet.getChangeRanges();
        for (OrderedCollectionChangeSet.Range range : modifications) {
            notifyItemRangeChanged(range.startIndex, range.length);
        }
    };
}
Also used : OrderedCollectionChangeSet(io.realm.OrderedCollectionChangeSet) OrderedRealmCollectionChangeListener(io.realm.OrderedRealmCollectionChangeListener) RealmRoom(net.iGap.realm.RealmRoom)

Example 4 with RealmRoom

use of net.iGap.realm.RealmRoom 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;
                        }
                    }
                }
            }
        });
    });
}
Also used : Context(android.content.Context) Realm(io.realm.Realm) MessageObject(net.iGap.structs.MessageObject) AccountManager(net.iGap.module.accountManager.AccountManager) UploadObject(net.iGap.module.upload.UploadObject) RealmRoom(net.iGap.realm.RealmRoom) IResendMessage(net.iGap.observers.interfaces.IResendMessage) RequestManager(net.iGap.network.RequestManager) Uploader(net.iGap.module.upload.Uploader) G(net.iGap.G) List(java.util.List) FragmentChat(net.iGap.fragments.FragmentChat) ProtoGlobal(net.iGap.proto.ProtoGlobal) MessageDataStorage(net.iGap.controllers.MessageDataStorage) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Activity(android.app.Activity) DbManager(net.iGap.module.accountManager.DbManager) ProtoGlobal(net.iGap.proto.ProtoGlobal) UploadObject(net.iGap.module.upload.UploadObject) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmRoom(net.iGap.realm.RealmRoom) Realm(io.realm.Realm) MessageObject(net.iGap.structs.MessageObject) RealmRoom(net.iGap.realm.RealmRoom)

Example 5 with RealmRoom

use of net.iGap.realm.RealmRoom 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);
    }
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) OnUserContactDelete(net.iGap.observers.interfaces.OnUserContactDelete) RealmChangeListener(io.realm.RealmChangeListener) AppUtils(net.iGap.module.AppUtils) RealmList(io.realm.RealmList) ObservableField(androidx.databinding.ObservableField) AccountManager(net.iGap.module.accountManager.AccountManager) ViewModel(androidx.lifecycle.ViewModel) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) RequestSignalingGetConfiguration(net.iGap.request.RequestSignalingGetConfiguration) G(net.iGap.G) RealmContacts(net.iGap.realm.RealmContacts) ArrayList(java.util.ArrayList) OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) View(android.view.View) ObservableBoolean(androidx.databinding.ObservableBoolean) OnUserContactEdit(net.iGap.observers.interfaces.OnUserContactEdit) RequestUserInfo(net.iGap.request.RequestUserInfo) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) GoToSharedMediaModel(net.iGap.model.GoToSharedMediaModel) HelperCalander(net.iGap.helper.HelperCalander) RealmModel(io.realm.RealmModel) RealmObjectChangeListener(io.realm.RealmObjectChangeListener) RealmRoom(net.iGap.realm.RealmRoom) RequestUserContactsDelete(net.iGap.request.RequestUserContactsDelete) File(java.io.File) OnUserUpdateStatus(net.iGap.observers.interfaces.OnUserUpdateStatus) RealmAvatar(net.iGap.realm.RealmAvatar) Gravity(android.view.Gravity) List(java.util.List) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) ProtoGlobal(net.iGap.proto.ProtoGlobal) FragmentShearedMedia(net.iGap.fragments.FragmentShearedMedia) ObservableInt(androidx.databinding.ObservableInt) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) RealmCallConfig(net.iGap.realm.RealmCallConfig) RealmCallConfig(net.iGap.realm.RealmCallConfig) RealmRoom(net.iGap.realm.RealmRoom) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) File(java.io.File) RequestSignalingGetConfiguration(net.iGap.request.RequestSignalingGetConfiguration) RealmContacts(net.iGap.realm.RealmContacts)

Aggregations

RealmRoom (net.iGap.realm.RealmRoom)80 ArrayList (java.util.ArrayList)28 ProtoGlobal (net.iGap.proto.ProtoGlobal)27 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)27 DbManager (net.iGap.module.accountManager.DbManager)26 View (android.view.View)23 G (net.iGap.G)23 List (java.util.List)19 R (net.iGap.R)19 SuppressLint (android.annotation.SuppressLint)18 TextView (android.widget.TextView)18 AccountManager (net.iGap.module.accountManager.AccountManager)18 RealmRegisteredInfo (net.iGap.realm.RealmRegisteredInfo)18 Bundle (android.os.Bundle)17 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)17 RecyclerView (androidx.recyclerview.widget.RecyclerView)16 AvatarHandler (net.iGap.helper.avatar.AvatarHandler)16 Context (android.content.Context)15 NonNull (androidx.annotation.NonNull)15 HelperFragment (net.iGap.helper.HelperFragment)15