Search in sources :

Example 1 with IRegistrationFieldView

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;
}
Also used : IRegistrationFieldView(org.edx.mobile.module.registration.view.IRegistrationFieldView)

Example 2 with IRegistrationFieldView

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();
}
Also used : DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) RegisterTask(org.edx.mobile.task.RegisterTask) HttpStatusException(org.edx.mobile.http.HttpStatusException) IRegistrationFieldView(org.edx.mobile.module.registration.view.IRegistrationFieldView) HttpStatusException(org.edx.mobile.http.HttpStatusException) AuthResponse(org.edx.mobile.authentication.AuthResponse) RegisterResponseFieldError(org.edx.mobile.model.api.RegisterResponseFieldError) FormFieldMessageBody(org.edx.mobile.model.api.FormFieldMessageBody) SocialFactory(org.edx.mobile.social.SocialFactory)

Example 3 with IRegistrationFieldView

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);
        }
    }
}
Also used : RegistrationEditTextView(org.edx.mobile.module.registration.view.RegistrationEditTextView) IRegistrationFieldView(org.edx.mobile.module.registration.view.IRegistrationFieldView)

Example 4 with IRegistrationFieldView

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);
    }
}
Also used : RegistrationSelectView(org.edx.mobile.module.registration.view.RegistrationSelectView) LayoutInflater(android.view.LayoutInflater) ArrayList(java.util.ArrayList) RegistrationFormField(org.edx.mobile.module.registration.model.RegistrationFormField) IRegistrationFieldView(org.edx.mobile.module.registration.view.IRegistrationFieldView) HttpStatusException(org.edx.mobile.http.HttpStatusException)

Example 5 with IRegistrationFieldView

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();
}
Also used : DividerWithTextView(org.edx.mobile.view.custom.DividerWithTextView) DividerWithTextView(org.edx.mobile.view.custom.DividerWithTextView) View(android.view.View) RegistrationEditTextView(org.edx.mobile.module.registration.view.RegistrationEditTextView) TextView(android.widget.TextView) RegistrationSelectView(org.edx.mobile.module.registration.view.RegistrationSelectView) IRegistrationFieldView(org.edx.mobile.module.registration.view.IRegistrationFieldView) ScrollView(android.widget.ScrollView) IRegistrationFieldView(org.edx.mobile.module.registration.view.IRegistrationFieldView)

Aggregations

IRegistrationFieldView (org.edx.mobile.module.registration.view.IRegistrationFieldView)5 HttpStatusException (org.edx.mobile.http.HttpStatusException)2 RegistrationEditTextView (org.edx.mobile.module.registration.view.RegistrationEditTextView)2 RegistrationSelectView (org.edx.mobile.module.registration.view.RegistrationSelectView)2 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 AuthResponse (org.edx.mobile.authentication.AuthResponse)1 FormFieldMessageBody (org.edx.mobile.model.api.FormFieldMessageBody)1 RegisterResponseFieldError (org.edx.mobile.model.api.RegisterResponseFieldError)1 RegistrationFormField (org.edx.mobile.module.registration.model.RegistrationFormField)1 SocialFactory (org.edx.mobile.social.SocialFactory)1 RegisterTask (org.edx.mobile.task.RegisterTask)1 DividerWithTextView (org.edx.mobile.view.custom.DividerWithTextView)1