Skip to content

Commit

Permalink
Added show_standard_instructions feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jbc25 committed Feb 29, 2024
1 parent 5d22da6 commit 0417863
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
/*
/*
* This file is part of OppiaMobile - https://digital-campus.org/
*
*
* OppiaMobile is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* OppiaMobile is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with OppiaMobile. If not, see <http://www.gnu.org/licenses/>.
*/

package org.digitalcampus.oppia.widgets.quiz;

import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
Expand All @@ -34,68 +33,75 @@
import java.util.Collections;
import java.util.List;

public class MultiChoiceWidget extends QuestionWidget{

public static final String TAG = MultiChoiceWidget.class.getSimpleName();

private QuizQuestion question;

public MultiChoiceWidget(Activity activity, View v, ViewGroup container, QuizQuestion q) {
super(activity, v, container, R.layout.widget_quiz_multichoice);
this.question = q;
}

@Override
public void setQuestionResponses(List<String> currentAnswers) {
// not used for this widget
}

@Override
public void setQuestionResponses(List<Response> responses, List<String> currentAnswer) {
LinearLayout responsesLL = view.findViewById(R.id.questionresponses);
responsesLL.removeAllViews();
RadioGroup responsesRG = new RadioGroup(ctx);
responsesRG.setId(R.id.multichoiceRadioGroup);
responsesLL.addView(responsesRG);
String shuffle = question.getProp("shuffleanswers");
if ((shuffle != null) && shuffle.equals("1")){
Collections.shuffle(responses);
}

int id = 1000+1;
for (Response r : responses){
RadioButton rb = new RadioButton(ctx, null, 0, R.style.QuizCheckableItem);
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
setResponseMarginInLayoutParams(params);
rb.setId(id);
rb.setText(UIUtils.getFromHtmlAndTrim(r.getTitle(currentUserLang)));
responsesRG.addView(rb, params);
public class MultiChoiceWidget extends QuestionWidget {

public static final String TAG = MultiChoiceWidget.class.getSimpleName();

private QuizQuestion question;

public MultiChoiceWidget(Activity activity, View v, ViewGroup container, QuizQuestion q) {
super(activity, v, container, R.layout.widget_quiz_multichoice);
this.question = q;
}

@Override
public void setQuestionResponses(List<String> currentAnswers) {
// not used for this widget
}

@Override
public void setQuestionResponses(List<Response> responses, List<String> currentAnswer) {
LinearLayout responsesLL = view.findViewById(R.id.questionresponses);
responsesLL.removeAllViews();
RadioGroup responsesRG = new RadioGroup(ctx);
responsesRG.setId(R.id.multichoiceRadioGroup);
responsesLL.addView(responsesRG);
String shuffle = question.getProp("shuffleanswers");
if ((shuffle != null) && shuffle.equals("1")) {
Collections.shuffle(responses);
}

String showStandardInstructions = question.getProp("show_standard_instructions");
View tvInstructions = view.findViewById(R.id.tv_instructions);
if (tvInstructions != null) {
boolean visible = showStandardInstructions != null && showStandardInstructions.equals("1");
tvInstructions.setVisibility(visible ? View.VISIBLE : View.GONE);
}

int id = 1000 + 1;
for (Response r : responses) {
RadioButton rb = new RadioButton(ctx, null, 0, R.style.QuizCheckableItem);
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
setResponseMarginInLayoutParams(params);
rb.setId(id);
rb.setText(UIUtils.getFromHtmlAndTrim(r.getTitle(currentUserLang)));
responsesRG.addView(rb, params);
for (String answer : currentAnswer) {
if (answer.equals(r.getTitle(currentUserLang))){
if (answer.equals(r.getTitle(currentUserLang))) {
rb.setChecked(true);
}
}
id++;
}
}
public List<String> getQuestionResponses(List<Response> responses){
RadioGroup responsesRG = view.findViewById(R.id.multichoiceRadioGroup);
int resp = responsesRG.getCheckedRadioButtonId();
View rb = responsesRG.findViewById(resp);
int idx = responsesRG.indexOfChild(rb);
List<String> response = new ArrayList<>();
if (idx >= 0){
response.add(responses.get(idx).getTitle(currentUserLang));
}
return response;
}

@Override
public List<String> getQuestionResponses() {
return new ArrayList<>();
}
id++;
}

}

public List<String> getQuestionResponses(List<Response> responses) {
RadioGroup responsesRG = view.findViewById(R.id.multichoiceRadioGroup);
int resp = responsesRG.getCheckedRadioButtonId();
View rb = responsesRG.findViewById(resp);
int idx = responsesRG.indexOfChild(rb);
List<String> response = new ArrayList<>();
if (idx >= 0) {
response.add(responses.get(idx).getTitle(currentUserLang));
}
return response;
}

@Override
public List<String> getQuestionResponses() {
return new ArrayList<>();
}

}
27 changes: 19 additions & 8 deletions app/src/main/res/layout/widget_quiz_multichoice.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/questionresponses"
android:layout_margin="10dp">
</LinearLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/tv_instructions"
style="@style/TextBase"
android:text="@string/select_one"
android:textStyle="italic"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:visibility="gone"/>

<LinearLayout
android:id="@+id/questionresponses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical" />
</LinearLayout>
25 changes: 17 additions & 8 deletions app/src/main/res/layout/widget_quiz_multiselect.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/questionresponses"
android:layout_margin="10dp">
</LinearLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
style="@style/TextBase"
android:text="@string/select_one_or_more"
android:textStyle="italic"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"/>

<LinearLayout
android:id="@+id/questionresponses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical" />
</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@
<string name="offline_course_import.media_files_imported">Media files imported</string>
<string name="offline_course_import.course_files_imported">Course files imported</string>
<string name="bluetooth_not_supported">Bluetooth not supported</string>
<string name="select_one_or_more">(Select one or more)</string>
<string name="select_one">(Select one)</string>

</resources>

0 comments on commit 0417863

Please sign in to comment.