Skip to content

Commit

Permalink
Bug correction when warning are included JSON
Browse files Browse the repository at this point in the history
See [this issue](alexylem/jarvis#774)
  • Loading branch information
Oliv4945 committed Jan 2, 2018
1 parent 9b71758 commit 729b170
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
34 changes: 21 additions & 13 deletions app/src/main/java/net/iopush/jarvis/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,22 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String jarvisAnswer = null;

// Parse answer
try {
JSONArray jObject = new JSONArray(response);
Log.i("Jarvis", "jObject" + jObject.toString());
for ( int i=0; i<jObject.length(); i++ ) {
JSONObject c = jObject.getJSONObject(i);
Log.i("Jarvis", "Answer: " + c.toString());
String jarvisAnswer;
// Conditional JSON key, wait for jarvis-core issue #564 to be closed
if (c.has(jarvisTrigger)) {
jarvisAnswer = c.getString(jarvisTrigger);
} else {
} else if (c.has("answer")) {
jarvisAnswer = c.getString("answer");
}
jarvisConversationList.add(0, new ConversationObject(jarvisTrigger, jarvisAnswer));
recyclerViewConversation.getAdapter().notifyItemInserted(0);
recyclerViewConversation.smoothScrollToPosition(0);
if (!muteLocalJarvis) {
if (android.os.Build.VERSION.SDK_INT >= 21) {
ttsEngine.speak(jarvisAnswer, TextToSpeech.QUEUE_ADD, null, jarvisAnswer);
} else {
ttsEngine.speak(jarvisAnswer, TextToSpeech.QUEUE_ADD, null);
}
}
}

} catch (final JSONException e) {
Log.e("Jarvis", "Json parsing error: " + e.getMessage());
Toast.makeText(getApplicationContext(),
Expand All @@ -244,6 +234,24 @@ public void onResponse(String response) {
.show();

}
if (jarvisAnswer != null) {
jarvisConversationList.add(0, new ConversationObject(jarvisTrigger, jarvisAnswer));
recyclerViewConversation.getAdapter().notifyItemInserted(0);
recyclerViewConversation.smoothScrollToPosition(0);
if (!muteLocalJarvis) {
if (android.os.Build.VERSION.SDK_INT >= 21) {
ttsEngine.speak(jarvisAnswer, TextToSpeech.QUEUE_ADD, null, jarvisAnswer);
} else {
ttsEngine.speak(jarvisAnswer, TextToSpeech.QUEUE_ADD, null);
}
}
} else {
// TODO - Snackbar action button or add message to conversation list
Snackbar snackbarVolleyError = Snackbar
.make(findViewById(R.id.mainActivity), getString(R.string.invalidAnswer), Snackbar.LENGTH_LONG);

snackbarVolleyError.show();
}
}
}, new Response.ErrorListener() {
@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<string name="missingAPIKey">Falta la clave del API de Jarvis</string>
<string name="timeoutServerNetworkError">Por favor, compruebe la dirección y el puerto de Jarvis. ¿Funciona?</string>
<string name="noConnectionError">No hay conexión de red</string>
<string name="invalidAnswer">Respuesta invalida</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<string name="pref_muteLocalJarvis">Ne pas répondre dans l\'application</string>
<string name="noConnectionError">Pas de connexion réseau</string>
<string name="timeoutServerNetworkError">Vérifiez l\'adresse et le numéro de port de Jarvis, est-il démarré ?</string>
<string name="invalidAnswer">Réponse non valide</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<string name="missingAPIKey">Missing Jarvis-api key</string>
<string name="timeoutServerNetworkError">Please check Jarvis address and port. Does it run ?</string>
<string name="noConnectionError">No network connection</string>
<string name="invalidAnswer">Invalid answer</string>
</resources>

0 comments on commit 729b170

Please sign in to comment.