Fix for voice message race conditions

Fixes #4625
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-11-20 10:22:36 -08:00
parent 4fe6256967
commit e41f34729e

View File

@ -97,11 +97,11 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
@Override @Override
public void onRecordReleased(float x) { public void onRecordReleased(float x) {
onRecordHideEvent(x); long elapsedTime = onRecordHideEvent(x);
if (listener != null) { if (listener != null) {
Log.w(TAG, "Elapsed time: " + recordTime.getElapsedTimeMillis()); Log.w(TAG, "Elapsed time: " + elapsedTime);
if (recordTime.getElapsedTimeMillis() > 1000) { if (elapsedTime > 1000) {
listener.onRecorderFinished(); listener.onRecorderFinished();
} else { } else {
Toast.makeText(getContext(), R.string.InputPanel_tap_and_hold_to_record_a_voice_note_release_to_send, Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), R.string.InputPanel_tap_and_hold_to_record_a_voice_note_release_to_send, Toast.LENGTH_LONG).show();
@ -129,8 +129,10 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
this.microphoneRecorderView.cancelAction(); this.microphoneRecorderView.cancelAction();
} }
private void onRecordHideEvent(float x) { private long onRecordHideEvent(float x) {
ListenableFuture<Void> future = slideToCancel.hide(x); ListenableFuture<Void> future = slideToCancel.hide(x);
long elapsedTime = recordTime.hide();
future.addListener(new AssertedSuccessListener<Void>() { future.addListener(new AssertedSuccessListener<Void>() {
@Override @Override
public void onSuccess(Void result) { public void onSuccess(Void result) {
@ -139,10 +141,10 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
ViewUtil.fadeIn(quickCameraToggle, FADE_TIME); ViewUtil.fadeIn(quickCameraToggle, FADE_TIME);
ViewUtil.fadeIn(quickAudioToggle, FADE_TIME); ViewUtil.fadeIn(quickAudioToggle, FADE_TIME);
ViewUtil.fadeIn(buttonToggle, FADE_TIME); ViewUtil.fadeIn(buttonToggle, FADE_TIME);
recordTime.hide();
} }
}); });
return elapsedTime;
} }
public interface Listener { public interface Listener {
@ -231,15 +233,13 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
handler.postDelayed(this, TimeUnit.SECONDS.toMillis(1)); handler.postDelayed(this, TimeUnit.SECONDS.toMillis(1));
} }
public void hide() { public long hide() {
long elapsedtime = System.currentTimeMillis() - startTime.get();
this.startTime.set(0); this.startTime.set(0);
ViewUtil.fadeOut(this.recordTimeView, FADE_TIME, View.INVISIBLE); ViewUtil.fadeOut(this.recordTimeView, FADE_TIME, View.INVISIBLE);
return elapsedtime;
} }
public long getElapsedTimeMillis() {
return System.currentTimeMillis() - startTime.get();
}
@Override @Override
public void run() { public void run() {
long localStartTime = startTime.get(); long localStartTime = startTime.get();