Search in sources :

Example 1 with DynamicStockImageRadioButtonSingleQuestionView

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

the class SingleQuestionViewFactory method getView.

public IQuestionView getView(Context context, int typeQuestion) {
    switch(typeQuestion) {
        case Constants.PHONE:
            return new PhoneSingleQuestionView(context);
        case Constants.POSITIVE_INT:
            return new PositiveNumberSingleQuestionView(context);
        case Constants.POSITIVE_OR_ZERO_INT:
            return new PositiveOrZeroNumberMultiQuestionView(context);
        case Constants.IMAGE_RADIO_GROUP_NO_DATAELEMENT:
            return new ImageRadioButtonSingleQuestionView(context);
        case Constants.IMAGE_RADIO_GROUP:
            return new ImageRadioButtonSingleQuestionView(context);
        case Constants.DYNAMIC_STOCK_IMAGE_RADIO_BUTTON:
            return new DynamicStockImageRadioButtonSingleQuestionView(context);
        case Constants.REMINDER:
        case Constants.WARNING:
            return new ReminderSingleQuestionView(context);
        case Constants.IMAGES_2:
        case Constants.IMAGES_4:
        case Constants.IMAGES_6:
        case Constants.IMAGES_5:
            ImageOptionSingleQuestionView twoColumnsImageOptionSingleQuestionView = new ImageOptionSingleQuestionView(context);
            twoColumnsImageOptionSingleQuestionView.setColumnsCount(2);
            return twoColumnsImageOptionSingleQuestionView;
        case Constants.IMAGES_3:
        case Constants.IMAGE_3_NO_DATAELEMENT:
            ImageOptionSingleQuestionView imageOptionSingleQuestionView = new ImageOptionSingleQuestionView(context);
            imageOptionSingleQuestionView.setColumnsCount(1);
            return imageOptionSingleQuestionView;
    }
    return null;
}
Also used : ReminderSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ReminderSingleQuestionView) PhoneSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.PhoneSingleQuestionView) PositiveNumberSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.PositiveNumberSingleQuestionView) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) PositiveOrZeroNumberMultiQuestionView(org.eyeseetea.malariacare.views.question.multiquestion.PositiveOrZeroNumberMultiQuestionView) ImageOptionSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageOptionSingleQuestionView) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) ImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView)

Example 2 with DynamicStockImageRadioButtonSingleQuestionView

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

the class DynamicTabAdapter method configureAnswerChangedListener.

private void configureAnswerChangedListener(IQuestionView questionView) {
    if (questionView instanceof AKeyboardQuestionView) {
        ((AKeyboardQuestionView) questionView).setOnAnswerChangedListener(new QuestionAnswerChangedListener(tableLayout, this, !GradleVariantConfig.isButtonNavigationActive()));
    } else if (questionView instanceof AOptionQuestionView) {
        ((AOptionQuestionView) questionView).setOnAnswerChangedListener(new QuestionAnswerChangedListener(tableLayout, this, !GradleVariantConfig.isButtonNavigationActive()));
    } else if (questionView instanceof NumberRadioButtonMultiquestionView) {
        ((NumberRadioButtonMultiquestionView) questionView).setOnAnswerChangedListener(new QuestionAnswerChangedListener(tableLayout, this, !GradleVariantConfig.isButtonNavigationActive()));
        ((NumberRadioButtonMultiquestionView) questionView).setOnAnswerOptionChangedListener(new QuestionAnswerChangedListener(tableLayout, this, !GradleVariantConfig.isButtonNavigationActive()));
    } else if (questionView instanceof DynamicStockImageRadioButtonSingleQuestionView) {
        ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOnAnswerChangedListener(new QuestionAnswerChangedListener(tableLayout, this, !GradleVariantConfig.isButtonNavigationActive()));
        ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOnAnswerOptionChangedListener(new QuestionAnswerChangedListener(tableLayout, this, !GradleVariantConfig.isButtonNavigationActive()));
    }
}
Also used : AKeyboardQuestionView(org.eyeseetea.malariacare.views.question.AKeyboardQuestionView) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) NumberRadioButtonMultiquestionView(org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) QuestionAnswerChangedListener(org.eyeseetea.malariacare.layout.listeners.question.QuestionAnswerChangedListener)

Example 3 with DynamicStockImageRadioButtonSingleQuestionView

use of org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView 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) || Tab.isDynamicTreatmentTab(tabType)) ? new MultiQuestionViewFactory() : new SingleQuestionViewFactory();
    // Se get the value from Session
    int visibility = View.GONE;
    Survey survey = (screenQuestion.isStockQuestion() || screenQuestion.isDynamicStockQuestion()) ? Session.getStockSurvey() : getMalariaSurvey();
    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());
        }
        if (screenQuestion.isDynamicStockQuestion()) {
            Treatment treatment = new Treatment(getMalariaSurvey(), Session.getStockSurvey());
            if (treatment.hasTreatment()) {
                org.eyeseetea.malariacare.data.database.model.Treatment dbTreatment = treatment.getTreatment();
                Question actAnsweredNo = treatment.getACTQuestionAnsweredNo();
                screenQuestion.setAnswer(treatment.getACTOptions(dbTreatment));
                ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptionDose(treatment.getOptionDose(dbTreatment));
            }
            ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setQuestion(screenQuestion);
            ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
            //Getting the question to put the correct values on it
            ArrayList<Question> questions = new ArrayList<>();
            for (Option option : screenQuestion.getAnswer().getOptions()) {
                Question question = Question.findByID(option.getId_option());
                if (question != null) {
                    questions.add(question);
                }
            }
            survey.getValuesFromDB();
            for (Question question : questions) {
                Value valueStock = question.getValueBySession();
                questionView.setValue(valueStock);
            }
        }
        if (questionView instanceof AOptionQuestionView) {
            ((AOptionQuestionView) questionView).setQuestion(screenQuestion);
            List<Option> options = screenQuestion.getAnswer().getOptions();
            ((AOptionQuestionView) questionView).setOptions(options);
        }
        if (questionView instanceof NumberRadioButtonMultiquestionView) {
            if (doseByQuestion != null) {
                ((NumberRadioButtonMultiquestionView) questionView).setDose(doseByQuestion.get(screenQuestion.getId_question()));
            }
            ((NumberRadioButtonMultiquestionView) questionView).setQuestion(screenQuestion);
            ((NumberRadioButtonMultiquestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
        }
        if (!readOnly) {
            configureAnswerChangedListener(questionView);
        }
        if (reloadingQuestionFromInvalidOption) {
            reloadingQuestionFromInvalidOption = false;
        } else {
            questionView.setValue(value);
        }
        setupNavigationByQuestionView(rowView.getRootView(), questionView);
        tableRow.addView((View) questionView);
        swipeTouchListener.addClickableView(tableRow);
        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) ArrayList(java.util.ArrayList) 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) Treatment(org.eyeseetea.malariacare.domain.entity.Treatment) TableRow(android.widget.TableRow) Value(org.eyeseetea.malariacare.data.database.model.Value) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) NumberRadioButtonMultiquestionView(org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView) 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) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView)

Aggregations

DynamicStockImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)3 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)2 NumberRadioButtonMultiquestionView (org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView)2 TableRow (android.widget.TableRow)1 ArrayList (java.util.ArrayList)1 Option (org.eyeseetea.malariacare.data.database.model.Option)1 Question (org.eyeseetea.malariacare.data.database.model.Question)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 Treatment (org.eyeseetea.malariacare.domain.entity.Treatment)1 QuestionAnswerChangedListener (org.eyeseetea.malariacare.layout.listeners.question.QuestionAnswerChangedListener)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 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)1 AKeyboardQuestionView (org.eyeseetea.malariacare.views.question.AKeyboardQuestionView)1 IImageQuestionView (org.eyeseetea.malariacare.views.question.IImageQuestionView)1 IMultiQuestionView (org.eyeseetea.malariacare.views.question.IMultiQuestionView)1