Skip to content

Commit d3ca615

Browse files
committed
disable send button until retrieved success of failure from API
1 parent 2473c56 commit d3ca615

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/src/main/java/io/github/veeshostak/aichat/activities/ChatListActivity.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ public void onClick(View v) {
572572
mMessageAdapter.add(chatMessage); // display in RecyclerView while waiting for response
573573
// END: quickly display userQuery in RecyclerView
574574

575+
576+
// disable send button until retrieve success of failure from API
577+
sendBtn.setClickable(false);
578+
575579
// START: send userQuery to dialogFlow API, once obtain response: add to RecyclerView, add chatPost to local Room db
576580
// pass params
577581
final String eventString = null;
@@ -673,6 +677,8 @@ private void onResult(final AIResponse response) {
673677
//resultTextView.setText(gson.toJson(response));
674678
Log.i(TAG, "Received success response");
675679

680+
activityReference.get().sendBtn.setClickable(true); // enable button
681+
676682
// get speech from the result object
677683
final Result result = response.getResult();
678684
final String speech = result.getFulfillment().getSpeech();
@@ -688,12 +694,12 @@ private void onResult(final AIResponse response) {
688694
mChatPost.setCreatedAt(DateFormat.getDateTimeInstance().format(new Date()));
689695
activityReference.get().addChatPostsViewModel.addChatPosts(mChatPost);
690696

691-
692-
693697
}
694698

695699
private void onError(final AIError error) {
696700
Log.d(TAG, error.toString());
701+
activityReference.get().sendBtn.setClickable(true); // enable button
702+
697703
Toast.makeText(activityReference.get().getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();
698704
//resultTextView.setText(error.toString());
699705
}

0 commit comments

Comments
 (0)