-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement 'Hold to Record' Functionality #16293
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't review the code as it's a draft
2e4924d
to
00f9402
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meant for this to be "request changes"
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
623c20c
to
c29af60
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if tested, LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the PR isn't ready to be reviewed, please mark it as a draft
d38f173
to
4c54277
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface isn't the code which was provided.
The issue with my previously provided code was that the following still existed:
recordButton.setOnClickListener {
Timber.i("primary 'record' button clicked")
controlAudioRecorder()
}
Subject: [PATCH] tests: fix for Kotlin 2.0
The generic needs to apply to both `EmptyApplication` and `AnkiDroidApp`
---
Index: AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt b/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt
--- a/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt (revision 4c54277b27bf1f4045a2f8481708c0856b35a2c3)
+++ b/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt (date 1716476917194)
@@ -188,27 +188,24 @@
setUpMediaPlayer()
audioTimer = AudioTimer(this, this)
- recordButton.setOnClickListener {
- Timber.i("primary 'record' button clicked")
- controlAudioRecorder()
- }
// if the recorder is in the 'cleared' state
// holding the 'record' button should start a recording
// releasing the 'record' button should complete the recording
+ // TODO: remove haptics from the long press - the 'buzz' can be heard on the recording
recordButton.setOnHoldListener(object : OnHoldListener {
- override fun onTouchStart(isLongPress: Boolean): Boolean {
- if (state !in listOf(ImmediatePlayback.CLEARED, AppendToRecording.CLEARED)) return false
- Timber.d("holding 'record' button'")
+ override fun onTouchStart() {
+ Timber.d("pressed 'record' button'")
controlAudioRecorder()
- return true
}
- override fun onHoldEnd(isLongPress: Boolean) {
+ override fun onHoldEnd() {
Timber.d("finished holding 'record' button'")
- if (isLongPress && state is ImmediatePlayback) {
+ if (state is ImmediatePlayback) {
controlAudioRecorder()
} else {
+ // if we're recording audio to add permanently,
+ // releasing the button after a long press should be 'save', not 'pause'
saveButton?.performClick()
}
}
Index: AnkiDroid/src/main/java/com/ichi2/anki/ui/OnHoldListener.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/OnHoldListener.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/OnHoldListener.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/OnHoldListener.kt (revision 4c54277b27bf1f4045a2f8481708c0856b35a2c3)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/OnHoldListener.kt (date 1716476693346)
@@ -18,42 +18,40 @@
import android.view.MotionEvent
import android.view.View
+import timber.log.Timber
interface OnHoldListener {
- fun onTouchStart(isLongPress: Boolean): Boolean
- fun onHoldEnd(isLongPress: Boolean)
+ fun onTouchStart()
+ fun onHoldEnd()
}
fun View.setOnHoldListener(listener: OnHoldListener) {
val listenerWrapper = object : View.OnTouchListener, View.OnLongClickListener {
-
var isHolding = false
- var isLongPress = false
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
when (event?.action) {
MotionEvent.ACTION_DOWN -> {
- isLongPress = false
- if (listener.onTouchStart(isLongPress)) {
- isHolding = true
- }
+ Timber.v("ACTION_DOWN: onTouchStart()")
+ listener.onTouchStart()
}
MotionEvent.ACTION_UP -> {
+ Timber.v("ACTION_UP")
if (isHolding) {
- isHolding = false
- listener.onHoldEnd(isLongPress)
- return true
- }
+ Timber.v("onHoldEnd()")
+ listener.onHoldEnd()
+ }
+ isHolding = false
}
}
return false
}
override fun onLongClick(v: View?): Boolean {
- isLongPress = true
- if (listener.onTouchStart(isLongPress)) {
- isHolding = true
- }
+ Timber.v("onLongClick")
+ // this method is called once the threshold for a long press is reached
+ // not when the long press is released
+ isHolding = true
return true
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last patch + test I feel, you got my patch before I edited it
AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt
Outdated
Show resolved
Hide resolved
c67aea2
to
fb06aa7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of my code, so needs a thorough second review
Cheers!
Purpose / Description
This PR implements the "hold to record" functionality for the Pronunciation Check feature, as proposed in issue #16282.
Fixes
How Has This Been Tested?
On Realme 6 & Emulator
Screen Recording
video_2024-04-29_23-56-53.mp4
Checklist
Please, go through these checks before submitting the PR.