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);
}
}
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();
}
}
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);
}
}
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()));
}
}
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);
}
}
}
}
Aggregations