Search in sources :

Example 11 with RealmUserInfo

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

the class AbstractMessage method onBotBtnClick.

public void onBotBtnClick(View v, ButtonEntity buttonEntity) {
    DbManager.getInstance().doRealmTask(realm -> {
        try {
            if (v.getId() == ButtonActionType.USERNAME_LINK) {
                // TODO: fixed this and do not use G.currentActivity
                HelperUrl.checkUsernameAndGoToRoomWithMessageId(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(1), HelperUrl.ChatEntry.chat, 0, 0);
            } else if (v.getId() == ButtonActionType.BOT_ACTION) {
                long messageId = System.currentTimeMillis();
                RealmRoomMessage roomMessage = new RealmRoomMessage();
                roomMessage.setMessageId(messageId);
                roomMessage.setMessageType(ProtoGlobal.RoomMessageType.TEXT);
                roomMessage.setRoomId(messageObject.roomId);
                roomMessage.setMessage(((ArrayList<String>) v.getTag()).get(1));
                roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
                roomMessage.setUserId(AccountManager.getInstance().getCurrentUser().getId());
                roomMessage.setCreateTime(TimeUtils.currentLocalTime());
                if (((ArrayList<String>) v.getTag()).get(2) != null) {
                    RealmAdditional additional = new RealmAdditional();
                    additional.setId(AppUtils.makeRandomId());
                    additional.setAdditionalData(((ArrayList<String>) v.getTag()).get(2));
                    additional.setAdditionalType(3);
                    roomMessage.setRealmAdditional(additional);
                }
                new Thread(() -> {
                    DbManager.getInstance().doRealmTransaction(realm12 -> {
                        realm12.copyToRealmOrUpdate(roomMessage);
                    });
                }).start();
                MessageObject botMessage = MessageObject.create(roomMessage);
                ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(type, messageObject.roomId, botMessage);
                messageClickListener.sendFromBot(botMessage);
            } else if (v.getId() == ButtonActionType.JOIN_LINK) {
                // TODO: fixed this and do not use G.currentActivity
                HelperUrl.checkAndJoinToRoom(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(14));
            } else if (v.getId() == ButtonActionType.WEB_LINK) {
                HelperUrl.openBrowser(((ArrayList<String>) v.getTag()).get(0));
            } else if (v.getId() == ButtonActionType.WEBVIEW_LINK) {
                messageClickListener.sendFromBot(((ArrayList<String>) v.getTag()).get(0));
            } else if (v.getId() == ButtonActionType.REQUEST_PHONE) {
                try {
                    new MaterialDialog.Builder(G.currentActivity).title(R.string.access_phone_number).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            Long identity = System.currentTimeMillis();
                            realm.executeTransaction(new Realm.Transaction() {

                                @Override
                                public void execute(Realm realm) {
                                    RealmUserInfo realmUserInfo = RealmUserInfo.getRealmUserInfo(realm);
                                    RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(messageObject.roomId, identity, realmUserInfo.getUserInfo().getPhoneNumber(), realmUserInfo.getUserInfo().getPhoneNumber(), 0, realm, ProtoGlobal.RoomMessageType.TEXT);
                                    MessageObject botMessage = MessageObject.create(realmRoomMessage);
                                    ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(type, messageObject.roomId, botMessage);
                                    messageClickListener.sendFromBot(botMessage);
                                }
                            });
                        }
                    }).show();
                } catch (Exception e) {
                }
            } else if (v.getId() == ButtonActionType.REQUEST_LOCATION) {
                try {
                    new MaterialDialog.Builder(G.currentActivity).title(R.string.access_location).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            if (G.locationListener != null) {
                                isLocationFromBot = true;
                                G.locationListener.requestLocation();
                            }
                        }
                    }).show();
                } catch (Exception e) {
                }
            } else if (v.getId() == ButtonActionType.PAY_DIRECT) {
                JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
                RealmRoom room = realm.where(RealmRoom.class).equalTo("id", messageObject.roomId).findFirst();
                new HelperFragment(G.currentActivity.getSupportFragmentManager()).loadPayment(room.getTitle(), jsonObject.getString("token"), null);
            } else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.CARD_TO_CARD.getNumber()) {
                JSONObject rootJsonObject = new JSONObject(buttonEntity.getJsonObject());
                JSONObject valueObject = rootJsonObject.getJSONObject("value");
                String cardNumber = valueObject.getString("cardNumber");
                int amount = valueObject.getInt("amount");
                long userId = valueObject.getLong("userId");
                CardToCardHelper.NewCallCardToCard(G.currentActivity, userId, amount, cardNumber);
            } else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.BILL_MENU.getNumber()) {
                try {
                    JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
                    new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills, jsonObject)).setReplace(false).load();
                } catch (JSONException e) {
                    new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills)).setReplace(false).load();
                }
            } else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.TRAFFIC_BILL_MENU.getNumber()) {
                try {
                    JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
                    new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime, jsonObject)).setReplace(false).load();
                } catch (JSONException e) {
                    new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime)).setReplace(false).load();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(G.context, "دستور با خطا مواجه شد", Toast.LENGTH_LONG).show();
        }
    });
/**
 * The data was sent via the button via the view tag. Right now I only do this for the card due to lack of time with the new object
 */
}
Also used : RealmAdditional(net.iGap.realm.RealmAdditional) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) NonNull(androidx.annotation.NonNull) RealmRoom(net.iGap.realm.RealmRoom) Realm(io.realm.Realm) RealmUserInfo(net.iGap.realm.RealmUserInfo) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) JSONException(org.json.JSONException) JSONException(org.json.JSONException) AndroidRuntimeException(android.util.AndroidRuntimeException) JSONObject(org.json.JSONObject) DialogAction(com.afollestad.materialdialogs.DialogAction) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) HelperFragment(net.iGap.helper.HelperFragment) MessageObject(net.iGap.structs.MessageObject)

Example 12 with RealmUserInfo

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

the class MessageDataStorage method updateMessageStatus.

public void updateMessageStatus(long roomId, long messageId, long documentId, String updaterAuthorHash, ProtoGlobal.RoomMessageStatus messageStatus, long statusVersion, boolean update) {
    storageQueue.postRunnable(() -> {
        FileLog.i(TAG, "updateRoomStatusStatus: " + roomId + " " + messageId + " " + updaterAuthorHash + " " + messageStatus.name() + " " + statusVersion + " " + update);
        try {
            database.beginTransaction();
            if (!update) {
                if (messageStatus == SEEN) {
                    deleteOfflineAction(messageId, ClientConditionOffline.SEEN, false, false);
                } else if (messageStatus == LISTENED) {
                    deleteOfflineAction(messageId, ClientConditionOffline.LISTEN, false, false);
                }
            } else {
                String currentUserAuthorHash = "";
                RealmUserInfo realmUser = database.where(RealmUserInfo.class).findFirst();
                if (realmUser != null) {
                    currentUserAuthorHash = realmUser.getAuthorHash();
                }
                if (currentUserAuthorHash.equals(updaterAuthorHash) && messageStatus == SEEN) {
                    RealmRoom realmRoom = database.where(RealmRoom.class).equalTo("id", roomId).findFirst();
                    if (realmRoom != null && (realmRoom.getLastMessage() != null && realmRoom.getLastMessage().getMessageId() <= messageId)) {
                        realmRoom.setUnreadCount(0);
                    }
                }
                RealmRoomMessage roomMessage;
                if (messageStatus != LISTENED) {
                    roomMessage = database.where(RealmRoomMessage.class).equalTo("messageId", messageId).notEqualTo("status", SEEN.toString()).notEqualTo("status", LISTENED.toString()).findFirst();
                } else {
                    roomMessage = database.where(RealmRoomMessage.class).equalTo("messageId", messageId).findFirst();
                }
                if (roomMessage != null) {
                    roomMessage.setStatus(messageStatus.toString());
                    roomMessage.setStatusVersion(statusVersion);
                    roomMessage.setDocumentId(documentId);
                    database.copyToRealmOrUpdate(roomMessage);
                }
                if (roomMessage != null || messageStatus == SEEN) {
                    G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.CHAT_UPDATE_STATUS, roomId, messageId, messageStatus));
                }
            }
            database.commitTransaction();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo) RealmRoom(net.iGap.realm.RealmRoom) RealmRoomMessage(net.iGap.realm.RealmRoomMessage)

Example 13 with RealmUserInfo

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

the class SplashActivity method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Config.FILE_LOG_ENABLE) {
        FileLog.i("Splash activity on create");
    }
    if (G.ISRealmOK) {
        DbManager.getInstance().doRealmTask(realm -> {
            RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst();
            if (realmUserInfo != null) {
                final String[] token = { realmUserInfo.getModuleToken() };
                if (token[0] == null || token[0].length() < 2) {
                    NotificationCenter.getInstance().setOnTokenReceived(token1 -> {
                        token[0] = token1;
                        RealmUserInfo.setPushNotification(token[0]);
                        Metrix.setPushToken(token[0]);
                    });
                }
            }
        });
        RealmUserInfo userInfo = DbManager.getInstance().doRealmTask(realm -> {
            return realm.where(RealmUserInfo.class).findFirst();
        });
        if (userInfo == null || !userInfo.getUserRegistrationState()) {
            // user registered before
            if (AccountManager.getInstance().haveAccount()) {
                // Todo: this is code and must find cause of this bug
                Intent intent = new Intent(this, ActivityMain.class);
                if (getIntent().getStringExtra(ActivityMain.DEEP_LINK) != null)
                    intent.putExtra(ActivityMain.DEEP_LINK, getIntent().getStringExtra(ActivityMain.DEEP_LINK));
                startActivity(intent);
                finish();
            } else {
                Intent intent = new Intent(this, ActivityRegistration.class);
                startActivity(intent);
                finish();
            }
        } else if (userInfo.getUserInfo() == null || userInfo.getUserInfo().getDisplayName() == null || userInfo.getUserInfo().getDisplayName().isEmpty()) {
            Intent intent = new Intent(this, ActivityRegistration.class);
            intent.putExtra(ActivityRegistration.showProfile, true);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
        } else {
            Intent intent = new Intent(this, ActivityMain.class);
            if (getIntent().getStringExtra(ActivityMain.DEEP_LINK) != null)
                intent.putExtra(ActivityMain.DEEP_LINK, getIntent().getStringExtra(ActivityMain.DEEP_LINK));
            startActivity(intent);
            finish();
        }
    }
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo) Intent(android.content.Intent)

Example 14 with RealmUserInfo

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

the class ChooseMoneyTransferActionFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DbManager.getInstance().doRealmTask(realm -> {
        RealmUserInfo userInfo = RealmUserInfo.getRealmUserInfo(realm);
        if (userInfo != null) {
            isWalletActive = userInfo.isWalletActive();
            isWalletRegister = userInfo.isWalletRegister();
        }
    });
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo)

Aggregations

RealmUserInfo (net.iGap.realm.RealmUserInfo)14 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)4 NonNull (androidx.annotation.NonNull)3 DialogAction (com.afollestad.materialdialogs.DialogAction)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 Realm (io.realm.Realm)3 ArrayList (java.util.ArrayList)3 HelperFragment (net.iGap.helper.HelperFragment)3 MessageObject (net.iGap.structs.MessageObject)3 Manifest (android.Manifest)2 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2 Log (android.util.Log)2 Animation (android.view.animation.Animation)2 ContextCompat (androidx.core.content.ContextCompat)2 Gson (com.google.gson.Gson)2 List (java.util.List)2 G (net.iGap.G)2 AccountManager (net.iGap.module.accountManager.AccountManager)2 DbManager (net.iGap.module.accountManager.DbManager)2