Search in sources :

Example 6 with RequestChatGetRoom

use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.

the class UserProfileViewModel method onCloudMessageClick.

public void onCloudMessageClick() {
    showLoading.set(View.VISIBLE);
    retryRequestTime++;
    RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
        long userId = (userInfo != null && userInfo.getUserId() > 0) ? userInfo.getUserId() : AccountManager.getInstance().getCurrentUser().getId();
        return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
    });
    if (realmRoom != null) {
        showLoading.set(View.GONE);
        goToChatPage.setValue(new GoToChatModel(realmRoom.getId(), userInfo.getUserId()));
    } else {
        if (retryRequestTime < 3) {
            new RequestChatGetRoom().chatGetRoom((userInfo != null && userInfo.getUserId() > 0) ? userInfo.getUserId() : AccountManager.getInstance().getCurrentUser().getId(), new RequestChatGetRoom.OnChatRoomReady() {

                @Override
                public void onReady(ProtoGlobal.Room room) {
                    RealmRoom.putOrUpdate(room);
                    G.handler.post(() -> {
                        G.refreshRealmUi();
                        showLoading.set(View.GONE);
                        goToChatPage.postValue(new GoToChatModel(room.getId(), userInfo.getUserId()));
                    });
                }

                @Override
                public void onError(int majorCode, int minorCode) {
                    if (majorCode == 5 && minorCode == 1) {
                        G.runOnUiThread(() -> {
                            showError.postValue(R.string.connection_error);
                            showLoading.set(View.GONE);
                        });
                    } else {
                        G.runOnUiThread(() -> {
                            showError.postValue(R.string.error);
                            showLoading.set(View.GONE);
                        });
                    }
                }
            });
        } else {
            showLoading.set(View.GONE);
            showError.setValue(R.string.error);
            retryRequestTime = -1;
        }
    }
}
Also used : RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmRoom(net.iGap.realm.RealmRoom)

Example 7 with RequestChatGetRoom

use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.

the class FragmentContactsProfileViewModel method onClickGoToChat.

public void onClickGoToChat() {
    if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || enterFrom.equals("Others")) {
        // Others is from FragmentMapUsers adapter
        RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
            return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
        });
        if (realmRoom != null) {
            goToChatPage.setValue(realmRoom.getId());
        } else {
            new RequestChatGetRoom().chatGetRoom(userId, new RequestChatGetRoom.OnChatRoomReady() {

                @Override
                public void onReady(ProtoGlobal.Room room) {
                    DbManager.getInstance().doRealmTransaction(realm -> {
                        RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm);
                        realmRoom1.setDeleted(true);
                    });
                    G.handler.post(new Runnable() {

                        @Override
                        public void run() {
                            G.refreshRealmUi();
                            goToChatPage.setValue(room.getId());
                        }
                    });
                }

                @Override
                public void onError(int major, int minor) {
                }
            });
        }
    } else {
        goBack.setValue(true);
    }
}
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) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmRoom(net.iGap.realm.RealmRoom)

Example 8 with RequestChatGetRoom

use of net.iGap.request.RequestChatGetRoom in project iGap-Android by KianIranian-STDG.

the class SearchFragment method goToRoomWithRealm.

public void goToRoomWithRealm(RealmRoom realmRoom, SearchType type, long id, long messageId) {
    if (realmRoom != null) {
        G.refreshRealmUi();
        if (type == SearchType.message) {
            new GoToChatActivity(realmRoom.getId()).setMessageID(messageId).startActivity(getActivity());
        } else {
            new GoToChatActivity(realmRoom.getId()).startActivity(getActivity());
        }
    } else {
        new RequestChatGetRoom().chatGetRoom(id, new RequestChatGetRoom.OnChatRoomReady() {

            @Override
            public void onReady(ProtoGlobal.Room room) {
                G.runOnUiThread(() -> DbManager.getInstance().doRealmTransaction(realm -> {
                    RealmRoom room2 = RealmRoom.putOrUpdate(room, realm);
                    room2.setDeleted(true);
                }));
                if (getActivity() != null && getActivity().getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
                    new GoToChatActivity(room.getId()).setPeerID(id).setMessageID(messageId).startActivity(getActivity());
            }

            @Override
            public void onError(int major, int minor) {
            }
        });
    }
}
Also used : RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) ProtoGlobal(net.iGap.proto.ProtoGlobal) GoToChatActivity(net.iGap.helper.GoToChatActivity) RealmRoom(net.iGap.realm.RealmRoom)

Aggregations

RequestChatGetRoom (net.iGap.request.RequestChatGetRoom)8 RealmRoom (net.iGap.realm.RealmRoom)7 ProtoGlobal (net.iGap.proto.ProtoGlobal)6 DbManager (net.iGap.module.accountManager.DbManager)4 OnChatGetRoom (net.iGap.observers.interfaces.OnChatGetRoom)4 Realm (io.realm.Realm)3 RequestClientGetRoom (net.iGap.request.RequestClientGetRoom)3 Bundle (android.os.Bundle)2 Gravity (android.view.Gravity)2 View (android.view.View)2 ArrayList (java.util.ArrayList)2 G (net.iGap.G)2 FragmentContactsProfile (net.iGap.fragments.FragmentContactsProfile)2 ProtoClientGetRoom (net.iGap.proto.ProtoClientGetRoom)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Color (android.graphics.Color)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1