Search in sources :

Example 1 with OnClientGetRoomResponse

use of net.iGap.observers.interfaces.OnClientGetRoomResponse in project iGap-Android by KianIranian-STDG.

the class FragmentNewGroupViewModel method getRoom.

private void getRoom(final long roomId, final ProtoGlobal.Room.Type typeCreate, boolean isGroup) {
    G.onClientGetRoomResponse = new OnClientGetRoomResponse() {

        @Override
        public void onClientGetRoomResponse(final ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
            if (identity.createRoomMode != RequestClientGetRoom.CreateRoomMode.requestFromOwner) {
                return;
            }
            try {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        if (existAvatar) {
                            showProgressBar();
                            if (room.getType() == ProtoGlobal.Room.Type.GROUP) {
                                new RequestGroupAvatarAdd().groupAvatarAdd(roomId, token);
                            } else {
                                new RequestChannelAvatarAdd().channelAvatarAdd(roomId, token);
                            }
                        } else {
                            hideProgressBar();
                            if (isGroup) {
                                createdRoomId.postValue(roomId);
                            } else {
                                goToContactGroupPage.setValue(new ContactGroupFragmentModel(roomId, room.getGroupRoomExtra().getParticipantsCountLimitLabel(), typeCreate.toString(), true));
                            }
                        }
                    }
                });
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(int majorCode, int minorCode) {
            hideProgressBar();
        }

        @Override
        public void onTimeOut() {
            hideProgressBar();
        }
    };
    new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
}
Also used : RequestChannelAvatarAdd(net.iGap.request.RequestChannelAvatarAdd) ProtoGlobal(net.iGap.proto.ProtoGlobal) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) RequestGroupAvatarAdd(net.iGap.request.RequestGroupAvatarAdd)

Example 2 with OnClientGetRoomResponse

use of net.iGap.observers.interfaces.OnClientGetRoomResponse in project iGap-Android by KianIranian-STDG.

the class FragmentNewGroupViewModel method getChannelRoom.

private void getChannelRoom(final long roomId) {
    G.onClientGetRoomResponse = new OnClientGetRoomResponse() {

        @Override
        public void onClientGetRoomResponse(final ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
            if (identity.createRoomMode != RequestClientGetRoom.CreateRoomMode.requestFromOwner) {
                return;
            }
            G.onClientGetRoomResponse = null;
            G.handler.post(new Runnable() {

                @Override
                public void run() {
                    mInviteLink = room.getChannelRoomExtra().getPrivateExtra().getInviteLink();
                    if (existAvatar) {
                        MessageController.getInstance(currentAccount).saveChannelAvatar(imagePath, room.getId());
                    } else {
                        hideProgressBar();
                        goToCreateChannelPage.setValue(new CreateChannelModel(room.getId(), mInviteLink, token));
                    }
                }
            });
        }

        @Override
        public void onError(int majorCode, int minorCode) {
            G.onClientGetRoomResponse = null;
        }

        @Override
        public void onTimeOut() {
            G.onClientGetRoomResponse = null;
        }
    };
    new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
}
Also used : RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) ProtoGlobal(net.iGap.proto.ProtoGlobal) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse)

Example 3 with OnClientGetRoomResponse

use of net.iGap.observers.interfaces.OnClientGetRoomResponse in project iGap-Android by KianIranian-STDG.

the class HelperUrl method goToActivityFromFCM.

public static void goToActivityFromFCM(FragmentActivity activity, final long roomId, final long peerId) {
    if (roomId != FragmentChat.lastChatRoomId) {
        DbManager.getInstance().doRealmTask(realm -> {
            RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", roomId).findFirst();
            if (realmRoom != null) {
                // room with given roomID exists.
                new GoToChatActivity(realmRoom.getId()).startActivity(activity);
            } else if (peerId > 0) {
                realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", peerId).findFirst();
                if (realmRoom != null) {
                    new GoToChatActivity(realmRoom.getId()).startActivity(activity);
                } else {
                    G.onChatGetRoom = new OnChatGetRoom() {

                        @Override
                        public void onChatGetRoom(final ProtoGlobal.Room room) {
                            DbManager.getInstance().doRealmTask(new DbManager.RealmTask() {

                                @Override
                                public void doTask(Realm realm1) {
                                    realm1.executeTransaction(new Realm.Transaction() {

                                        @Override
                                        public void execute(Realm realm) {
                                            if (realm.where(RealmRoom.class).equalTo("id", room.getId()).findFirst() == null) {
                                                RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm);
                                                realmRoom1.setDeleted(true);
                                            } else {
                                                RealmRoom.putOrUpdate(room, realm);
                                            }
                                        }
                                    });
                                }
                            });
                            G.handler.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
                                    G.onChatGetRoom = null;
                                }
                            }, 500);
                        }

                        @Override
                        public void onChatGetRoomTimeOut() {
                        }

                        @Override
                        public void onChatGetRoomError(int majorCode, int minorCode) {
                        }
                    };
                    new RequestChatGetRoom().chatGetRoom(peerId);
                }
            } else {
                G.onClientGetRoomResponse = new OnClientGetRoomResponse() {

                    @Override
                    public void onClientGetRoomResponse(ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
                        G.onClientGetRoomResponse = null;
                        G.handler.postDelayed(() -> {
                            new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
                            G.onChatGetRoom = null;
                        }, 500);
                    }

                    @Override
                    public void onError(int majorCode, int minorCode) {
                    }

                    @Override
                    public void onTimeOut() {
                    }
                };
                new RequestClientGetRoom().clientGetRoom(roomId, null);
                Toast.makeText(activity, "Please Wait...", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) SpannableStringBuilder(android.text.SpannableStringBuilder) DbManager(net.iGap.module.accountManager.DbManager) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) RealmRoom(net.iGap.realm.RealmRoom) ProtoClientGetRoom(net.iGap.proto.ProtoClientGetRoom) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmRoom(net.iGap.realm.RealmRoom) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) ProtoClientGetRoom(net.iGap.proto.ProtoClientGetRoom) Realm(io.realm.Realm)

Example 4 with OnClientGetRoomResponse

use of net.iGap.observers.interfaces.OnClientGetRoomResponse in project iGap-Android by KianIranian-STDG.

the class HelperGetOwnerInfo method checkRoomExist.

private static void checkRoomExist(long id, final Listener listener) {
    DbManager.getInstance().doRealmTask(realm -> {
        RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", id).findFirst();
        if (realmRoom == null) {
            G.onClientGetRoomResponse = new OnClientGetRoomResponse() {

                @Override
                public void onClientGetRoomResponse(ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
                    if (identity.createRoomMode == RequestClientGetRoom.CreateRoomMode.requestFromOwner) {
                        if (listener != null) {
                            listener.OnResponse();
                        }
                    }
                }

                @Override
                public void onError(int majorCode, int minorCode) {
                }

                @Override
                public void onTimeOut() {
                }
            };
            new RequestClientGetRoom().clientGetRoom(id, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
        } else {
            if (listener != null) {
                listener.OnResponse();
            }
        }
    });
}
Also used : RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmRoom(net.iGap.realm.RealmRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse)

Aggregations

OnClientGetRoomResponse (net.iGap.observers.interfaces.OnClientGetRoomResponse)4 RequestClientGetRoom (net.iGap.request.RequestClientGetRoom)4 ProtoGlobal (net.iGap.proto.ProtoGlobal)3 RealmRoom (net.iGap.realm.RealmRoom)2 SpannableStringBuilder (android.text.SpannableStringBuilder)1 Realm (io.realm.Realm)1 DbManager (net.iGap.module.accountManager.DbManager)1 OnChatGetRoom (net.iGap.observers.interfaces.OnChatGetRoom)1 ProtoClientGetRoom (net.iGap.proto.ProtoClientGetRoom)1 RequestChannelAvatarAdd (net.iGap.request.RequestChannelAvatarAdd)1 RequestChatGetRoom (net.iGap.request.RequestChatGetRoom)1 RequestGroupAvatarAdd (net.iGap.request.RequestGroupAvatarAdd)1