Skip to content
Snippets Groups Projects
Commit 885cd69f authored by Adrien Béraud's avatar Adrien Béraud
Browse files

account creation: fix issues after first attempt, cleanup

Change-Id: I1d0ce2b1ab5fbfaa8310cd1cb00fb191ee04e6ae
parent 571ac088
Branches
Tags
No related merge requests found
...@@ -32,23 +32,19 @@ import cx.ring.mvp.RootPresenter; ...@@ -32,23 +32,19 @@ import cx.ring.mvp.RootPresenter;
import cx.ring.services.AccountService; import cx.ring.services.AccountService;
import cx.ring.services.DeviceRuntimeService; import cx.ring.services.DeviceRuntimeService;
import cx.ring.utils.Log; import cx.ring.utils.Log;
import cx.ring.utils.StringUtils;
import io.reactivex.observers.DisposableObserver; import io.reactivex.observers.DisposableObserver;
public class AccountWizardPresenter extends RootPresenter<AccountWizardView> { public class AccountWizardPresenter extends RootPresenter<AccountWizardView> {
public static final String TAG = AccountWizardPresenter.class.getSimpleName(); public static final String TAG = AccountWizardPresenter.class.getSimpleName();
protected AccountService mAccountService; private final AccountService mAccountService;
protected DeviceRuntimeService mDeviceRuntimeService; private final DeviceRuntimeService mDeviceRuntimeService;
private boolean mLinkAccount = false;
private boolean mCreationError = false; private boolean mCreationError = false;
private boolean mCreatingAccount = false; private boolean mCreatingAccount = false;
private String mAccountType; private String mAccountType;
private Account mAccount;
private String mCreatedAccountId;
private RingAccountViewModel mRingAccountViewModel; private RingAccountViewModel mRingAccountViewModel;
@Inject @Inject
...@@ -57,16 +53,6 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView>{ ...@@ -57,16 +53,6 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView>{
this.mDeviceRuntimeService = deviceRuntimeService; this.mDeviceRuntimeService = deviceRuntimeService;
} }
@Override
public void bindView(AccountWizardView view) {
super.bindView(view);
}
@Override
public void unbindView() {
super.unbindView();
}
public void init(String accountType) { public void init(String accountType) {
mAccountType = accountType; mAccountType = accountType;
if (AccountConfig.ACCOUNT_TYPE_SIP.equals(mAccountType)) { if (AccountConfig.ACCOUNT_TYPE_SIP.equals(mAccountType)) {
...@@ -130,9 +116,6 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView>{ ...@@ -130,9 +116,6 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView>{
boolean hasCameraPermission = mDeviceRuntimeService.hasVideoPermission(); boolean hasCameraPermission = mDeviceRuntimeService.hasVideoPermission();
accountDetails.put(ConfigKey.VIDEO_ENABLED.key(), Boolean.toString(hasCameraPermission)); accountDetails.put(ConfigKey.VIDEO_ENABLED.key(), Boolean.toString(hasCameraPermission));
//~ Sipinfo is forced for any sipaccount since overrtp is not supported yet.
//~ This will have to be removed when it will be supported.
accountDetails.put(ConfigKey.ACCOUNT_DTMF_TYPE.key(), "sipinfo"); accountDetails.put(ConfigKey.ACCOUNT_DTMF_TYPE.key(), "sipinfo");
return accountDetails; return accountDetails;
} catch (Exception e) { } catch (Exception e) {
...@@ -153,82 +136,69 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView>{ ...@@ -153,82 +136,69 @@ public class AccountWizardPresenter extends RootPresenter<AccountWizardView>{
getView().blockOrientation(); getView().blockOrientation();
getView().displayProgress(true); getView().displayProgress(true);
if (mAccountType.equals(AccountConfig.ACCOUNT_TYPE_RING) || mAccount == null) { mCompositeDisposable.add(mAccountService.addAccount(accountDetails)
mCompositeDisposable.add(mAccountService.addAccount(accountDetails).subscribeWith(new DisposableObserver<Account>() { .subscribeWith(new DisposableObserver<Account>() {
@Override @Override
public void onNext(Account account) { public void onNext(Account account) {
if (!handleCreationState(account)) { if (!handleCreationState(account)) {
mCreatingAccount = false;
dispose(); dispose();
} }
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
handleCreationState(null); handleCreationState(null);
mCreatingAccount = false;
dispose(); dispose();
} }
@Override
public void onComplete() {}
}));
} else {
mAccount.setDetail(ConfigKey.ACCOUNT_ALIAS, accountDetails.get(ConfigKey.ACCOUNT_ALIAS.key()));
if (accountDetails.containsKey(ConfigKey.ACCOUNT_HOSTNAME.key())) {
mAccount.setDetail(ConfigKey.ACCOUNT_HOSTNAME, accountDetails.get(ConfigKey.ACCOUNT_HOSTNAME.key()));
mAccount.setDetail(ConfigKey.ACCOUNT_USERNAME, accountDetails.get(ConfigKey.ACCOUNT_USERNAME.key()));
mAccount.setDetail(ConfigKey.ACCOUNT_PASSWORD, accountDetails.get(ConfigKey.ACCOUNT_PASSWORD.key()));
}
mAccountService.setAccountDetails(mAccount.getAccountID(), mAccount.getDetails()); @Override
public void onComplete() {
} }
}));
mCreatingAccount = false;
} }
private boolean handleCreationState(final Account account) { private boolean handleCreationState(final Account account) {
AccountWizardView view = getView();
if (account == null) { if (account == null) {
getView().displayProgress(false); view.displayProgress(false);
getView().displayCannotBeFoundError(); view.displayCannotBeFoundError();
return false; return false;
} }
String newState = account.getRegistrationState(); String newState = account.getRegistrationState();
if (account.isRing() && (newState.isEmpty() || newState.contentEquals(AccountConfig.STATE_INITIALIZING))) { if (account.isRing() && (newState.isEmpty() || newState.contentEquals(AccountConfig.STATE_INITIALIZING))) {
return true; return true;
} }
getView().displayProgress(false); view.displayProgress(false);
if (!mCreationError) { if (!mCreationError) {
switch (newState) { switch (newState) {
case AccountConfig.STATE_ERROR_GENERIC: case AccountConfig.STATE_ERROR_GENERIC:
getView().displayGenericError(); view.displayGenericError();
mCreationError = true; mCreationError = true;
break; break;
case AccountConfig.STATE_UNREGISTERED: case AccountConfig.STATE_UNREGISTERED:
if (mLinkAccount) { view.displaySuccessDialog();
getView().displayCannotBeFoundError(); view.saveProfile(account.getAccountID(), mRingAccountViewModel);
mCreationError = true;
} else {
getView().displaySuccessDialog();
getView().saveProfile(account.getAccountID(), mRingAccountViewModel);
mCreationError = false; mCreationError = false;
mAccountService.setCurrentAccount(account);
break;
}
break; break;
case AccountConfig.STATE_ERROR_NETWORK: case AccountConfig.STATE_ERROR_NETWORK:
getView().displayNetworkError(); view.displayNetworkError();
mCreationError = true; mCreationError = true;
break; break;
default: default:
getView().displaySuccessDialog(); view.displaySuccessDialog();
getView().saveProfile(account.getAccountID(), mRingAccountViewModel); view.saveProfile(account.getAccountID(), mRingAccountViewModel);
mCreationError = false; mCreationError = false;
mAccountService.setCurrentAccount(account);
break; break;
} }
if (mRingAccountViewModel.getUsername() != null && !mRingAccountViewModel.getUsername().contentEquals("")) { if (account.isRing() && !StringUtils.isEmpty(mRingAccountViewModel.getUsername())) {
Log.i(TAG, "Account created, registering " + mRingAccountViewModel.getUsername()); Log.i(TAG, "Account created, registering " + mRingAccountViewModel.getUsername());
mAccountService.registerName(account, "", mRingAccountViewModel.getUsername()); mAccountService.registerName(account, mRingAccountViewModel.getPassword(), mRingAccountViewModel.getUsername());
} }
mAccountService.setCurrentAccount(account);
} }
return false; return false;
} }
......
...@@ -126,16 +126,21 @@ public class RingAccountCreationPresenter extends RootPresenter<RingAccountCreat ...@@ -126,16 +126,21 @@ public class RingAccountCreationPresenter extends RootPresenter<RingAccountCreat
} }
public void createAccount() { public void createAccount() {
getView().enableNextButton(false); if (isInputValid()) {
getView().goToAccountCreation(mRingAccountViewModel); RingAccountCreationView view = getView();
view.enableNextButton(false);
view.goToAccountCreation(mRingAccountViewModel);
}
} }
private void checkForms() { private boolean isInputValid() {
if (isRegisterUsernameChecked) { boolean passwordOk = isPasswordCorrect && isConfirmCorrect;
getView().enableNextButton(isRingUserNameCorrect && isPasswordCorrect && isConfirmCorrect); boolean usernameOk = !isRegisterUsernameChecked || isRingUserNameCorrect;
} else { return passwordOk && usernameOk;
getView().enableNextButton(isPasswordCorrect && isConfirmCorrect);
} }
private void checkForms() {
getView().enableNextButton(isInputValid());
} }
private void handleBlockchainResult(String name, String address, int state) { private void handleBlockchainResult(String name, String address, int state) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment