Search in sources :

Example 1 with OnUserLogin

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

the class RegisterRepository method userLogin.

public void userLogin(String token) {
    G.onUserLogin = new OnUserLogin() {

        @Override
        public void onLogin() {
            G.onUserLogin = null;
            DbManager.getInstance().doRealmTask(realm -> {
                AccountManager.getInstance().addNewUser(userId, phoneNumber);
                realm.executeTransaction(realm1 -> RealmUserInfo.putOrUpdate(realm1, userId, userName, phoneNumber, token, authorHash));
                BotInit.setCheckDrIgap(true);
                if (newUser) {
                    goToWelcomePage.postValue(userId);
                    HelperTracker.sendTracker(HelperTracker.TRACKER_REGISTRATION_NEW_USER);
                } else {
                    // get user info for set nick name and after from that go to ActivityMain
                    getUserInfo();
                    requestUserInfo();
                    HelperTracker.sendTracker(HelperTracker.TRACKER_REGISTRATION_USER);
                }
            });
        }

        @Override
        public void onLoginError(int majorCode, int minorCode) {
            if (majorCode == 5 && minorCode == 1) {
                requestLogin();
            }
        }
    };
    requestLogin();
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) WebSocketClient(net.iGap.WebSocketClient) OnReceiveInfoLocation(net.iGap.observers.interfaces.OnReceiveInfoLocation) RequestInfoLocation(net.iGap.request.RequestInfoLocation) GoToMainFromRegister(net.iGap.model.GoToMainFromRegister) AccountManager(net.iGap.module.accountManager.AccountManager) TwoStepVerificationVerifyPassword(net.iGap.observers.interfaces.TwoStepVerificationVerifyPassword) ProtoUserVerify(net.iGap.proto.ProtoUserVerify) OnUserRegistration(net.iGap.observers.interfaces.OnUserRegistration) RequestUserLogin(net.iGap.request.RequestUserLogin) OnUserProfileSetRepresentative(net.iGap.observers.interfaces.OnUserProfileSetRepresentative) RequestUserProfileSetRepresentative(net.iGap.request.RequestUserProfileSetRepresentative) G(net.iGap.G) OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) RealmUserInfo(net.iGap.realm.RealmUserInfo) LocationModel(net.iGap.model.LocationModel) Handler(android.os.Handler) TwoStepVerificationGetPasswordDetail(net.iGap.observers.interfaces.TwoStepVerificationGetPasswordDetail) RequestInfoPage(net.iGap.request.RequestInfoPage) OnUserVerification(net.iGap.observers.interfaces.OnUserVerification) RequestWrapper(net.iGap.request.RequestWrapper) RequestUserInfo(net.iGap.request.RequestUserInfo) Log(android.util.Log) RequestUserProfileSetNickname(net.iGap.request.RequestUserProfileSetNickname) UserPasswordDetail(net.iGap.model.UserPasswordDetail) ProtoUserRegister(net.iGap.proto.ProtoUserRegister) HelperTracker(net.iGap.helper.HelperTracker) BuildConfig(net.iGap.BuildConfig) SingleLiveEvent(net.iGap.module.SingleLiveEvent) RequestUserTwoStepVerificationGetPasswordDetail(net.iGap.request.RequestUserTwoStepVerificationGetPasswordDetail) BotInit(net.iGap.module.BotInit) RealmAvatar(net.iGap.realm.RealmAvatar) OnInfoCountryResponse(net.iGap.observers.interfaces.OnInfoCountryResponse) List(java.util.List) RequestInfoCountry(net.iGap.request.RequestInfoCountry) HelperString(net.iGap.helper.HelperString) ProtoGlobal(net.iGap.proto.ProtoGlobal) RequestQueue(net.iGap.request.RequestQueue) OnUserProfileSetNickNameResponse(net.iGap.observers.interfaces.OnUserProfileSetNickNameResponse) ProtoRequest(net.iGap.proto.ProtoRequest) RequestUserTwoStepVerificationVerifyPassword(net.iGap.request.RequestUserTwoStepVerificationVerifyPassword) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) OnUserLogin(net.iGap.observers.interfaces.OnUserLogin) OnUserLogin(net.iGap.observers.interfaces.OnUserLogin)

Example 2 with OnUserLogin

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

the class LoginActions method login.

/**
 * try login to server and do common actions
 */
public static void login() {
    if (!G.ISRealmOK) {
        return;
    }
    G.onUserLogin = new OnUserLogin() {

        @Override
        public void onLogin() {
            G.handler.post(new Runnable() {

                @Override
                public void run() {
                    if (firstEnter) {
                        firstEnter = false;
                        new RequestUserContactsGetBlockedList().userContactsGetBlockedList();
                        importContact();
                    }
                    getUserInfo();
                    if (G.isAppInFg) {
                        UserStatusController.getInstance().setOnline();
                    }
                    if (AndroidUtils.isAppOnForeground(G.context)) {
                        GPSTracker.getGpsTrackerInstance().checkLocation();
                    }
                    // sendWaitingRequestWrappers();
                    HelperCheckInternetConnection.detectConnectionTypeForDownload();
                }
            });
        }

        @Override
        public void onLoginError(int majorCode, int minorCode) {
        }
    };
    if (RequestManager.getInstance(AccountManager.selectedAccount).isSecure()) {
        DbManager.getInstance().doRealmTask(realm -> {
            RealmUserInfo userInfo = realm.where(RealmUserInfo.class).findFirst();
            if (!RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
                if (userInfo != null) {
                    if (userInfo.getUserRegistrationState()) {
                        Log.wtf(LoginActions.class.getName(), "LoginActions.login: RequestUserLogin().userLogin");
                        new RequestUserLogin().userLogin(userInfo.getToken());
                    } else {
                        Log.wtf(LoginActions.class.getName(), "LoginActions.login:getUserRegistrationState" + userInfo.getUserRegistrationState());
                    }
                } else {
                    Log.wtf(LoginActions.class.getName(), "LoginActions.login:userInfo != null");
                }
            } else {
                Log.wtf(LoginActions.class.getName(), "LoginActions.login:else");
            }
        });
    } else {
        login();
    }
}
Also used : RealmUserInfo(net.iGap.realm.RealmUserInfo) RequestUserLogin(net.iGap.request.RequestUserLogin) RequestUserContactsGetBlockedList(net.iGap.request.RequestUserContactsGetBlockedList) OnUserLogin(net.iGap.observers.interfaces.OnUserLogin)

Aggregations

OnUserLogin (net.iGap.observers.interfaces.OnUserLogin)2 RealmUserInfo (net.iGap.realm.RealmUserInfo)2 RequestUserLogin (net.iGap.request.RequestUserLogin)2 Handler (android.os.Handler)1 Log (android.util.Log)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 List (java.util.List)1 BuildConfig (net.iGap.BuildConfig)1 G (net.iGap.G)1 WebSocketClient (net.iGap.WebSocketClient)1 HelperString (net.iGap.helper.HelperString)1 HelperTracker (net.iGap.helper.HelperTracker)1 GoToMainFromRegister (net.iGap.model.GoToMainFromRegister)1 LocationModel (net.iGap.model.LocationModel)1 UserPasswordDetail (net.iGap.model.UserPasswordDetail)1 BotInit (net.iGap.module.BotInit)1 SingleLiveEvent (net.iGap.module.SingleLiveEvent)1 AccountManager (net.iGap.module.accountManager.AccountManager)1 DbManager (net.iGap.module.accountManager.DbManager)1 OnInfoCountryResponse (net.iGap.observers.interfaces.OnInfoCountryResponse)1