Skip to content

Commit

Permalink
Merge pull request #102 from chrqls/dev
Browse files Browse the repository at this point in the history
[#101] Restart button will alert the teacher if server is down
  • Loading branch information
Charles Quelos committed Dec 25, 2013
2 parents 3251b5d + bb44d02 commit 77292df
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 26 deletions.
15 changes: 9 additions & 6 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<string name="group_name_hint">Group name</string>
<string name="date_hint">Date</string>
<string name="btn_create_session">Create</string>
<string name="creating_session">Creating session...</string>
<string name="no_picture">No picture</string>
<string name="delete_btn">Del btn</string>

Expand Down Expand Up @@ -70,18 +69,22 @@
<string name="minutes">Minutes</string>
<string name="hours">Hours</string>

<string name="connection_established">Connection established</string>

<string name="created_by">Question(s) created by</string>
<string name="top_scorer">Top Scorer</string>
<string name="answers">Complete</string>
<string name="question">Question</string>
<string name="question_uppercase">QUESTION</string>
<string name="student">Students</string>

<string name="starting">Starting...</string>
<string name="solving">Solving...</string>
<string name="recovering">Recovering...</string>
<!-- Toasts -->
<string name="toast_connection_established">Connection established</string>
<string name="toast_creating_session">Creating session...</string>
<string name="toast_starting">Starting...</string>
<string name="toast_solving">Solving...</string>
<string name="toast_sorting">Sorting...</string>
<string name="toast_recovering">Recovering...</string>
<string name="toast_retaking">Retaking...</string>
<string name="toast_down_or_unavailable">Smileplug is down or unavailable</string>

<string name="question_number">Question Number</string>
<string name="correct_answer">Correct Answer</string>
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/org/smilec/smile/bu/AbstractBaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@

public abstract class AbstractBaseManager {

protected static void checkServer(String ip) throws NetworkErrorException {
/**
* @return if the server is available or not
*/
protected static boolean checkServer(String ip) throws NetworkErrorException {

InputStream is = null;
String url = SmilePlugUtil.createUrl(ip);
boolean isAvailable = false;

try {
is = HttpUtil.executeGet(url);
if(is != null) isAvailable = true;
} catch (NetworkErrorException e) {
throw new NetworkErrorException("Connection errror: " + e.getMessage(), e);

throw new NetworkErrorException("Server unavailable: " + e.getMessage(), e);
} finally {
IOUtil.silentClose(is);
}

if (is == null) {
throw new NetworkErrorException("Server unavailable");
}

}
return isAvailable;
}

protected static void checkConnection(Context context) throws NetworkErrorException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void startUsingPreparedQuestions(String ip, Context context, Collection<Q
for (Question question : questions) {
LocalQuestionWrapper questionWrapper = new LocalQuestionWrapper(question);

// Add in a sessionID to inform the server thisz is coming from a teacher
// Add in a sessionID to inform the server this is coming from a teacher
questionWrapper.setSessionID(Long.toString(System.currentTimeMillis())); // XXX This really should be the sessionID from the server (via couchDB _ID)
Gson gson = new Gson();
String json = gson.toJson(questionWrapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public void onClick(View v) {
if (status != null && !status.equals("") && !status.equals("RESET")) {

new LoadTask(ChooseActivityFlowDialog.this).execute();
ActivityUtil.showLongToast(ChooseActivityFlowDialog.this, R.string.recovering);
ActivityUtil.showLongToast(ChooseActivityFlowDialog.this, R.string.toast_recovering);

} else {
new LoadTask(ChooseActivityFlowDialog.this).execute();
ActivityUtil.showLongToast(ChooseActivityFlowDialog.this, R.string.starting);
ActivityUtil.showLongToast(ChooseActivityFlowDialog.this, R.string.toast_starting);
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/smilec/smile/ui/GeneralActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
AlertDialog.Builder builderRestart = new AlertDialog.Builder(this);
builderRestart.setMessage(R.string.restart_game).setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override

@Override
public void onClick(DialogInterface dialog, int id) {
try {

try {
//new SmilePlugServerManager().connect(ip, GeneralActivity.this);

new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
// QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
GeneralActivity.this.finish();
} catch (NetworkErrorException e) {
ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_down_or_unavailable);
Log.e(Constants.LOG_CATEGORY, "Error: ", e);
}
}

}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Expand All @@ -444,7 +450,7 @@ public void onClick(DialogInterface dialog, int id) {
public void onClick(DialogInterface dialog, int id) {
try {
new SmilePlugServerManager().startRetakeQuestions(ip, GeneralActivity.this, board);
ActivityUtil.showLongToast(GeneralActivity.this, "Retaking...");
ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_retaking);
} catch (NetworkErrorException e) {
Log.e(Constants.LOG_CATEGORY, "Error: ", e);
}
Expand Down Expand Up @@ -563,12 +569,12 @@ public void onClick(View v) {
vTotal.setVisibility(View.VISIBLE);
}

ActivityUtil.showLongToast(GeneralActivity.this, "Sorting...");
ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_sorting);
}
}

private void startSolvingQuestion() {
ActivityUtil.showLongToast(GeneralActivity.this, R.string.solving);
ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_solving);

status = CurrentMessageStatus.START_SOLVE.name();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/smilec/smile/ui/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void loading() {

// Display toast through the handler
Message msg = null;
msg = mHandler.obtainMessage(MSG_OK, getResources().getString(R.string.connection_established));
msg = mHandler.obtainMessage(MSG_OK, getResources().getString(R.string.toast_connection_established));
mHandler.sendMessage(msg);

//Starting SessionValuesActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void loading() {

// Display toast through the handler
Message msg = null;
msg = mHandler.obtainMessage(MSG_OK, getResources().getString(R.string.creating_session));
msg = mHandler.obtainMessage(MSG_OK, getResources().getString(R.string.toast_creating_session));
mHandler.sendMessage(msg);

// Starting ChooseActivityFlowDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void onClick(DialogInterface dialog, int id) {
} else {
new LoadTask(UsePreparedQuestionsActivity.this).execute();
}
ActivityUtil.showLongToast(UsePreparedQuestionsActivity.this, R.string.starting);
ActivityUtil.showLongToast(UsePreparedQuestionsActivity.this, R.string.toast_starting);
}

}
Expand Down Expand Up @@ -209,7 +209,7 @@ private void openGeneralActivity() {
intent.putExtra(GeneralActivity.PARAM_SECONDS, spinnerSeconds.getSelectedItem().toString());
startActivity(intent);

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

this.finish();
}
Expand Down

0 comments on commit 77292df

Please sign in to comment.