Search in sources :

Example 1 with IMultiQuestionView

use of org.eyeseetea.malariacare.views.question.IMultiQuestionView in project pictureapp by EyeSeeTea.

the class DynamicTabAdapter method initializeNavigationButtons.

private void initializeNavigationButtons(View navigationButtonsHolder) {
    ImageButton button = (ImageButton) navigationButtonsHolder.findViewById(R.id.next_btn);
    ((LinearLayout) button.getParent()).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isClicked) {
                Log.d(TAG, "onClick ignored to avoid double click");
                return;
            }
            Log.d(TAG, "onClicked");
            isClicked = true;
            boolean questionsWithError = false;
            for (IMultiQuestionView multiquestionView : mMultiQuestionViews) {
                if (((CommonQuestionView) multiquestionView).isActive() && multiquestionView.hasError()) {
                    questionsWithError = true;
                    break;
                }
            }
            Log.d(TAG, "Questions with failed validation " + failedValidations);
            if (failedValidations == 0 && !questionsWithError) {
                TableRow currentRow = (TableRow) tableLayout.getChildAt(0);
                if (!readOnly && currentRow != null && currentRow.getChildAt(0) instanceof ImageRadioButtonSingleQuestionView) {
                    navigationController.isMovingToForward = true;
                    ImageRadioButtonSingleQuestionView imageRadioButtonSingleQuestionView = (ImageRadioButtonSingleQuestionView) currentRow.getChildAt(0);
                    ImageRadioButtonOption selectedOptionView = imageRadioButtonSingleQuestionView.getSelectedOptionView();
                    if (selectedOptionView != null) {
                        final Question question = navigationController.getCurrentQuestion();
                        Option selectedOption = selectedOptionView.getOption();
                        Question counterQuestion = question.findCounterByOption(selectedOption);
                        if ((mReviewMode && isCounterValueEqualToMax(question, selectedOption))) {
                            saveOptionValue(selectedOptionView, selectedOptionView.getOption(), question, true);
                        } else if (counterQuestion != null) {
                            showConfirmCounter(selectedOptionView, selectedOptionView.getOption(), question, counterQuestion);
                        } else {
                            finishOrNext();
                        }
                    } else {
                        isClicked = false;
                    }
                } else {
                    finishOrNext();
                }
            } else if (navigationController.getCurrentQuestion().hasCompulsoryNotAnswered() || mDynamicTabAdapterStrategy.isMultiQuestionByVariant(navigationController.getCurrentTab().getType())) {
                UIMessagesStrategy.getInstance().showCompulsoryUnansweredToast();
                isClicked = false;
                return;
            } else {
                isClicked = false;
            }
        }
    });
    button = (ImageButton) navigationButtonsHolder.findViewById(R.id.back_btn);
    // Save the numberpicker value in the DB, and continue to the next screen.
    ((LinearLayout) button.getParent()).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            previous();
        }
    });
}
Also used : ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) ImageButton(android.widget.ImageButton) TableRow(android.widget.TableRow) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) CommonQuestionView(org.eyeseetea.malariacare.views.question.CommonQuestionView) Question(org.eyeseetea.malariacare.data.database.model.Question) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) Option(org.eyeseetea.malariacare.data.database.model.Option) AKeyboardQuestionView(org.eyeseetea.malariacare.views.question.AKeyboardQuestionView) ImageView(android.widget.ImageView) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) View(android.view.View) INavigationQuestionView(org.eyeseetea.malariacare.views.question.INavigationQuestionView) IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView) ImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView) CustomTextView(org.eyeseetea.sdk.presentation.views.CustomTextView) ListView(android.widget.ListView) CommonQuestionView(org.eyeseetea.malariacare.views.question.CommonQuestionView) YearSelectorQuestionView(org.eyeseetea.malariacare.views.question.multiquestion.YearSelectorQuestionView) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView) ScrollView(android.widget.ScrollView) LinearLayout(android.widget.LinearLayout) ImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView)

Example 2 with IMultiQuestionView

use of org.eyeseetea.malariacare.views.question.IMultiQuestionView in project pictureapp by EyeSeeTea.

the class DynamicTabAdapter method renderQuestion.

public void renderQuestion(View rowView, int tabType, Question screenQuestion) {
    TableRow tableRow;
    IQuestionViewFactory questionViewFactory;
    questionViewFactory = (Tab.isMultiQuestionTab(tabType) || mDynamicTabAdapterStrategy.isMultiQuestionByVariant(tabType)) ? new MultiQuestionViewFactory() : new SingleQuestionViewFactory();
    // Se get the value from Session
    int visibility = View.GONE;
    Survey survey = new SurveyFragmentStrategy().getRenderSurvey(screenQuestion);
    if (!screenQuestion.isHiddenBySurveyAndHeader(survey) || !Tab.isMultiQuestionTab(tabType)) {
        visibility = View.VISIBLE;
    }
    Value value = screenQuestion.getValueBySession();
    tableRow = new TableRow(context);
    IQuestionView questionView = questionViewFactory.getView(context, screenQuestion.getOutput());
    if (questionView != null) {
        if (questionView instanceof IMultiQuestionView) {
            mMultiQuestionViews.add((IMultiQuestionView) questionView);
            ((IMultiQuestionView) questionView).setHeader(Utils.getInternationalizedString(screenQuestion.getForm_name()));
        }
        addTagQuestion(screenQuestion, (View) questionView);
        configureLayoutParams(tabType, tableRow, (LinearLayout) questionView);
        questionView.setHelpText(Utils.getInternationalizedString(screenQuestion.getHelp_text()));
        questionView.setEnabled(!readOnly);
        if (questionView instanceof IImageQuestionView) {
            ((IImageQuestionView) questionView).setImage(screenQuestion.getInternationalizedPath());
        }
        mDynamicTabAdapterStrategy.renderParticularSurvey(screenQuestion, survey, questionView);
        if (questionView instanceof AOptionQuestionView) {
            ((AOptionQuestionView) questionView).setQuestion(screenQuestion);
            List<Option> options = screenQuestion.getAnswer().getOptions();
            ((AOptionQuestionView) questionView).setOptions(options);
        }
        mDynamicTabAdapterStrategy.instanceOfSingleQuestion(questionView, screenQuestion);
        if (!readOnly) {
            configureAnswerChangedListener(questionView);
            mDynamicTabAdapterStrategy.configureAnswerChangedListener(this, questionView);
        }
        if (reloadingQuestionFromInvalidOption) {
            reloadingQuestionFromInvalidOption = false;
        } else {
            questionView.setValue(value);
        }
        setupNavigationByQuestionView(rowView.getRootView(), questionView);
        tableRow.addView((View) questionView);
        swipeTouchListener.addTouchableView(rowView);
        swipeTouchListener.addTouchableView(tableRow);
        swipeTouchListener.addTouchableView((View) questionView);
        swipeTouchListener.addClickableView((View) questionView);
        setVisibilityAndAddRow(tableRow, screenQuestion, visibility);
    }
}
Also used : SingleQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.SingleQuestionViewFactory) IQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.IQuestionViewFactory) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) MultiQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.MultiQuestionViewFactory) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) Session.getMalariaSurvey(org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey) Survey(org.eyeseetea.malariacare.data.database.model.Survey) IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView) SurveyFragmentStrategy(org.eyeseetea.malariacare.strategies.SurveyFragmentStrategy) TableRow(android.widget.TableRow) Value(org.eyeseetea.malariacare.data.database.model.Value) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) Option(org.eyeseetea.malariacare.data.database.model.Option) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView)

Example 3 with IMultiQuestionView

use of org.eyeseetea.malariacare.views.question.IMultiQuestionView in project pictureapp by EyeSeeTea.

the class DynamicTabAdapter method showOrHideChildren.

/**
 * Hide or show the childen question from a given question,  if is necessary  it reloads the
 * children questions values or refreshing the children questions answer component
 *
 * this code will be delete when DynamicTabAdapter refactoring will be completed
 *
 * @param question is the parent question
 */
private void showOrHideChildren(Question question) {
    if (!question.hasChildren()) {
        return;
    }
    for (int i = 0, j = tableLayout.getChildCount(); i < j; i++) {
        View view = tableLayout.getChildAt(i);
        if (view instanceof TableRow) {
            TableRow row = (TableRow) view;
            View targetView = row.getChildAt(0);
            if (targetView instanceof IMultiQuestionView || targetView instanceof IQuestionView) {
                Question rowQuestion = (Question) targetView.getTag();
                if (rowQuestion == null) {
                    continue;
                }
                List<Question> questionChildren = question.getChildren();
                if (questionChildren != null && questionChildren.size() > 0) {
                    for (Question childQuestion : questionChildren) {
                        // if the table row question is child of the modified question...
                        toggleChild(row, rowQuestion, childQuestion);
                    }
                }
            }
        }
    }
}
Also used : IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView) TableRow(android.widget.TableRow) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) Question(org.eyeseetea.malariacare.data.database.model.Question) AKeyboardQuestionView(org.eyeseetea.malariacare.views.question.AKeyboardQuestionView) ImageView(android.widget.ImageView) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) View(android.view.View) INavigationQuestionView(org.eyeseetea.malariacare.views.question.INavigationQuestionView) IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView) ImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView) CustomTextView(org.eyeseetea.sdk.presentation.views.CustomTextView) ListView(android.widget.ListView) CommonQuestionView(org.eyeseetea.malariacare.views.question.CommonQuestionView) YearSelectorQuestionView(org.eyeseetea.malariacare.views.question.multiquestion.YearSelectorQuestionView) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView) ScrollView(android.widget.ScrollView)

Aggregations

TableRow (android.widget.TableRow)3 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)3 IImageQuestionView (org.eyeseetea.malariacare.views.question.IImageQuestionView)3 IMultiQuestionView (org.eyeseetea.malariacare.views.question.IMultiQuestionView)3 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 ScrollView (android.widget.ScrollView)2 Option (org.eyeseetea.malariacare.data.database.model.Option)2 Question (org.eyeseetea.malariacare.data.database.model.Question)2 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)2 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)2 AKeyboardQuestionView (org.eyeseetea.malariacare.views.question.AKeyboardQuestionView)2 CommonQuestionView (org.eyeseetea.malariacare.views.question.CommonQuestionView)2 INavigationQuestionView (org.eyeseetea.malariacare.views.question.INavigationQuestionView)2 YearSelectorQuestionView (org.eyeseetea.malariacare.views.question.multiquestion.YearSelectorQuestionView)2 ImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView)2 CustomTextView (org.eyeseetea.sdk.presentation.views.CustomTextView)2 ImageButton (android.widget.ImageButton)1