Search in sources :

Example 41 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class DynamicTabAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    mMultiQuestionViews.clear();
    Validation.init();
    //init validation control(used only in multiquestions tabs)
    failedValidations = 0;
    //Inflate the layout
    View rowView = lInflater.inflate(R.layout.dynamic_tab_grid_question, parent, false);
    rowView.getLayoutParams().height = parent.getHeight();
    rowView.requestLayout();
    Question questionItem = (Question) this.getItem(position);
    // We get values from DB and put them in Session
    if (getMalariaSurvey() != null) {
        if (Session.getStockSurvey() != null) {
            Session.getStockSurvey().getValuesFromDB();
        }
        getMalariaSurvey().getValuesFromDB();
    } else {
        // getView is called.
        return convertView;
    }
    //Question
    CustomTextView headerView = (CustomTextView) rowView.findViewById(question);
    //Load a font which support Khmer character
    Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/" + context.getString(R.string.specific_language_font));
    headerView.setTypeface(tf);
    int tabType = questionItem.getHeader().getTab().getType();
    if (Tab.isMultiQuestionTab(tabType)) {
        headerView.setText(questionItem.getHeader().getTab().getInternationalizedName());
    } else if (Tab.isDynamicTreatmentTab(tabType)) {
        headerView.setText(questionItem.getHeader().getTab().getInternationalizedName());
    } else {
        headerView.setText(questionItem.getInternationalizedForm_name());
    }
    //question image
    if (questionItem.getPath() != null && !questionItem.getPath().equals("") && mDynamicTabAdapterStrategy.HasQuestionImageVisibleInHeader(questionItem.getOutput())) {
        ImageView imageView = (ImageView) rowView.findViewById(R.id.questionImage);
        BaseLayoutUtils.putImageInImageView(questionItem.getInternationalizedPath(), imageView);
        imageView.setVisibility(View.VISIBLE);
    }
    //Progress
    ProgressUtils.updateProgressBarStatus(rowView, navigationController.getCurrentPage(), navigationController.getCurrentTotalPages());
    List<Question> screenQuestions = new ArrayList<>();
    if (isTabScrollable(questionItem, tabType)) {
        tableLayout = (TableLayout) rowView.findViewById(R.id.multi_question_options_table);
        (rowView.findViewById(R.id.scrolled_table)).setVisibility(View.VISIBLE);
        (rowView.findViewById(R.id.no_scrolled_table)).setVisibility(View.GONE);
        if (tabType == Constants.TAB_DYNAMIC_TREATMENT) {
            Treatment treatment = new Treatment(Session.getMalariaSurvey(), Session.getStockSurvey());
            if (treatment.hasTreatment()) {
                screenQuestions = treatment.getQuestions();
                doseByQuestion = treatment.getDoseByQuestion();
            } else {
                screenQuestions = treatment.getNoTreatmentQuestions();
            }
        } else if (Tab.isMultiQuestionTab(tabType)) {
            screenQuestions = questionItem.getQuestionsByTab(questionItem.getHeader().getTab());
        } else {
            screenQuestions.add(questionItem);
        }
        swipeTouchListener.addScrollView((ScrollView) (rowView.findViewById(R.id.scrolled_table)).findViewById(R.id.table_scroll));
    } else {
        tableLayout = (TableLayout) rowView.findViewById(R.id.dynamic_tab_options_table);
        (rowView.findViewById(R.id.no_scrolled_table)).setVisibility(View.VISIBLE);
        (rowView.findViewById(R.id.scrolled_table)).setVisibility(View.GONE);
        screenQuestions.add(questionItem);
    }
    navigationButtonHolder = rowView.findViewById(R.id.snackbar);
    if (GradleVariantConfig.isButtonNavigationActive()) {
        initializeNavigationButtons(navigationButtonHolder);
        isClicked = false;
    }
    Log.d(TAG, "Questions in actual tab: " + screenQuestions.size());
    swipeTouchListener.clearClickableViews();
    for (Question screenQuestion : screenQuestions) {
        renderQuestion(rowView, tabType, screenQuestion);
    }
    rowView.requestLayout();
    reloadingQuestionFromInvalidOption = false;
    //FIXME: 09/03/2017  Refactor: This is used to prevent multiple open and close surveys crash
    Session.setIsLoadingSurvey(false);
    if (Session.shouldPressBackOnLoadSurvey()) {
        DashboardActivity.dashboardActivity.runOnUiThread(new Runnable() {

            public void run() {
                DashboardActivity.dashboardActivity.onBackPressed();
            }
        });
    }
    return rowView;
}
Also used : CustomTextView(org.eyeseetea.sdk.presentation.views.CustomTextView) Treatment(org.eyeseetea.malariacare.domain.entity.Treatment) Typeface(android.graphics.Typeface) ArrayList(java.util.ArrayList) Question(org.eyeseetea.malariacare.data.database.model.Question) ImageView(android.widget.ImageView) 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) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView) NumberRadioButtonMultiquestionView(org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView) ScrollView(android.widget.ScrollView)

Example 42 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class NavigationController method previous.

/**
     * Returns the previous question
     */
public Question previous() {
    Log.d(TAG, "previous()...");
    //First position -> cannot move
    if (this.currentPosition <= 0) {
        Log.d(TAG, String.format("previous()->No previous question"));
        return null;
    }
    //Moving backwards removes current node in screen (unless a special node)
    if (nonVisibleNode == null) {
        this.visited.remove(currentPosition);
        currentPosition--;
    } else {
        //Abandoning temporal node
        nonVisibleNode = null;
    }
    //Return the 'new' last question
    Question previousQuestion = getCurrentNode().getQuestion();
    Log.d(TAG, String.format("previous()->%s", previousQuestion.getCode()));
    return previousQuestion;
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 43 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class NavigationController method isNextAllowed.

/**
     * Tells if you can move forward:
     * - Not even started: true
     * -
     * Cann
     */
public boolean isNextAllowed() {
    if (isMovingToForward) {
        return false;
    }
    QuestionNode currentQuestionNode = getCurrentNode();
    //not even start
    if (currentQuestionNode == null) {
        return true;
    }
    //Get value for current
    Question currentQuestion = getCurrentQuestion();
    Value currentValue = currentQuestion.getValueBySession();
    //Cannot move without answer
    if (currentValue == null) {
        Log.d(TAG, "isNextAllowed()->You must answer first");
        return false;
    }
    Option currentOption = currentValue == null ? null : currentValue.getOption();
    //Find next node with current option
    boolean isAllowed = findNext(currentOption) != null;
    Log.d(TAG, String.format("isNextAllowed()->%b", isAllowed));
    return isAllowed;
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 44 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class NavigationController method findNext.

private QuestionNode findNext(Option option) {
    Log.d(TAG, String.format("findNext(%s)...", option == null ? "" : option.getInternationalizedCode()));
    //First movement (entering survey)
    if (isInitialMove()) {
        Log.d(TAG, String.format("findNext(%s)-> Initial movement", option == null ? "" : option.getInternationalizedCode()));
        return this.rootNode;
    }
    Question actualQuestion = getCurrentNode().getQuestion();
    QuestionNode nextNode;
    nextNode = getCurrentNode().next(option);
    if (nextNode != null && (actualQuestion.getHeader().getTab().getType() == Constants.TAB_MULTI_QUESTION || actualQuestion.getHeader().getTab().getType() == Constants.TAB_DYNAMIC_TREATMENT || nextNode.getQuestion().getOutput() == Constants.HIDDEN)) {
        while (nextNode != null && (nextNode.getQuestion().getHeader().getTab().equals(actualQuestion.getHeader().getTab()) || nextNode.getQuestion().getOutput() == Constants.HIDDEN)) {
            Option optionNext = nextNode.getQuestion().getOptionBySession();
            nextNode = nextNode.next(optionNext);
        }
    }
    //Survey finished -> No more questions
    if (nextNode == null) {
        Map<Long, QuestionCounter> counters = getCurrentNode().getCountersMap();
        if (counters == null || counters.size() == 0) {
            Log.d(TAG, String.format("findNext(%s)-> Survey finished", option == null ? "" : option.getInternationalizedCode()));
            return null;
        }
        if (option != null && counters.containsKey(option.getId_option())) {
            QuestionCounter questionCounter = counters.get(option.getId_option());
            Integer limit = (int) Math.floor(option.getFactor());
            Log.d(TAG, String.format("findNext(%s)-> Survey(%s)finished", option == null ? "" : option.getInternationalizedCode(), (questionCounter.isMaxCounterLimit(limit)) ? " " : " not "));
            return (questionCounter.isMaxCounterLimit(limit)) ? null : getCurrentNode().getPreviousSibling();
        }
    }
    //Return next question
    if (nextNode != null && nextNode.getQuestion() != null) {
        Log.d(TAG, String.format("findNext(%s)->%s", option == null ? "" : option.getInternationalizedCode(), nextNode.getQuestion().getCode() + ""));
    }
    return nextNode;
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 45 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class WarningStatusChecker method isEnabled.

@Override
public boolean isEnabled() {
    //Warning not built yet -> false
    if (questionThreshold == null || questionOption == null) {
        return false;
    }
    //Get current values in DB
    Question questionWithOption = questionOption.getQuestion();
    Value optionValue = questionWithOption.getValueBySession();
    Value intValue = questionThreshold.getQuestion().getValueBySession();
    //A question is not answered yet -> false
    if (optionValue == null || optionValue.getOption() == null || intValue == null) {
        return false;
    }
    //The option for this warning has not been selected
    if (optionValue.getId_option() != questionOption.getOption().getId_option()) {
        return false;
    }
    //If current int value NOT in threshold -> the warning is activated
    return !questionThreshold.isInThreshold(intValue.getValue());
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Aggregations

Question (org.eyeseetea.malariacare.data.database.model.Question)58 Option (org.eyeseetea.malariacare.data.database.model.Option)15 Value (org.eyeseetea.malariacare.data.database.model.Value)15 CSVReader (com.opencsv.CSVReader)11 InputStreamReader (java.io.InputStreamReader)11 ArrayList (java.util.ArrayList)7 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)7 View (android.view.View)6 Answer (org.eyeseetea.malariacare.data.database.model.Answer)5 Match (org.eyeseetea.malariacare.data.database.model.Match)5 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)5 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)5 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)5 DynamicStockImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)5 TableRow (android.widget.TableRow)4 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)4 IImageQuestionView (org.eyeseetea.malariacare.views.question.IImageQuestionView)4 IMultiQuestionView (org.eyeseetea.malariacare.views.question.IMultiQuestionView)4 NumberRadioButtonMultiquestionView (org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView)4 ImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView)4