Search in sources :

Example 1 with RealmUserInfo

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

the class LoginActions method getUserInfo.

private static void getUserInfo() {
    final Long userId;
    userId = DbManager.getInstance().doRealmTask(realm -> {
        try {
            RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst();
            if (realmUserInfo == null) {
                throw new Exception("Empty Exception");
            }
            return realmUserInfo.getUserId();
        } catch (Exception e) {
            e.printStackTrace();
            Log.wtf(LoginActions.class.getName(), "catch");
            G.logoutAccount.postValue(true);
            return null;
        }
    });
    if (userId == null)
        return;
    new RequestUserInfo().userInfo(userId);
}
Also used : StructListOfContact(net.iGap.module.structs.StructListOfContact) OnContactFetchForServer(net.iGap.observers.interfaces.OnContactFetchForServer) PackageManager(android.content.pm.PackageManager) MessageDigest(java.security.MessageDigest) AccountManager(net.iGap.module.accountManager.AccountManager) RequestUserLogin(net.iGap.request.RequestUserLogin) G(net.iGap.G) RealmPhoneContacts(net.iGap.realm.RealmPhoneContacts) RealmUserInfo(net.iGap.realm.RealmUserInfo) Manifest(android.Manifest) Gson(com.google.gson.Gson) RequestUserContactsGetBlockedList(net.iGap.request.RequestUserContactsGetBlockedList) RequestUserInfo(net.iGap.request.RequestUserInfo) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) HelperCheckInternetConnection(net.iGap.helper.HelperCheckInternetConnection) AsyncTask(android.os.AsyncTask) UserStatusController(net.iGap.helper.UserStatusController) RequestUserContactsGetList(net.iGap.request.RequestUserContactsGetList) RequestManager(net.iGap.network.RequestManager) List(java.util.List) G.firstEnter(net.iGap.G.firstEnter) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DbManager(net.iGap.module.accountManager.DbManager) OnSecuring(net.iGap.observers.interfaces.OnSecuring) OnUserLogin(net.iGap.observers.interfaces.OnUserLogin) RealmUserInfo(net.iGap.realm.RealmUserInfo) RequestUserInfo(net.iGap.request.RequestUserInfo) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with RealmUserInfo

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

the class Type0ViewHolder method bindView.

@Override
public void bindView(DiscoveryItem item) {
    itemView.setOnClickListener(view -> new HelperFragment(G.currentActivity.getSupportFragmentManager(), new FragmentUserScore()).setReplace(false).load());
    DbManager.getInstance().doRealmTask(realm -> {
        RealmUserInfo userInfo = realm.where(RealmUserInfo.class).findFirst();
        if (userInfo != null)
            tvScore.setText(HelperCalander.isPersianUnicode ? HelperCalander.convertToUnicodeFarsiNumber(String.valueOf(userInfo.getIvandScore())) : String.valueOf(userInfo.getIvandScore()));
    });
    Animation animation = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.shake_mode);
    animation.reset();
    tvContent.clearAnimation();
    tvContent.startAnimation(animation);
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo) FragmentUserScore(net.iGap.fragments.FragmentUserScore) Animation(android.view.animation.Animation) HelperFragment(net.iGap.helper.HelperFragment)

Example 3 with RealmUserInfo

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

the class TokenContainer method getToken.

public String getToken() {
    String result = "Bearer ";
    String dbToken = DbManager.getInstance().doRealmTask(realm -> {
        RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst();
        if (realmUserInfo != null) {
            return realmUserInfo.getAccessToken();
        }
        return null;
    });
    if (dbToken != null) {
        token = dbToken;
    }
    result += token;
    if (BuildConfig.DEBUG)
        Log.i(getClass().getSimpleName(), "ApiToken: " + token);
    return result;
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo)

Example 4 with RealmUserInfo

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

the class HelperToolbar method onScannerClickListener.

private void onScannerClickListener() {
    DbManager.getInstance().doRealmTask(realm -> {
        String phoneNumber = "";
        RealmUserInfo userInfo = realm.where(RealmUserInfo.class).findFirst();
        try {
            if (userInfo != null) {
                phoneNumber = userInfo.getUserInfo().getPhoneNumber().substring(2);
            } else {
                phoneNumber = AccountManager.getInstance().getCurrentUser().getPhoneNumber().substring(2);
            }
        } catch (Exception e) {
            // maybe exception was for realm substring
            try {
                phoneNumber = AccountManager.getInstance().getCurrentUser().getPhoneNumber().substring(2);
            } catch (Exception ex) {
            // nothing
            }
        }
    });
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo)

Example 5 with RealmUserInfo

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

the class BotInit method onClick.

@Override
public void onClick(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) {
                try {
                    Long identity = System.currentTimeMillis();
                    realm.executeTransaction(new Realm.Transaction() {

                        @Override
                        public void execute(Realm realm) {
                            RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(roomId, identity, ((ArrayList<String>) v.getTag()).get(1), ((ArrayList<String>) v.getTag()).get(2), 3, realm, ProtoGlobal.RoomMessageType.TEXT);
                            MessageObject botMessage = MessageObject.create(realmRoomMessage);
                            ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(ProtoGlobal.Room.Type.CHAT, roomId, botMessage);
                            if (G.onBotClick != null) {
                                G.onBotClick.onBotCommandText(realmRoomMessage, ButtonActionType.BOT_ACTION);
                            }
                        }
                    });
                } catch (Exception e) {
                }
            } else if (v.getId() == ButtonActionType.JOIN_LINK) {
                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) {
                G.onBotClick.onBotCommandText(((ArrayList<String>) v.getTag()).get(0), ButtonActionType.WEBVIEW_LINK);
            } 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(roomId, identity, realmUserInfo.getUserInfo().getPhoneNumber(), realmUserInfo.getUserInfo().getPhoneNumber(), 0, realm, ProtoGlobal.RoomMessageType.TEXT);
                                    MessageObject botMessage = MessageObject.create(realmRoomMessage);
                                    ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(ProtoGlobal.Room.Type.CHAT, roomId, botMessage);
                                    if (G.onBotClick != null) {
                                        G.onBotClick.onBotCommandText(realmRoomMessage, ButtonActionType.BOT_ACTION);
                                    }
                                }
                            });
                        }
                    }).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) {
                            Boolean response = false;
                            if (G.locationListener != null) {
                                isLocationFromBot = true;
                                G.locationListener.requestLocation();
                            }
                        /*              G.locationListenerResponse = new LocationListenerResponse() {
                            @Override
                            public void setLocationResponse(Double latitude, Double longitude) {
                                Long identity = System.currentTimeMillis();
                                realm.executeTransaction(new Realm.Transaction() {
                                    @Override
                                    public void execute(Realm realm) {
                                        RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(roomId, identity, latitude + "," + longitude, ((ArrayList<String>) v.getTag()).get(2).toString(), 3, realm, ProtoGlobal.RoomMessageType.TEXT);
                                        G.chatSendMessageUtil.build(ProtoGlobal.Room.Type.CHAT, roomId, realmRoomMessage).sendMessage(identity + "");
                                        if (G.onBotClick != null) {
                                            G.onBotClick.onBotCommandText(realmRoomMessage, ButtonActionType.BOT_ACTION);
                                        }
                                    }
                                });
                            }
                        };*/
                        }
                    }).show();
                } catch (Exception e) {
                }
            }
        } catch (Exception e) {
            Toast.makeText(G.context, "دستور با خطا مواجه شد", Toast.LENGTH_LONG).show();
        }
    });
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(androidx.annotation.NonNull) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Realm(io.realm.Realm) MessageObject(net.iGap.structs.MessageObject)

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