Search in sources :

Example 1 with SystemUser

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

the class AccountFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Bundle arguments = getArguments();
    if (arguments != null) {
        mMobileEditText = (EditText) view.findViewById(R.id.mobileNumberTextDialog);
        mMobileEditText.setText(arguments.getString(ARG_MOBILE));
        mMobileEditText.addTextChangedListener(this);
        mMobileEditText.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                final int DRAWABLE_RIGHT = 2;
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (event.getRawX() >= (mMobileEditText.getRight() - mMobileEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                        mListener.onAlertDialog(getString(R.string.phonenumber_info_text_title), getString(R.string.phonenumber_info_text));
                        return true;
                    }
                }
                return false;
            }
        });
        mOutgoingEditText = (EditText) view.findViewById(R.id.outgoingNumberTextDialog);
        String outGoingNumber = arguments.getString(ARG_OUTGOING);
        // TODO Find a better solution for this (VIALA-575) in future.
        if (outGoingNumber == null || outGoingNumber.isEmpty()) {
            // Forced logging due to user not being able to set/unset it at this point.
            mRemoteLogger = new RemoteLogger(AccountFragment.class).forceRemoteLogging(true);
            mRemoteLogger.d("no outGoingNumber");
            SystemUser systemUser = (SystemUser) new JsonStorage(getActivity()).get(SystemUser.class);
            outGoingNumber = systemUser.getOutgoingCli();
        }
        // Sometimes the outgoing number is suppressed (anonymous), so we capture that here.
        if (outGoingNumber != null && outGoingNumber.equals(SUPPRESSED)) {
            outGoingNumber = getString(R.string.supressed_number);
        }
        mOutgoingEditText.setText(outGoingNumber);
        mOutgoingEditText.addTextChangedListener(this);
        mConfigureButton = (Button) view.findViewById(R.id.button_configure);
        mConfigureButton.setOnClickListener(this);
        // enable configure button when mobile number is available for the SystemUser
        if (mMobileEditText.getText().length() > 0) {
            mConfigureButton.setEnabled(true);
        }
    }
}
Also used : Bundle(android.os.Bundle) SystemUser(com.voipgrid.vialer.api.models.SystemUser) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) JsonStorage(com.voipgrid.vialer.util.JsonStorage) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 2 with SystemUser

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

the class SetupActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup);
    mJsonStorage = new JsonStorage(this);
    mPreferences = new Preferences(this);
    // Forced logging due to user not being able to set/unset it at this point.
    mRemoteLogger = new RemoteLogger(SetupActivity.class).forceRemoteLogging(true);
    Fragment gotoFragment = null;
    Integer fragmentId = null;
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        fragmentId = bundle.getInt("fragment");
        mActivityToReturnToName = bundle.getString("activity");
        if (fragmentId == R.id.fragment_voip_account_missing) {
            gotoFragment = ((SetUpVoipAccountFragment) getFragmentManager().findFragmentById(fragmentId)).newInstance();
        } else if (fragmentId == R.id.fragment_account) {
            SystemUser systemUser = (SystemUser) mJsonStorage.get(SystemUser.class);
            gotoFragment = ((AccountFragment) getFragmentManager().findFragmentById(fragmentId)).newInstance(systemUser.getMobileNumber(), systemUser.getOutgoingCli());
        }
    }
    if (findViewById(R.id.fragment_container) != null) {
        if (gotoFragment == null) {
            gotoFragment = LogoFragment.newInstance();
        }
        if (fragmentId != null && fragmentId == R.id.fragment_account) {
            swapFragment(gotoFragment, AccountFragment.class.getSimpleName());
        } else {
            swapFragment(gotoFragment, gotoFragment.getClass().getSimpleName());
        }
    }
}
Also used : Bundle(android.os.Bundle) SystemUser(com.voipgrid.vialer.api.models.SystemUser) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) JsonStorage(com.voipgrid.vialer.util.JsonStorage) Preferences(com.voipgrid.vialer.Preferences) Fragment(android.app.Fragment)

Example 3 with SystemUser

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

the class SetupActivity method onLogin.

@Override
public void onLogin(final Fragment fragment, String username, String password) {
    mPassword = password;
    enableProgressBar(true);
    boolean success = createAPIService(username, password);
    AccountHelper accountHelper = new AccountHelper(this);
    accountHelper.setCredentials(username, password);
    if (success) {
        Call<SystemUser> call = mApi.systemUser();
        call.enqueue(this);
    }
}
Also used : AccountHelper(com.voipgrid.vialer.util.AccountHelper) PhoneAccountHelper(com.voipgrid.vialer.util.PhoneAccountHelper) SystemUser(com.voipgrid.vialer.api.models.SystemUser)

Example 4 with SystemUser

use of com.voipgrid.vialer.api.models.SystemUser 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 5 with SystemUser

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

the class PhoneAccountHelper method updateSystemUser.

/**
 * Function to update the systemuser information.
 */
private void updateSystemUser(SystemUser systemUser) {
    SystemUser currentSystemuser = (SystemUser) mJsonStorage.get(SystemUser.class);
    currentSystemuser.setOutgoingCli(systemUser.getOutgoingCli());
    currentSystemuser.setMobileNumber(systemUser.getMobileNumber());
    currentSystemuser.setClient(systemUser.getClient());
    currentSystemuser.setAppAccountUri(systemUser.getAppAccountUri());
    mJsonStorage.save(currentSystemuser);
}
Also used : SystemUser(com.voipgrid.vialer.api.models.SystemUser)

Aggregations

SystemUser (com.voipgrid.vialer.api.models.SystemUser)13 PhoneAccount (com.voipgrid.vialer.api.models.PhoneAccount)5 JsonStorage (com.voipgrid.vialer.util.JsonStorage)5 Bundle (android.os.Bundle)3 AccountHelper (com.voipgrid.vialer.util.AccountHelper)3 PhoneAccountHelper (com.voipgrid.vialer.util.PhoneAccountHelper)3 IOException (java.io.IOException)3 Preferences (com.voipgrid.vialer.Preferences)2 RemoteLogger (com.voipgrid.vialer.logging.RemoteLogger)2 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 GoogleAnalytics (com.google.android.gms.analytics.GoogleAnalytics)1 Tracker (com.google.android.gms.analytics.Tracker)1 WebActivityHelper (com.voipgrid.vialer.WebActivityHelper)1 AnalyticsApplication (com.voipgrid.vialer.analytics.AnalyticsApplication)1