use of org.edx.mobile.module.registration.view.IRegistrationFieldView in project edx-app-android by edx.
the class RegisterActivity method tryToSetUIInteraction.
@Override
public boolean tryToSetUIInteraction(boolean enable) {
if (enable) {
unblockTouch();
createButtonEnabled();
} else {
blockTouch();
createButtonDisabled();
}
for (IRegistrationFieldView v : mFieldViews) {
v.setEnabled(enable);
}
facebookButton.setClickable(enable);
googleButton.setClickable(enable);
return true;
}
use of org.edx.mobile.module.registration.view.IRegistrationFieldView in project edx-app-android by edx.
the class RegisterActivity method createAccount.
private void createAccount() {
boolean hasError = false;
// prepare query (POST body)
Bundle parameters = new Bundle();
for (IRegistrationFieldView v : mFieldViews) {
if (v.isValidInput()) {
if (v.hasValue()) {
// we submit the field only if it provides a value
parameters.putString(v.getField().getName(), v.getCurrentValue().getAsString());
}
} else {
if (!hasError) {
// this is the first input field with error,
// so focus on it after showing the popup
showErrorPopup(v.getOnErrorFocusView());
}
hasError = true;
}
}
// set honor_code and terms_of_service to true
parameters.putString("honor_code", "true");
parameters.putString("terms_of_service", "true");
// set parameter required by social registration
final String access_token = loginPrefs.getSocialLoginAccessToken();
final String provider = loginPrefs.getSocialLoginProvider();
boolean fromSocialNet = !TextUtils.isEmpty(access_token);
if (fromSocialNet) {
parameters.putString("access_token", access_token);
parameters.putString("provider", provider);
parameters.putString("client_id", environment.getConfig().getOAuthClientId());
}
// do NOT proceed if validations are failed
if (hasError) {
return;
}
// Send analytics event for Create Account button click
final String appVersion = String.format("%s v%s", getString(R.string.android), BuildConfig.VERSION_NAME);
environment.getAnalyticsRegistry().trackCreateAccountClicked(appVersion, provider);
showProgress();
final SocialFactory.SOCIAL_SOURCE_TYPE backsourceType = SocialFactory.SOCIAL_SOURCE_TYPE.fromString(provider);
final RegisterTask task = new RegisterTask(this, parameters, access_token, backsourceType) {
@Override
public void onSuccess(AuthResponse auth) {
environment.getAnalyticsRegistry().trackRegistrationSuccess(appVersion, provider);
onUserLoginSuccess(auth.profile);
}
@Override
public void onException(Exception ex) {
hideProgress();
if (ex instanceof LoginAPI.RegistrationException) {
final FormFieldMessageBody messageBody = ((LoginAPI.RegistrationException) ex).getFormErrorBody();
boolean errorShown = false;
for (String key : messageBody.keySet()) {
if (key == null)
continue;
for (IRegistrationFieldView fieldView : mFieldViews) {
if (key.equalsIgnoreCase(fieldView.getField().getName())) {
List<RegisterResponseFieldError> error = messageBody.get(key);
showErrorOnField(error, fieldView);
if (!errorShown) {
// this is the first input field with error,
// so focus on it after showing the popup
showErrorPopup(fieldView.getOnErrorFocusView());
errorShown = true;
}
break;
}
}
}
if (errorShown) {
// Return here to avoid falling back to the generic error handler.
return;
}
}
// If app version is un-supported
if (ex instanceof HttpStatusException && ((HttpStatusException) ex).getStatusCode() == HttpStatus.UPGRADE_REQUIRED) {
RegisterActivity.this.showAlertDialog(null, getString(R.string.app_version_unsupported_register_msg), getString(R.string.label_update), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AppStoreUtils.openAppInAppStore(RegisterActivity.this);
}
}, getString(android.R.string.cancel), null);
} else {
RegisterActivity.this.showAlertDialog(null, ErrorUtils.getErrorMessage(ex, RegisterActivity.this));
}
}
};
task.execute();
}
use of org.edx.mobile.module.registration.view.IRegistrationFieldView in project edx-app-android by edx.
the class RegisterActivity method setAllEditTextsFocusable.
public void setAllEditTextsFocusable(final boolean focusable) {
for (IRegistrationFieldView fieldView : mFieldViews) {
if (fieldView instanceof RegistrationEditTextView) {
RegistrationEditTextView field = (RegistrationEditTextView) fieldView;
field.setEditTextFocusable(focusable);
}
}
}
use of org.edx.mobile.module.registration.view.IRegistrationFieldView in project edx-app-android by edx.
the class RegisterActivity method setupRegistrationForm.
private void setupRegistrationForm(RegistrationDescription form) {
try {
LayoutInflater inflater = getLayoutInflater();
List<RegistrationFormField> agreements = new ArrayList<>();
for (RegistrationFormField field : form.getFields()) {
if (field.getFieldType().equals(RegistrationFieldType.CHECKBOX) && field.getSupplementalLink() != null) {
// this is agreement field
// this must be added at the end of the form
// hold on it
agreements.add(field);
} else {
IRegistrationFieldView fieldView = IRegistrationFieldView.Factory.getInstance(inflater, field);
if (fieldView != null)
mFieldViews.add(fieldView);
// Add item selected listener for spinner views
if (field.getFieldType().equals(RegistrationFieldType.MULTI)) {
RegistrationSelectView selectView = (RegistrationSelectView) fieldView;
selectView.setOnSpinnerItemSelectedListener(this);
selectView.setOnSpinnerFocusedListener(this);
}
}
}
// add required and optional fields to the window
for (IRegistrationFieldView v : mFieldViews) {
if (v.getField().isRequired()) {
requiredFieldsLayout.addView(v.getView());
} else {
optionalFieldsLayout.addView(v.getView());
}
}
// add agreement fields to the window if available
for (RegistrationFormField agreement : agreements) {
IRegistrationFieldView agreementView = IRegistrationFieldView.Factory.getInstance(inflater, agreement);
agreementView.setActionListener(new IRegistrationFieldView.IActionListener() {
@Override
public void onClickAgreement() {
// show EULA license that is shipped with app
environment.getRouter().showWebViewActivity(RegisterActivity.this, getString(R.string.eula_file_link), getString(R.string.end_user_title));
}
});
agreementLayout.addView(agreementView.getView());
}
// enable all the views
tryToSetUIInteraction(true);
} catch (Exception ex) {
logger.error(ex);
}
}
use of org.edx.mobile.module.registration.view.IRegistrationFieldView in project edx-app-android by edx.
the class RegisterActivity method updateUIOnSocialLoginToEdxFailure.
private void updateUIOnSocialLoginToEdxFailure(SocialFactory.SOCIAL_SOURCE_TYPE socialType, String accessToken) {
// change UI.
View signupWith = findViewById(R.id.signup_with_row);
signupWith.setVisibility(View.GONE);
View socialPanel = findViewById(R.id.panel_social_layout);
socialPanel.setVisibility(View.GONE);
DividerWithTextView signupWithEmailTitle = (DividerWithTextView) findViewById(R.id.or_signup_with_email_title);
signupWithEmailTitle.setText(getString(R.string.complete_registration));
// help method
showRegularMessage(socialType);
// populate the field with value from social site
populateEmailFromSocialSite(socialType, accessToken);
// hide email and password field
for (IRegistrationFieldView field : this.mFieldViews) {
String fieldname = field.getField().getName();
if ("password".equalsIgnoreCase(fieldname)) {
field.getView().setVisibility(View.GONE);
this.mFieldViews.remove(field);
break;
}
}
// registrationLayout.requestLayout();
}
Aggregations