Search in sources :

Example 1 with IQuestionViewFactory

use of org.eyeseetea.malariacare.presentation.factory.IQuestionViewFactory 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)

Aggregations

TableRow (android.widget.TableRow)1 Option (org.eyeseetea.malariacare.data.database.model.Option)1 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)1 Survey (org.eyeseetea.malariacare.data.database.model.Survey)1 Value (org.eyeseetea.malariacare.data.database.model.Value)1 Session.getMalariaSurvey (org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey)1 IQuestionViewFactory (org.eyeseetea.malariacare.presentation.factory.IQuestionViewFactory)1 MultiQuestionViewFactory (org.eyeseetea.malariacare.presentation.factory.MultiQuestionViewFactory)1 SingleQuestionViewFactory (org.eyeseetea.malariacare.presentation.factory.SingleQuestionViewFactory)1 SurveyFragmentStrategy (org.eyeseetea.malariacare.strategies.SurveyFragmentStrategy)1 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)1 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)1 IImageQuestionView (org.eyeseetea.malariacare.views.question.IImageQuestionView)1 IMultiQuestionView (org.eyeseetea.malariacare.views.question.IMultiQuestionView)1 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)1