Search in sources :

Example 1 with AccountHelper

use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.

the class SetUpVoipAccountFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mContext = getActivity().getApplicationContext();
    mJsonStorage = new JsonStorage(mContext);
    mAccountHelper = new AccountHelper(mContext);
    mSystemUser = (SystemUser) mJsonStorage.get(SystemUser.class);
    mApi = ServiceGenerator.createService(getActivity(), Api.class, getString(R.string.api_url), mAccountHelper.getEmail(), mAccountHelper.getPassword());
    mVoipAccountButton = (Button) view.findViewById(R.id.set_voip_account_button);
    mVoipAccountButton.setOnClickListener(this);
    mCancelButton = (Button) view.findViewById(R.id.cancel_set_voip_account_button);
    mCancelButton.setOnClickListener(this);
}
Also used : AccountHelper(com.voipgrid.vialer.util.AccountHelper) Api(com.voipgrid.vialer.api.Api) JsonStorage(com.voipgrid.vialer.util.JsonStorage)

Example 2 with AccountHelper

use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.

the class SetupActivity method onUpdateMobileNumber.

@Override
public void onUpdateMobileNumber(Fragment fragment, String mobileNumber) {
    enableProgressBar(true);
    AccountHelper accountHelper = new AccountHelper(this);
    boolean success = createAPIService(accountHelper.getEmail(), accountHelper.getPassword());
    // Post mobileNumber to VoIPGRID platform.
    if (success) {
        Call<MobileNumber> call = mApi.mobileNumber(new MobileNumber(mobileNumber));
        call.enqueue(this);
    }
}
Also used : AccountHelper(com.voipgrid.vialer.util.AccountHelper) PhoneAccountHelper(com.voipgrid.vialer.util.PhoneAccountHelper) MobileNumber(com.voipgrid.vialer.api.models.MobileNumber)

Example 3 with AccountHelper

use of com.voipgrid.vialer.util.AccountHelper 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 AccountHelper

use of com.voipgrid.vialer.util.AccountHelper 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 AccountHelper

use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.

the class CallRecordFragment method loadCallRecordsFromApi.

private void loadCallRecordsFromApi() {
    mHaveNetworkRecords = false;
    AccountHelper accountHelper = new AccountHelper(getActivity());
    Api api = ServiceGenerator.createService(getContext(), Api.class, getString(R.string.api_url), accountHelper.getEmail(), accountHelper.getPassword());
    Call<VoipGridResponse<CallRecord>> call = api.getRecentCalls(50, 0, CallRecord.getLimitDate());
    call.enqueue(this);
}
Also used : AccountHelper(com.voipgrid.vialer.util.AccountHelper) VoipGridResponse(com.voipgrid.vialer.api.models.VoipGridResponse) Api(com.voipgrid.vialer.api.Api)

Aggregations

AccountHelper (com.voipgrid.vialer.util.AccountHelper)11 JsonStorage (com.voipgrid.vialer.util.JsonStorage)4 Intent (android.content.Intent)3 PhoneAccount (com.voipgrid.vialer.api.models.PhoneAccount)3 SystemUser (com.voipgrid.vialer.api.models.SystemUser)3 PhoneAccountHelper (com.voipgrid.vialer.util.PhoneAccountHelper)3 SharedPreferences (android.content.SharedPreferences)2 Preferences (com.voipgrid.vialer.Preferences)2 Api (com.voipgrid.vialer.api.Api)2 Registration (com.voipgrid.vialer.api.Registration)2 RemoteLogger (com.voipgrid.vialer.logging.RemoteLogger)2 IOException (java.io.IOException)2 ResponseBody (okhttp3.ResponseBody)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 FragmentManager (android.app.FragmentManager)1 DialogInterface (android.content.DialogInterface)1 CookieManager (android.webkit.CookieManager)1 Tracker (com.google.android.gms.analytics.Tracker)1 GsonBuilder (com.google.gson.GsonBuilder)1