Skip to content

Commit

Permalink
Merge pull request #27 from chrqls/dev
Browse files Browse the repository at this point in the history
[#23] Retake button v1
  • Loading branch information
chrqls committed Mar 24, 2014
2 parents 7d7a4bd + 24ceea9 commit b22897f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 53 deletions.
34 changes: 15 additions & 19 deletions src/main/java/org/smilec/smile/bu/SmilePlugServerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,30 +298,26 @@ public void startSolvingQuestions(String ip, Context context) throws NetworkErro
}

public void startRetakeQuestions(String ip, Context context, Board board) throws NetworkErrorException {
String url = "http://" + ip + "/" + SmilePlugUtil.RETAKE_QUESTIONS_URL;

String url = "http://" + ip + "/" + SmilePlugUtil.RETAKE_QUESTIONS_URL;

int questionsNumber = board.getQuestionsNumber();
Collection<Question> questions = board.getQuestions();
List<Integer> answersList = new ArrayList<Integer>();

try {
JSONObject retakeJson = new JSONObject();
int questionsNumber = board.getQuestionsNumber();
Collection<Question> questions = board.getQuestions();
List<Integer> answersList = new ArrayList<Integer>();
for (Iterator<Question> iterator = questions.iterator(); iterator.hasNext();) {
for (Iterator<Question> iterator = questions.iterator(); iterator.hasNext();) {
Question question = (Question) iterator.next();
answersList.add(question.getAnswer());
}
JSONArray answers = new JSONArray(answersList);

retakeJson.put("TIME_LIMIT", 10);
retakeJson.put("NUMQ", questionsNumber);
retakeJson.put("RANSWER", answers);

post(ip, context, url, retakeJson.toString());

} catch (JSONException e) {
new SendEmailAsyncTask(e.getMessage(),JSONException.class.getName(),SmilePlugServerManager.class.getName()).execute();
e.printStackTrace();
}

JSONArray answers = new JSONArray(answersList);

post(ip, context, url, "{TYPE:'RE_TAKE',RANSWER:"+answers.toString()+",TIME_LIMIT:'"+10+"',NUMQ:'"+questionsNumber+"'}");

} catch (Exception e) {
Log.e("SMILE_TEACHER:SmilePlugServerManager", "ERROR, reason: " + e.getMessage());
e.printStackTrace();
}
}

public void showResults(String ip, Context context) throws NetworkErrorException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum CurrentMessageStatus {
WAIT_CONNECT("Wait connect"),
START_MAKE("Make Questions"),
START_SOLVE("Solve Questions"),
START_SHOW("Show Results");
START_SHOW("Show Results"),
RE_TAKE("Retake iqset");

private String status;

Expand Down
39 changes: 23 additions & 16 deletions src/main/java/org/smilec/smile/ui/GeneralActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ private void updateCurrentFragment(Board newBoard) {
protected void onResume() {
super.onResume();

// If we retake, we "reload" the status to START_MAKE phase
if(status.equals(CurrentMessageStatus.RE_TAKE.name())) {

status = CurrentMessageStatus.START_MAKE.name();
}

btSolve.setOnClickListener(new SolveButtonListener());
btResults.setOnClickListener(new ResultsButtonListener());

Expand Down Expand Up @@ -394,29 +400,23 @@ protected void onStop() {
public boolean onPrepareOptionsMenu(Menu menu) {

/**
* TODO Until we implement retake button, we don't display it.
* Here is the code to implement it.
* To replace with 'menu.removeItem(R.id.bt_retake);' just below
* (cf. issue #55)
* TODO retake scenario (cf. issue #55)
* */
// if (btResults.isEnabled()) {
// MenuItem item = menu.findItem(R.id.bt_retake);
// if (item == null) {
// menu.add(0, R.id.bt_retake, Menu.NONE, R.string.retake).setIcon(R.drawable.retake);
// }
// } else {
// menu.removeItem(R.id.bt_retake);
// }

// Temporary
menu.removeItem(R.id.bt_retake);
if (btResults.isEnabled()) {
MenuItem item = menu.findItem(R.id.bt_retake);
if (item == null) {
menu.add(0, R.id.bt_retake, Menu.NONE, R.string.retake).setIcon(R.drawable.retake);
}
} else {
menu.removeItem(R.id.bt_retake);
}

return super.onPrepareOptionsMenu(menu);
}

@SuppressWarnings("deprecation")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.bt_restart:
AlertDialog.Builder builderRestart = new AlertDialog.Builder(this);
Expand Down Expand Up @@ -455,6 +455,13 @@ public void onClick(DialogInterface dialog, int id) {
try {
new SmilePlugServerManager().startRetakeQuestions(ip, GeneralActivity.this, board);
ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_retaking);

Intent intent = new Intent(GeneralActivity.this, org.smilec.smile.ui.UsePreparedQuestionsActivity.class);
intent.putExtra(GeneralActivity.PARAM_IP, ip);
status = CurrentMessageStatus.RE_TAKE.name();
intent.putExtra(GeneralActivity.PARAM_STATUS, status);
startActivity(intent);

} catch (NetworkErrorException e) {
Log.e(Constants.LOG_CATEGORY, "Error: ", e);
}
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/org/smilec/smile/ui/UsePreparedQuestionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.smilec.smile.bu.QuestionsManager;
import org.smilec.smile.bu.SmilePlugServerManager;
import org.smilec.smile.bu.exception.DataAccessException;
import org.smilec.smile.domain.CurrentMessageStatus;
import org.smilec.smile.domain.IQSet;
import org.smilec.smile.domain.Question;
import org.smilec.smile.domain.Results;
Expand Down Expand Up @@ -166,7 +167,7 @@ private class LoadButtonListener implements OnClickListener {
@Override
public void onClick(View v) {

if (status != null && !status.equals("") && !status.equals("START_MAKE")) {
if (status != null && !status.equals("") && !status.equals("START_MAKE") && !status.equals(CurrentMessageStatus.RE_TAKE.name())) {

Log.d("SMILE Teacher", "Status = " + status);

Expand Down Expand Up @@ -296,10 +297,11 @@ protected void onPostExecute(File[] fileQuestions) {

boolean iqsetsExist = false;

try
{iqsetsExist = new SmilePlugServerManager().iqsetsExist(ip, context); }
catch (NetworkErrorException e)
{ e.printStackTrace(); }
try {
iqsetsExist = new SmilePlugServerManager().iqsetsExist(ip, context);
} catch (NetworkErrorException e) {
e.printStackTrace();
}

if (iqsetsExist) {
UsePreparedQuestionsActivity.this.loadIQSets();
Expand Down Expand Up @@ -354,17 +356,18 @@ protected void onPostExecute(String message) {
}

private void openGeneralActivity() {
Intent intent = new Intent(this, GeneralActivity.class);
intent.putExtra(GeneralActivity.PARAM_IP, ip);
intent.putExtra(GeneralActivity.PARAM_RESULTS, results);
intent.putExtra(GeneralActivity.PARAM_STATUS, status);
intent.putExtra(GeneralActivity.PARAM_HOURS, spinnerHours.getSelectedItem().toString());
intent.putExtra(GeneralActivity.PARAM_MINUTES, spinnerMinutes.getSelectedItem().toString());
intent.putExtra(GeneralActivity.PARAM_SECONDS, spinnerSeconds.getSelectedItem().toString());
startActivity(intent);

ActivityUtil.showLongToast(this, R.string.toast_starting);


if(!status.equals("RE_TAKE")) {
Intent intent = new Intent(this, GeneralActivity.class);
intent.putExtra(GeneralActivity.PARAM_IP, ip);
intent.putExtra(GeneralActivity.PARAM_RESULTS, results);
intent.putExtra(GeneralActivity.PARAM_STATUS, status);
intent.putExtra(GeneralActivity.PARAM_HOURS, spinnerHours.getSelectedItem().toString());
intent.putExtra(GeneralActivity.PARAM_MINUTES, spinnerMinutes.getSelectedItem().toString());
intent.putExtra(GeneralActivity.PARAM_SECONDS, spinnerSeconds.getSelectedItem().toString());
startActivity(intent);
}
ActivityUtil.showLongToast(this, R.string.toast_starting);
this.finish();
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/smilec/smile/util/SmilePlugUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SmilePlugUtil {

public static final String START_MAKING_QUESTIONS_URL = "startmakequestion";
public static final String START_SOLVING_QUESTIONS_URL = "startsolvequestion";
public static final String RETAKE_QUESTIONS_URL = "junctionserverexecution/pushmsg.php";
public static final String RETAKE_QUESTIONS_URL = "JunctionServerExecution/pushmsg.php";
// public static final String RETAKE_QUESTIONS_URL = "junctionserverexecution/current/MSG/smsg.txt";

public static final String SHOW_RESULTS_URL = "sendshowresults";
Expand Down

0 comments on commit b22897f

Please sign in to comment.