Search in sources :

Example 1 with OnChatGetRoom

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

the class HelperUrl method goToActivity.

private static void goToActivity(FragmentActivity activity, final long roomId, final long peerId, ChatEntry chatEntry, final long messageId) {
    switch(chatEntry) {
        case chat:
            if (roomId != FragmentChat.lastChatRoomId) {
                DbManager.getInstance().doRealmTask(new DbManager.RealmTask() {

                    @Override
                    public void doTask(Realm realm) {
                        final RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", peerId).findFirst();
                        if (realmRoom != null) {
                            new GoToChatActivity(realmRoom.getId()).setMessageID(messageId).startActivity(activity);
                        } else {
                            G.onChatGetRoom = new OnChatGetRoom() {

                                @Override
                                public void onChatGetRoom(final ProtoGlobal.Room room) {
                                    DbManager.getInstance().doRealmTransaction(realm2 -> {
                                        if (realm2.where(RealmRoom.class).equalTo("id", room.getId()).findFirst() == null) {
                                            RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm2);
                                            realmRoom1.setDeleted(true);
                                        } else {
                                            RealmRoom.putOrUpdate(room, realm2);
                                        }
                                    });
                                    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);
                        }
                    }
                });
            }
            break;
        case profile:
            G.handler.post(new Runnable() {

                @Override
                public void run() {
                    FragmentContactsProfile contactsProfile = new FragmentContactsProfile();
                    Bundle bundle = new Bundle();
                    bundle.putLong("peerId", peerId);
                    bundle.putLong("RoomId", roomId);
                    bundle.putString("enterFrom", GROUP.toString());
                    contactsProfile.setArguments(bundle);
                    new HelperFragment(activity.getSupportFragmentManager(), contactsProfile).setReplace(false).load();
                }
            });
            break;
    }
}
Also used : RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) Bundle(android.os.Bundle) FragmentContactsProfile(net.iGap.fragments.FragmentContactsProfile) DbManager(net.iGap.module.accountManager.DbManager) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RealmRoom(net.iGap.realm.RealmRoom) CustomTabsHelperFragment(me.zhanghai.android.customtabshelper.CustomTabsHelperFragment) Realm(io.realm.Realm) 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)

Example 2 with OnChatGetRoom

use of net.iGap.observers.interfaces.OnChatGetRoom 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 3 with OnChatGetRoom

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

the class HelperLogMessage method gotToUserRoom.

private static void gotToUserRoom(final long id) {
    DbManager.getInstance().doRealmTask(realm -> {
        RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", id).findFirst();
        if (realmRoom != null) {
            // Intent intent = new Intent(G.currentActivity, ActivityChat.class);
            // intent.putExtra("RoomId", realmRoom.getId());
            // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // G.currentActivity.startActivity(intent);
            // Intent intent = new Intent(G.context, ActivityContactsProfile.class);
            // intent.putExtra("peerId", id);
            // intent.putExtra("RoomId", realmRoom.getId());
            // intent.putExtra("enterFrom", "GROUP");
            // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // G.currentActivity.startActivity(intent);
            FragmentContactsProfile contactsProfile = new FragmentContactsProfile();
            Bundle bundle = new Bundle();
            bundle.putLong("peerId", id);
            bundle.putLong("RoomId", realmRoom.getId());
            bundle.putString("enterFrom", "GROUP");
            contactsProfile.setArguments(bundle);
            // ToDo:fixed it and change to do not use G.currentActivity
            new HelperFragment(G.currentActivity.getSupportFragmentManager(), contactsProfile).setReplace(false).load();
        } else {
            G.onChatGetRoom = new OnChatGetRoom() {

                @Override
                public void onChatGetRoom(final ProtoGlobal.Room room) {
                    G.handler.post(new Runnable() {

                        @Override
                        public void run() {
                            FragmentContactsProfile contactsProfile = new FragmentContactsProfile();
                            Bundle bundle = new Bundle();
                            bundle.putLong("peerId", id);
                            bundle.putLong("RoomId", room.getId());
                            bundle.putString("enterFrom", "GROUP");
                            contactsProfile.setArguments(bundle);
                            // ToDo:fixed it and change to do not use G.currentActivity
                            new HelperFragment(G.currentActivity.getSupportFragmentManager(), contactsProfile).setReplace(false).load();
                            G.onChatGetRoom = null;
                        }
                    });
                }

                @Override
                public void onChatGetRoomTimeOut() {
                }

                @Override
                public void onChatGetRoomError(int majorCode, int minorCode) {
                }
            };
            new RequestChatGetRoom().chatGetRoom(id);
        }
    });
}
Also used : OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) Bundle(android.os.Bundle) FragmentContactsProfile(net.iGap.fragments.FragmentContactsProfile) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmRoom(net.iGap.realm.RealmRoom) TextPaint(android.text.TextPaint)

Example 4 with OnChatGetRoom

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

the class BotInit method checkDrIgap.

public static void checkDrIgap() {
    if (!BotInit.getCheckDrIgap())
        return;
    new RequestClientGetPromote().getPromote();
    G.ipromote = new Ipromote() {

        @Override
        public void onGetPromoteResponse(ProtoClientGetPromote.ClientGetPromoteResponse.Builder builder) {
            setCheckDrIgap(false);
            ArrayList<Long> promoteIds = new ArrayList<>();
            for (int i = 0; i < builder.getPromoteList().size(); i++) promoteIds.add(builder.getPromoteList().get(i).getId());
            DbManager.getInstance().doRealmTask(realm -> {
                realm.executeTransaction(new Realm.Transaction() {

                    @Override
                    public void execute(Realm realm) {
                        RealmResults<RealmRoom> roomList = realm.where(RealmRoom.class).equalTo("isFromPromote", true).findAll();
                        for (RealmRoom room : roomList) {
                            if (!promoteIds.contains(room.getPromoteId())) {
                                room.setFromPromote(false);
                                RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), false);
                            }
                        }
                    }
                });
                for (int i = builder.getPromoteList().size() - 1; i >= 0; i--) {
                    ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type TYPE = builder.getPromoteList().get(i).getType();
                    RealmRoom realmRoom;
                    if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
                        realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
                    } else {
                        realmRoom = realm.where(RealmRoom.class).equalTo("id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
                    }
                    if (realmRoom == null) {
                        if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
                            // RealmRoom.setPromote(builder.getPromoteList().get(i).getId(), TYPE);
                            G.onChatGetRoom = new OnChatGetRoom() {

                                @Override
                                public void onChatGetRoom(final ProtoGlobal.Room room) {
                                    G.onChatGetRoom = null;
                                    DbManager.getInstance().doRealmTransaction(realm1 -> {
                                        RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm1);
                                        realmRoom1.setFromPromote(true);
                                        realmRoom1.setPromoteId(realmRoom1.getChatRoom().getPeerId());
                                    // RealmRoom.setPromote(2297310L, ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER);
                                    });
                                    RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), true);
                                    ActivityPopUpNotification.sendMessage("/start", room.getId(), ProtoGlobal.Room.Type.CHAT);
                                }

                                @Override
                                public void onChatGetRoomTimeOut() {
                                }

                                @Override
                                public void onChatGetRoomError(int majorCode, int minorCode) {
                                }
                            };
                            new RequestChatGetRoom().chatGetRoom(builder.getPromoteList().get(i).getId());
                        } else {
                            new RequestClientGetRoom().clientGetRoom(builder.getPromoteList().get(i).getId(), RequestClientGetRoom.CreateRoomMode.getPromote);
                        }
                    } else {
                        RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(realmRoom.getId(), true);
                    }
                }
            });
        }
    };
}
Also used : LinearLayout(android.widget.LinearLayout) TypeToken(com.google.gson.reflect.TypeToken) NonNull(androidx.annotation.NonNull) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) GsonBuilder(com.google.gson.GsonBuilder) G(net.iGap.G) RealmUserInfo(net.iGap.realm.RealmUserInfo) JSONException(org.json.JSONException) AdditionalType(net.iGap.module.additionalData.AdditionalType) Gson(com.google.gson.Gson) View(android.view.View) ProtoClientGetPromote(net.iGap.proto.ProtoClientGetPromote) ContextCompat(androidx.core.content.ContextCompat) Realm(io.realm.Realm) RealmRoom(net.iGap.realm.RealmRoom) AppCompatButton(androidx.appcompat.widget.AppCompatButton) ViewGroup(android.view.ViewGroup) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) TextView(android.widget.TextView) ViewMaker.i_Dp(net.iGap.adapter.items.chat.ViewMaker.i_Dp) G.isLocationFromBot(net.iGap.G.isLocationFromBot) G.context(net.iGap.G.context) RelativeLayout(android.widget.RelativeLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) Context(android.content.Context) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ActivityPopUpNotification(net.iGap.activities.ActivityPopUpNotification) HelperUrl(net.iGap.helper.HelperUrl) AccountManager(net.iGap.module.accountManager.AccountManager) HashMap(java.util.HashMap) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) ButtonActionType(net.iGap.module.additionalData.ButtonActionType) Toast(android.widget.Toast) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Ipromote(net.iGap.observers.interfaces.Ipromote) RoomController(net.iGap.controllers.RoomController) MessageObject(net.iGap.structs.MessageObject) RealmResults(io.realm.RealmResults) RequestClientGetPromote(net.iGap.request.RequestClientGetPromote) DialogAction(com.afollestad.materialdialogs.DialogAction) Color(android.graphics.Color) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) ViewMaker(net.iGap.adapter.items.chat.ViewMaker) ButtonEntity(net.iGap.module.additionalData.ButtonEntity) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) Activity(android.app.Activity) DbManager(net.iGap.module.accountManager.DbManager) JSONArray(org.json.JSONArray) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) ArrayList(java.util.ArrayList) RequestClientGetPromote(net.iGap.request.RequestClientGetPromote) Ipromote(net.iGap.observers.interfaces.Ipromote) AdditionalType(net.iGap.module.additionalData.AdditionalType) ButtonActionType(net.iGap.module.additionalData.ButtonActionType) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmRoom(net.iGap.realm.RealmRoom) Realm(io.realm.Realm) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmRoom(net.iGap.realm.RealmRoom) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom)

Aggregations

OnChatGetRoom (net.iGap.observers.interfaces.OnChatGetRoom)4 RealmRoom (net.iGap.realm.RealmRoom)4 RequestChatGetRoom (net.iGap.request.RequestChatGetRoom)4 Realm (io.realm.Realm)3 DbManager (net.iGap.module.accountManager.DbManager)3 RequestClientGetRoom (net.iGap.request.RequestClientGetRoom)3 Bundle (android.os.Bundle)2 FragmentContactsProfile (net.iGap.fragments.FragmentContactsProfile)2 ProtoClientGetRoom (net.iGap.proto.ProtoClientGetRoom)2 ProtoGlobal (net.iGap.proto.ProtoGlobal)2 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 TextPaint (android.text.TextPaint)1 Gravity (android.view.Gravity)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1