From 4b979c9e28ac1c3568b082a3a301cdd32cfb7afe Mon Sep 17 00:00:00 2001 From: Sam Steele Date: Wed, 11 Dec 2013 08:09:50 -0800 Subject: [PATCH] Prevent multiple enter or send keypresses from sending duplicate messages --- src/com/irccloud/android/activity/MessageActivity.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/com/irccloud/android/activity/MessageActivity.java b/src/com/irccloud/android/activity/MessageActivity.java index 172596d63..e8049c54e 100644 --- a/src/com/irccloud/android/activity/MessageActivity.java +++ b/src/com/irccloud/android/activity/MessageActivity.java @@ -149,8 +149,9 @@ public void onCreate(Bundle savedInstanceState) { messageTxt.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { - if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER && messageTxt.getText() != null && messageTxt.getText().length() > 0) { - new SendTask().execute((Void)null); + if(sendBtn.isEnabled() && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER && messageTxt.getText() != null && messageTxt.getText().length() > 0) { + sendBtn.setEnabled(false); + new SendTask().execute((Void)null); } return false; } @@ -175,7 +176,8 @@ public void onClick(View v) { }); messageTxt.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { - if(NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED && actionId == EditorInfo.IME_ACTION_SEND && messageTxt.getText() != null && messageTxt.getText().length() > 0) { + if(sendBtn.isEnabled() && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED && actionId == EditorInfo.IME_ACTION_SEND && messageTxt.getText() != null && messageTxt.getText().length() > 0) { + sendBtn.setEnabled(false); new SendTask().execute((Void)null); } return true;