Search in sources :

Example 1 with RegistrationSelectView

use of org.edx.mobile.module.registration.view.RegistrationSelectView 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)

Aggregations

LayoutInflater (android.view.LayoutInflater)1 ArrayList (java.util.ArrayList)1 HttpStatusException (org.edx.mobile.http.HttpStatusException)1 RegistrationFormField (org.edx.mobile.module.registration.model.RegistrationFormField)1 IRegistrationFieldView (org.edx.mobile.module.registration.view.IRegistrationFieldView)1 RegistrationSelectView (org.edx.mobile.module.registration.view.RegistrationSelectView)1