From 970448d43d02b7fa947e3aaa7c17140de60eb25f Mon Sep 17 00:00:00 2001 From: Piotr Prucia Date: Fri, 13 Jan 2017 03:13:28 +0100 Subject: [PATCH] Disable AudioView controls clicks when message is selected Fixes: #5898 Closes #6054 --- .../securesms/ConversationItem.java | 6 +++ .../securesms/components/AudioView.java | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java index e7486c27e6..0429e540bb 100644 --- a/src/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/ConversationItem.java @@ -252,6 +252,12 @@ public class ConversationItem extends LinearLayout mediaThumbnailStub.get().setClickable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty()); mediaThumbnailStub.get().setLongClickable(batchSelected.isEmpty()); } + + if (audioViewStub.resolved()) { + audioViewStub.get().setFocusable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty()); + audioViewStub.get().setClickable(batchSelected.isEmpty()); + audioViewStub.get().setEnabled(batchSelected.isEmpty()); + } } private boolean isCaptionlessMms(MessageRecord messageRecord) { diff --git a/src/org/thoughtcrime/securesms/components/AudioView.java b/src/org/thoughtcrime/securesms/components/AudioView.java index 9616f045f1..40af6de189 100644 --- a/src/org/thoughtcrime/securesms/components/AudioView.java +++ b/src/org/thoughtcrime/securesms/components/AudioView.java @@ -12,6 +12,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.Log; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -157,6 +158,35 @@ public class AudioView extends FrameLayout implements AudioSlidePlayer.Listener } } + @Override + public void setFocusable(boolean focusable) { + super.setFocusable(focusable); + this.playButton.setFocusable(focusable); + this.pauseButton.setFocusable(focusable); + this.seekBar.setFocusable(focusable); + this.seekBar.setFocusableInTouchMode(focusable); + this.downloadButton.setFocusable(focusable); + } + + @Override + public void setClickable(boolean clickable) { + super.setClickable(clickable); + this.playButton.setClickable(clickable); + this.pauseButton.setClickable(clickable); + this.seekBar.setClickable(clickable); + this.seekBar.setOnTouchListener(clickable ? null : new TouchIgnoringListener()); + this.downloadButton.setClickable(clickable); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + this.playButton.setEnabled(enabled); + this.pauseButton.setEnabled(enabled); + this.seekBar.setEnabled(enabled); + this.downloadButton.setEnabled(enabled); + } + @Override public void onProgress(double progress, long millis) { int seekProgress = (int)Math.floor(progress * this.seekBar.getMax()); @@ -286,6 +316,13 @@ public class AudioView extends FrameLayout implements AudioSlidePlayer.Listener } } + private class TouchIgnoringListener implements OnTouchListener { + @Override + public boolean onTouch(View v, MotionEvent event) { + return true; + } + } + @SuppressWarnings("unused") public void onEventAsync(final PartProgressEvent event) { if (audioSlidePlayer != null && event.attachment.equals(this.audioSlidePlayer.getAudioSlide().asAttachment())) {