diff --git a/app/src/main/java/net/iopush/jarvis/MainActivity.java b/app/src/main/java/net/iopush/jarvis/MainActivity.java index 4509d53..9003751 100644 --- a/app/src/main/java/net/iopush/jarvis/MainActivity.java +++ b/app/src/main/java/net/iopush/jarvis/MainActivity.java @@ -210,6 +210,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { new Response.Listener() { @Override public void onResponse(String response) { + String jarvisAnswer = null; + // Parse answer try { JSONArray jObject = new JSONArray(response); @@ -217,25 +219,13 @@ public void onResponse(String response) { for ( int i=0; i= 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(), @@ -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 diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 2591d41..8b9dc54 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -18,4 +18,5 @@ Falta la clave del API de Jarvis Por favor, compruebe la dirección y el puerto de Jarvis. ¿Funciona? No hay conexión de red + Respuesta invalida \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d90c090..6e57929 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -18,4 +18,5 @@ Ne pas répondre dans l\'application Pas de connexion réseau Vérifiez l\'adresse et le numéro de port de Jarvis, est-il démarré ? + Réponse non valide \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 361916e..fc7d646 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,4 +18,5 @@ Missing Jarvis-api key Please check Jarvis address and port. Does it run ? No network connection + Invalid answer