Skip to content

Commit

Permalink
Completed feedback html file for multiselect
Browse files Browse the repository at this point in the history
bufixes
  • Loading branch information
jbc25 committed Mar 1, 2024
1 parent 0a21d87 commit 161bd6a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.digitalcampus.mobile.quiz.Quiz;
import org.digitalcampus.oppia.analytics.Analytics;
import org.digitalcampus.oppia.utils.TextUtilsJava;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -31,7 +30,7 @@
import java.util.List;
import java.util.Map;

public class QuizQuestion implements Serializable {
public abstract class QuizQuestion implements Serializable {

public static final String TAG = QuizQuestion.class.getSimpleName();
private static final long serialVersionUID = 852385823168202643L;
Expand All @@ -49,7 +48,7 @@ public class QuizQuestion implements Serializable {
protected List<Response> responseOptions = new ArrayList<>();
protected List<String> userResponses = new ArrayList<>();
protected String feedback = "";
protected String feedbackHtml = "";
protected String feedbackHtmlFile = "";
private boolean skipped;

public void addResponseOption(Response r) {
Expand All @@ -75,23 +74,9 @@ public void clearUserResponses() {
this.userResponses.clear();
}

public void mark(String lang) {
// loop through the responses
// find whichever are set as selected and add up the responses
float total = 0;
for (Response r : responseOptions) {
for (String a : userResponses) {
if (r.getTitle(lang).equals(a)) {
total += r.getScore();
feedback = r.getFeedback(lang);
feedbackHtml = r.getFeedbackHtml(lang);
}
}
}
this.calculateUserscore(total);
}
public abstract void mark(String lang);

public void calculateUserscore(float total){
protected void calculateUserscore(float total){
if (this.getProp(Quiz.JSON_PROPERTY_MAXSCORE) != null) {
int maxscore = Integer.parseInt(this.getProp(Quiz.JSON_PROPERTY_MAXSCORE));
if (total > maxscore) {
Expand Down Expand Up @@ -149,11 +134,11 @@ public String getFeedback(String lang) {
return this.feedback;
}

public String getFeedbackHtml(String lang) {
public String getFeedbackHtmlFile(String lang) {
// reset feedback back to nothing
this.feedbackHtml = "";
this.feedbackHtmlFile = "";
this.mark(lang);
return this.feedbackHtml;
return this.feedbackHtmlFile;
}

public int getMaxScore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class Description extends QuizQuestion {
private static final long serialVersionUID = 809312927290284785L;
public static final String TAG = Description.class.getSimpleName();

@Override
public void mark(String lang) {
// Nothing to do
}

@Override
public JSONObject responsesToJSON() {
JSONObject jo = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,30 @@

package org.digitalcampus.mobile.quiz.model.questiontypes;

import org.digitalcampus.mobile.quiz.model.Response;

import java.io.Serializable;

public class MultiChoice extends UserResponseQuestion implements Serializable {

private static final long serialVersionUID = -6605393327170759582L;
public static final String TAG = MultiChoice.class.getSimpleName();

@Override
public void mark(String lang) {
// loop through the responses
// find whichever are set as selected and add up the responses
float total = 0;
for (Response r : responseOptions) {
for (String a : userResponses) {
if (r.getTitle(lang).equals(a)) {
total += r.getScore();
feedback = r.getFeedback(lang);
feedbackHtmlFile = r.getFeedbackHtml(lang);
}
}
}
this.calculateUserscore(total);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,37 @@ public void mark(String lang){
} else {
userscore = total;
}

setFeedbackHtmlFile(lang);
Log.d(TAG, "User score for question: " + userscore);
}

private void setFeedbackHtmlFile(String lang) {
try {
String feedbackKey = "";
if (userscore == 0) {
feedbackKey = "incorrectfeedbackhtmlfile";
} else {
feedbackKey = "correctfeedbackhtmlfile";
}

if (getProps().containsKey(feedbackKey)) {
String incorrectFeedbackLangs = getProps().get(feedbackKey);
JSONObject feedbackHtmlLangs = new JSONObject(incorrectFeedbackLangs);

if (feedbackHtmlLangs.has(lang)) {
feedbackHtmlFile = feedbackHtmlLangs.getString(lang);
} else if (feedbackHtmlLangs.keys().hasNext()) {
feedbackHtmlFile = feedbackHtmlLangs.getString(feedbackHtmlLangs.keys().next());
} else {
feedbackHtmlFile = "";
}
}
} catch (JSONException e) {
Log.e(TAG, "setFeedbackHtmlFile: ", e);
}
}

private float setFeedback(String lang){
float total = 0;
StringBuilder questionFeedback = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,14 @@ private View.OnClickListener nextBtnClickListener() {
&& !quiz.getCurrentQuestion().getFeedbackDisplayed()) {

String feedback = quiz.getCurrentQuestion().getFeedback(prefLang);
String feedbackHtml = quiz.getCurrentQuestion().getFeedbackHtml(prefLang);
String feedbackHtmlFile = quiz.getCurrentQuestion().getFeedbackHtmlFile(prefLang);

if (feedbackHtml != null && !feedbackHtml.isEmpty()) {
showFeedbackHtml(feedbackHtml);
if (feedbackHtmlFile != null && !feedbackHtmlFile.isEmpty()) {
showFeedbackHtmlFile(feedbackHtmlFile);
} else if (feedback != null && !feedback.isEmpty()) {
showFeedback(feedback);
} else {
nextStep();
}
} else {
nextStep();
Expand Down Expand Up @@ -490,7 +492,7 @@ private void showFeedback(String msg) {
}
}

private void showFeedbackHtml(String htmlFile) {
private void showFeedbackHtmlFile(String htmlFile) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), R.style.Oppia_AlertDialogStyle);
WebView webView = new WebView(getContext());
webView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
Expand Down

0 comments on commit 161bd6a

Please sign in to comment.