use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class DynamicStockImageRadioButtonSingleQuestionView method onCheckedChanged.
@Override
public void onCheckedChanged(ImageRadioButtonOption imageRadioButton, boolean value) {
if (value == false)
return;
for (int i = 0; i < answersContainer.getChildCount(); i++) {
ImageRadioButtonOption optionView = (ImageRadioButtonOption) answersContainer.getChildAt(i);
if (imageRadioButton != optionView && optionView.isChecked()) {
optionView.setChecked(false);
Question question = (Question) optionView.getTag();
if (!question.isOutStockQuestion()) {
notifyAnswerChanged(optionView, String.valueOf(-1));
} else {
List<Option> options = question.getAnswer().getOptions();
for (Option option : options) {
if (option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.false_option_id))) {
notifyAnsweOptionChange(optionView, option);
}
}
}
}
}
Question question = (Question) imageRadioButton.getTag();
if (!question.isOutStockQuestion()) {
notifyAnswerChanged(imageRadioButton, String.valueOf(optionDose.get(imageRadioButton.getOption().getId_option())));
} else {
List<Option> options = question.getAnswer().getOptions();
for (Option option : options) {
if (option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.true_option_id))) {
notifyAnsweOptionChange(imageRadioButton, option);
}
}
}
//Setting a value for the stock question to get max total question correct
View stockHideView = new View(context);
stockHideView.setTag(Treatment.getDynamicStockQuestion());
Question pqHideQuestion = Question.findByUID(context.getString(R.string.stockPqQuestionUID));
Option falseOption = Option.findById(41l);
Value valuePq = pqHideQuestion.getValueBySession();
if (valuePq != null) {
falseOption = valuePq.getOption();
}
notifyAnsweOptionChange(stockHideView, falseOption);
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class NumberRadioButtonMultiquestionView method changeTotalQuestions.
/**
* Changing the total questions of the alternative pq questions depending on the answer provided
*/
private void changeTotalQuestions() {
Question pqQuestion = Question.findByUID(context.getString(R.string.pqQuestionUID));
Question actQuestion = Question.findByUID(context.getString(R.string.alternativePqQuestionUID));
Question alternativePqQuestion = Question.findByUID(context.getString(R.string.alternativePqQuestionUID));
Value actValue = null;
Value pqValue = null;
List<Value> values = Session.getMalariaSurvey().getValuesFromDB();
for (Value sValue : values) {
if (sValue.getQuestion() == null) {
continue;
}
if (sValue.getQuestion().equals(actQuestion)) {
actValue = sValue;
break;
}
if (sValue.getQuestion().getUid().equals(pqQuestion.getUid())) {
pqValue = sValue;
break;
}
}
if ((actValue == null || actValue.getOption().getName().equals(PreferencesState.getInstance().getContext().getString(R.string.yes_option_identifier))) || (pqValue == null || Float.parseFloat(pqValue.getValue()) > 0)) {
alternativePqQuestion.setTotalQuestions(8);
} else {
alternativePqQuestion.setTotalQuestions(9);
}
alternativePqQuestion.save();
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class ImageOptionView method setCounter.
public void setCounter(Question question) {
Question optionCounter = question.findCounterByOption(mOption);
if (optionCounter == null) {
return;
}
String counterValue = optionCounter.getQuestionValueBySession();
if (counterValue == null || counterValue.isEmpty()) {
return;
}
String counterTextValue = getContext().getResources().getString(R.string.option_counter);
mOptionCounterTextView.setText(counterTextValue + counterValue);
mOptionCounterTextView.setVisibility(View.VISIBLE);
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method saveTextValue.
public void saveTextValue(View view, String newValue, boolean moveToNextQuestion) {
Question question = (Question) view.getTag();
question.saveValuesText(newValue);
if (moveToNextQuestion) {
navigationController.isMovingToForward = true;
finishOrNext();
} else {
showOrHideChildren(question);
}
}
use of org.eyeseetea.malariacare.data.database.model.Question 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);
}
}
}
}
}
}
Aggregations