Fixes a bug where if the send or report buttons are mashed they can send several copies of the same thing.

This commit is contained in:
Vavassor 2017-03-02 01:05:02 -05:00
parent 4fdeba248a
commit c18186f135
2 changed files with 16 additions and 0 deletions

View File

@ -101,6 +101,7 @@ public class ComposeActivity extends BaseActivity {
private boolean statusMarkSensitive; // to the status being composed. private boolean statusMarkSensitive; // to the status being composed.
private boolean statusHideText; // private boolean statusHideText; //
private View contentWarningBar; private View contentWarningBar;
private boolean statusAlreadyInFlight; // to prevent duplicate sends by mashing the send button
private static class QueuedMedia { private static class QueuedMedia {
enum Type { enum Type {
@ -370,12 +371,17 @@ public class ComposeActivity extends BaseActivity {
final EditText contentWarningEditor = (EditText) findViewById(R.id.field_content_warning); final EditText contentWarningEditor = (EditText) findViewById(R.id.field_content_warning);
showContentWarning(false); showContentWarning(false);
statusAlreadyInFlight = false;
final Button sendButton = (Button) findViewById(R.id.button_send); final Button sendButton = (Button) findViewById(R.id.button_send);
sendButton.setOnClickListener(new View.OnClickListener() { sendButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (statusAlreadyInFlight) {
return;
}
Editable editable = textEditor.getText(); Editable editable = textEditor.getText();
if (editable.length() <= STATUS_CHARACTER_LIMIT) { if (editable.length() <= STATUS_CHARACTER_LIMIT) {
statusAlreadyInFlight = true;
String spoilerText = ""; String spoilerText = "";
if (statusHideText) { if (statusHideText) {
spoilerText = contentWarningEditor.getText().toString(); spoilerText = contentWarningEditor.getText().toString();
@ -524,6 +530,7 @@ public class ComposeActivity extends BaseActivity {
private void onSendFailure() { private void onSendFailure() {
textEditor.setError(getString(R.string.error_sending_status)); textEditor.setError(getString(R.string.error_sending_status));
statusAlreadyInFlight = false;
} }
private void readyStatus(final String content, final String visibility, final boolean sensitive, private void readyStatus(final String content, final String visibility, final boolean sensitive,
@ -557,6 +564,7 @@ public class ComposeActivity extends BaseActivity {
@Override @Override
protected void onCancelled() { protected void onCancelled() {
removeAllMediaFromQueue(); removeAllMediaFromQueue();
statusAlreadyInFlight = false;
super.onCancelled(); super.onCancelled();
} }
}; };
@ -581,6 +589,7 @@ public class ComposeActivity extends BaseActivity {
readyStatus(content, visibility, sensitive, spoilerText); readyStatus(content, visibility, sensitive, spoilerText);
} }
}); });
statusAlreadyInFlight = false;
} }
private void onMediaPick() { private void onMediaPick() {

View File

@ -55,6 +55,7 @@ public class ReportActivity extends BaseActivity {
private String accessToken; private String accessToken;
private View anyView; // what Snackbar will use to find the root view private View anyView; // what Snackbar will use to find the root view
private ReportAdapter adapter; private ReportAdapter adapter;
private boolean reportAlreadyInFlight;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -102,11 +103,16 @@ public class ReportActivity extends BaseActivity {
final EditText comment = (EditText) findViewById(R.id.report_comment); final EditText comment = (EditText) findViewById(R.id.report_comment);
Button send = (Button) findViewById(R.id.report_send); Button send = (Button) findViewById(R.id.report_send);
reportAlreadyInFlight = false;
send.setOnClickListener(new View.OnClickListener() { send.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (reportAlreadyInFlight) {
return;
}
String[] statusIds = adapter.getCheckedStatusIds(); String[] statusIds = adapter.getCheckedStatusIds();
if (statusIds.length > 0) { if (statusIds.length > 0) {
reportAlreadyInFlight = true;
sendReport(accountId, statusIds, comment.getText().toString()); sendReport(accountId, statusIds, comment.getText().toString());
} else { } else {
comment.setError(getString(R.string.error_report_too_few_statuses)); comment.setError(getString(R.string.error_report_too_few_statuses));
@ -187,6 +193,7 @@ public class ReportActivity extends BaseActivity {
} }
}) })
.show(); .show();
reportAlreadyInFlight = false;
} }
private void fetchRecentStatuses(String accountId) { private void fetchRecentStatuses(String accountId) {