Search in sources :

Example 1 with PhoneAccount

use of com.voipgrid.vialer.api.models.PhoneAccount in project vialer-android by VoIPGRID.

the class SetupActivity method onResponse.

@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
    if (mServiceGen != null) {
        mServiceGen.release();
    }
    if (response.isSuccessful()) {
        enableProgressBar(false);
        if (response.body() instanceof SystemUser) {
            SystemUser systemUser = ((SystemUser) response.body());
            if (systemUser.getPartner() != null) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        onAlertDialog(getString(R.string.user_is_partner_error_title), getString(R.string.user_is_partner_error_message));
                    }
                });
            } else {
                if (systemUser.getOutgoingCli() == null || systemUser.getOutgoingCli().isEmpty()) {
                    mRemoteLogger.d("onResponse getOutgoingCli is null");
                }
                mPreferences.setSipPermission(true);
                AccountHelper accountHelper = new AccountHelper(this);
                accountHelper.setCredentials(systemUser.getEmail(), mPassword);
                mJsonStorage.save(systemUser);
                onNextStep(AccountFragment.newInstance(systemUser.getMobileNumber(), systemUser.getOutgoingCli()));
            }
        } else if (response.body() instanceof PhoneAccount) {
            mJsonStorage.save(response.body());
            if (mPreferences.hasSipPermission()) {
                MiddlewareHelper.registerAtMiddleware(this);
            }
            SystemUser systemUser = (SystemUser) mJsonStorage.get(SystemUser.class);
            onNextStep(WelcomeFragment.newInstance(systemUser.getFullName()));
        } else {
            FragmentManager fragmentManager = getFragmentManager();
            // First see if an AccountFragment exists
            AccountFragment fragment = (AccountFragment) fragmentManager.findFragmentByTag(AccountFragment.class.getSimpleName());
            if (fragment != null) {
                fragment.onNextStep();
            }
            // Check if the current fragment is the account fragment.
            AccountFragment accountFragment = (AccountFragment) getCurrentFragment();
            if (accountFragment != null) {
                accountFragment.onNextStep();
            }
            ForgotPasswordFragment forgotFragment = (ForgotPasswordFragment) fragmentManager.findFragmentByTag(ForgotPasswordFragment.class.getSimpleName());
            if (forgotFragment != null) {
                onNextStep(LoginFragment.newInstance());
            }
        }
    } else {
        String errorString = "";
        try {
            errorString = response.errorBody().string();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (errorString.equals("You need to change your password in the portal")) {
            WebActivityHelper webHelper = new WebActivityHelper(this);
            webHelper.startWebActivity(getString(R.string.password_change_title), getString(R.string.web_password_change), getString(R.string.analytics_password_change));
            Toast.makeText(this, R.string.change_password_webview_toast, Toast.LENGTH_LONG).show();
            return;
        }
        failedFeedback(errorString);
    }
}
Also used : FragmentManager(android.app.FragmentManager) AccountHelper(com.voipgrid.vialer.util.AccountHelper) PhoneAccountHelper(com.voipgrid.vialer.util.PhoneAccountHelper) PhoneAccount(com.voipgrid.vialer.api.models.PhoneAccount) WebActivityHelper(com.voipgrid.vialer.WebActivityHelper) SystemUser(com.voipgrid.vialer.api.models.SystemUser) IOException(java.io.IOException)

Example 2 with PhoneAccount

use of com.voipgrid.vialer.api.models.PhoneAccount in project vialer-android by VoIPGRID.

the class AccountActivity method onCheckedChanged.

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (mPreferences.hasSipEnabled() == isChecked) {
        /* nothing changed, so return */
        return;
    }
    mPreferences.setSipEnabled(isChecked);
    if (!isChecked) {
        // Unregister at middleware.
        MiddlewareHelper.unregister(this);
        // Stop the sipservice.
        stopService(new Intent(this, SipService.class));
        mSipIdEditText.setVisibility(View.GONE);
    } else {
        enableProgressBar(true);
        new AsyncTask<Void, Void, PhoneAccount>() {

            @Override
            protected PhoneAccount doInBackground(Void... params) {
                return mPhoneAccountHelper.getLinkedPhoneAccount();
            }

            @Override
            protected void onPostExecute(PhoneAccount phoneAccount) {
                super.onPostExecute(phoneAccount);
                if (phoneAccount != null) {
                    mPhoneAccountHelper.savePhoneAccountAndRegister(phoneAccount);
                    updateAndPopulate();
                } else {
                    // Make sure sip is disabled in preference and the switch is returned
                    // to disabled. Setting disabled in the settings first makes sure
                    // the onCheckChanged does not execute the code that normally is executed
                    // on a change in the check of the switch.
                    setVoIPAccount();
                }
            }
        }.execute();
    }
}
Also used : PhoneAccount(com.voipgrid.vialer.api.models.PhoneAccount) Intent(android.content.Intent) SipService(com.voipgrid.vialer.sip.SipService)

Example 3 with PhoneAccount

use of com.voipgrid.vialer.api.models.PhoneAccount in project vialer-android by VoIPGRID.

the class SetUpVoipAccountFragment method onResponse.

@Override
public void onResponse(Call call, Response response) {
    if (response.body() instanceof SystemUser) {
        SystemUser systemUser = ((SystemUser) response.body());
        // Update existing systemuser to avoid overriding values like password.
        SystemUser currentSystemuser = mSystemUser;
        currentSystemuser.setOutgoingCli(systemUser.getOutgoingCli());
        currentSystemuser.setMobileNumber(systemUser.getMobileNumber());
        currentSystemuser.setClient(systemUser.getClient());
        currentSystemuser.setAppAccountUri(systemUser.getAppAccountUri());
        mJsonStorage.save(currentSystemuser);
        mSystemUser = currentSystemuser;
        // Check if a account has been set.
        String phoneAccountId = mSystemUser.getPhoneAccountId();
        if (phoneAccountId != null) {
            // Request new phoneaccount object.
            Call<PhoneAccount> apicall = mApi.phoneAccount(phoneAccountId);
            apicall.enqueue(this);
        } else {
            // User has no phone account linked so remove it from the local storage.
            mJsonStorage.remove(PhoneAccount.class);
        }
    } else if (response.body() instanceof PhoneAccount) {
        mJsonStorage.save(response.body());
        mListener.onFinish(this);
    }
}
Also used : PhoneAccount(com.voipgrid.vialer.api.models.PhoneAccount) SystemUser(com.voipgrid.vialer.api.models.SystemUser)

Example 4 with PhoneAccount

use of com.voipgrid.vialer.api.models.PhoneAccount in project vialer-android by VoIPGRID.

the class SetupActivity method onConfigure.

@Override
public void onConfigure(Fragment fragment, String mobileNumber, String outgoingNumber) {
    enableProgressBar(true);
    // Save mobile and outgoing number.
    SystemUser systemUser = (SystemUser) mJsonStorage.get(SystemUser.class);
    systemUser.setMobileNumber(mobileNumber);
    systemUser.setOutgoingCli(outgoingNumber);
    mJsonStorage.save(systemUser);
    String phoneAccountId = systemUser.getPhoneAccountId();
    if (phoneAccountId != null) {
        Call<PhoneAccount> call = mApi.phoneAccount(phoneAccountId);
        call.enqueue(this);
    } else {
        enableProgressBar(false);
        onNextStep(WelcomeFragment.newInstance(((SystemUser) mJsonStorage.get(SystemUser.class)).getFullName()));
    }
}
Also used : PhoneAccount(com.voipgrid.vialer.api.models.PhoneAccount) SystemUser(com.voipgrid.vialer.api.models.SystemUser)

Example 5 with PhoneAccount

use of com.voipgrid.vialer.api.models.PhoneAccount in project vialer-android by VoIPGRID.

the class NavigationDrawerActivity method onItemSelected.

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    if (mFirstTimeOnItemSelected) {
        mFirstTimeOnItemSelected = false;
    } else {
        if (parent.getCount() - 1 == position) {
            startWebActivity(getString(R.string.add_destination_title), getString(R.string.web_add_destination), getString(R.string.analytics_add_destination_title));
        } else {
            Destination destination = (Destination) parent.getAdapter().getItem(position);
            if (destination.getDescription().equals(getString(R.string.not_available))) {
                MiddlewareHelper.unregister(this);
            }
            SelectedUserDestinationParams params = new SelectedUserDestinationParams();
            params.fixedDestination = destination instanceof FixedDestination ? destination.getId() : null;
            params.phoneAccount = destination instanceof PhoneAccount ? destination.getId() : null;
            Call<Object> call = mApi.setSelectedUserDestination(mSelectedUserDestinationId, params);
            call.enqueue(this);
            if (!MiddlewareHelper.isRegistered(this)) {
                // If the previous destination was not available, or if we're not registered
                // for another reason, register again.
                MiddlewareHelper.registerAtMiddleware(this);
            }
        }
    }
}
Also used : FixedDestination(com.voipgrid.vialer.api.models.FixedDestination) Destination(com.voipgrid.vialer.api.models.Destination) UserDestination(com.voipgrid.vialer.api.models.UserDestination) PhoneAccount(com.voipgrid.vialer.api.models.PhoneAccount) SelectedUserDestinationParams(com.voipgrid.vialer.api.models.SelectedUserDestinationParams) FixedDestination(com.voipgrid.vialer.api.models.FixedDestination)

Aggregations

PhoneAccount (com.voipgrid.vialer.api.models.PhoneAccount)10 SystemUser (com.voipgrid.vialer.api.models.SystemUser)5 Preferences (com.voipgrid.vialer.Preferences)3 AccountHelper (com.voipgrid.vialer.util.AccountHelper)3 SharedPreferences (android.content.SharedPreferences)2 Registration (com.voipgrid.vialer.api.Registration)2 RemoteLogger (com.voipgrid.vialer.logging.RemoteLogger)2 JsonStorage (com.voipgrid.vialer.util.JsonStorage)2 IOException (java.io.IOException)2 ResponseBody (okhttp3.ResponseBody)2 FragmentManager (android.app.FragmentManager)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Handler (android.os.Handler)1 TelephonyManager (android.telephony.TelephonyManager)1 Tracker (com.google.android.gms.analytics.Tracker)1 WebActivityHelper (com.voipgrid.vialer.WebActivityHelper)1 AnalyticsApplication (com.voipgrid.vialer.analytics.AnalyticsApplication)1 AnalyticsHelper (com.voipgrid.vialer.analytics.AnalyticsHelper)1 Destination (com.voipgrid.vialer.api.models.Destination)1