Commit 19d3ced5 by Kunj Gupta

Added conversation flag in chatscreen.

parent 0d0aeea9
...@@ -60,6 +60,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -60,6 +60,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
private static String NEW_MESSAGE_USER_NAME = "username"; private static String NEW_MESSAGE_USER_NAME = "username";
private static String NEW_MESSAGE_MESSAGE = "message"; private static String NEW_MESSAGE_MESSAGE = "message";
private static String IS_END_OF_INTENT = "is_end_of_intent";
private static final int CHECK_CODE = 102; private static final int CHECK_CODE = 102;
...@@ -82,6 +83,9 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -82,6 +83,9 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
private ImageButton mVoiceButton; private ImageButton mVoiceButton;
private DroidSpeech droidSpeech; private DroidSpeech droidSpeech;
/*According to this flag we'll close the conversation from mobile side. We'll get this flag in chat response*/
private boolean mIsConversationEnd;
@Override @Override
public boolean onOptionsItemSelected(MenuItem menuItem) { public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) { if (menuItem.getItemId() == android.R.id.home) {
...@@ -213,7 +217,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -213,7 +217,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
if(CURRENT_STATE == VOICE_STATE && !username.equals(mLoggedInUsername)) { if(CURRENT_STATE == VOICE_STATE && !username.equals(mLoggedInUsername)) {
if(droidSpeech != null) { if(droidSpeech != null) {
CatalogueLog.i("addMessage: close droid speech");
droidSpeech.closeDroidSpeechOperations(); droidSpeech.closeDroidSpeechOperations();
} }
speaker.allow(true); speaker.allow(true);
...@@ -278,7 +281,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -278,7 +281,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
CatalogueLog.e("diconnected");
isConnected = false; isConnected = false;
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
R.string.disconnect, Toast.LENGTH_LONG).show(); R.string.disconnect, Toast.LENGTH_LONG).show();
...@@ -296,7 +298,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -296,7 +298,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
CatalogueLog.e("Error connecting");
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
R.string.error_connect, Toast.LENGTH_LONG).show(); R.string.error_connect, Toast.LENGTH_LONG).show();
} }
...@@ -310,6 +311,8 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -310,6 +311,8 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
private Emitter.Listener onNewMessage = new Emitter.Listener() { private Emitter.Listener onNewMessage = new Emitter.Listener() {
@Override @Override
public void call(final Object... args) { public void call(final Object... args) {
/*Reset this flag every time*/
mIsConversationEnd = false;
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -319,6 +322,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -319,6 +322,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
try { try {
username = data.getString(NEW_MESSAGE_USER_NAME); username = data.getString(NEW_MESSAGE_USER_NAME);
message = data.getString(NEW_MESSAGE_MESSAGE); message = data.getString(NEW_MESSAGE_MESSAGE);
mIsConversationEnd = data.getBoolean(IS_END_OF_INTENT);
} catch (JSONException e) { } catch (JSONException e) {
CatalogueLog.e(e.getMessage()); CatalogueLog.e(e.getMessage());
return; return;
...@@ -345,7 +349,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -345,7 +349,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
private Emitter.Listener authenticated = new Emitter.Listener() { private Emitter.Listener authenticated = new Emitter.Listener() {
@Override @Override
public void call(final Object... args) { public void call(final Object... args) {
CatalogueLog.e("authorized user: "+args[0]);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -371,7 +374,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -371,7 +374,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
@Override @Override
public void run() { public void run() {
//TODO : need to check if access token is valid or not. //TODO : need to check if access token is valid or not.
CatalogueLog.e("unauthorized user: "+args[0]);
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
R.string.unauthorized_user, Toast.LENGTH_LONG).show(); R.string.unauthorized_user, Toast.LENGTH_LONG).show();
} }
...@@ -437,8 +439,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -437,8 +439,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() { speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override @Override
public void onDone(String utteranceId) { public void onDone(String utteranceId) {
CatalogueLog.i("onActivityResult: Speaking done: isSpeaking: "+speaker.isSpeaking()+", droidSpeech: "+droidSpeech); if (!mIsConversationEnd && (!speaker.isSpeaking() && droidSpeech != null)) {
if (!speaker.isSpeaking() && droidSpeech != null) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -456,7 +457,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -456,7 +457,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
@Override @Override
public void onStart(String utteranceId) { public void onStart(String utteranceId) {
if (droidSpeech != null) { if (droidSpeech != null) {
CatalogueLog.i("onActivityResult: close droid speech");
droidSpeech.closeDroidSpeechOperations(); droidSpeech.closeDroidSpeechOperations();
} }
} }
...@@ -503,7 +503,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList ...@@ -503,7 +503,6 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
speaker.stop(); speaker.stop();
} }
if(droidSpeech != null) { if(droidSpeech != null) {
CatalogueLog.i("onPause: close droid speech");
droidSpeech.closeDroidSpeechOperations(); droidSpeech.closeDroidSpeechOperations();
} }
CURRENT_STATE = NONE; CURRENT_STATE = NONE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment