From c18186f135a4719f590295a4ee494f938b6b9a92 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Thu, 2 Mar 2017 01:05:02 -0500 Subject: [PATCH] Fixes a bug where if the send or report buttons are mashed they can send several copies of the same thing. --- .../java/com/keylesspalace/tusky/ComposeActivity.java | 9 +++++++++ .../java/com/keylesspalace/tusky/ReportActivity.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 2f61cdb24..c6b76523c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -101,6 +101,7 @@ public class ComposeActivity extends BaseActivity { private boolean statusMarkSensitive; // to the status being composed. private boolean statusHideText; // private View contentWarningBar; + private boolean statusAlreadyInFlight; // to prevent duplicate sends by mashing the send button private static class QueuedMedia { enum Type { @@ -370,12 +371,17 @@ public class ComposeActivity extends BaseActivity { final EditText contentWarningEditor = (EditText) findViewById(R.id.field_content_warning); showContentWarning(false); + statusAlreadyInFlight = false; final Button sendButton = (Button) findViewById(R.id.button_send); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + if (statusAlreadyInFlight) { + return; + } Editable editable = textEditor.getText(); if (editable.length() <= STATUS_CHARACTER_LIMIT) { + statusAlreadyInFlight = true; String spoilerText = ""; if (statusHideText) { spoilerText = contentWarningEditor.getText().toString(); @@ -524,6 +530,7 @@ public class ComposeActivity extends BaseActivity { private void onSendFailure() { textEditor.setError(getString(R.string.error_sending_status)); + statusAlreadyInFlight = false; } private void readyStatus(final String content, final String visibility, final boolean sensitive, @@ -557,6 +564,7 @@ public class ComposeActivity extends BaseActivity { @Override protected void onCancelled() { removeAllMediaFromQueue(); + statusAlreadyInFlight = false; super.onCancelled(); } }; @@ -581,6 +589,7 @@ public class ComposeActivity extends BaseActivity { readyStatus(content, visibility, sensitive, spoilerText); } }); + statusAlreadyInFlight = false; } private void onMediaPick() { diff --git a/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java b/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java index 35c71bf24..fb0a8ccdc 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java @@ -55,6 +55,7 @@ public class ReportActivity extends BaseActivity { private String accessToken; private View anyView; // what Snackbar will use to find the root view private ReportAdapter adapter; + private boolean reportAlreadyInFlight; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -102,11 +103,16 @@ public class ReportActivity extends BaseActivity { final EditText comment = (EditText) findViewById(R.id.report_comment); Button send = (Button) findViewById(R.id.report_send); + reportAlreadyInFlight = false; send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + if (reportAlreadyInFlight) { + return; + } String[] statusIds = adapter.getCheckedStatusIds(); if (statusIds.length > 0) { + reportAlreadyInFlight = true; sendReport(accountId, statusIds, comment.getText().toString()); } else { comment.setError(getString(R.string.error_report_too_few_statuses)); @@ -187,6 +193,7 @@ public class ReportActivity extends BaseActivity { } }) .show(); + reportAlreadyInFlight = false; } private void fetchRecentStatuses(String accountId) {