Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Giyutomioka-SS
Copy link
Contributor

@Giyutomioka-SS Giyutomioka-SS commented Apr 29, 2024

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.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@Giyutomioka-SS Giyutomioka-SS marked this pull request as draft April 29, 2024 04:39
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Apr 29, 2024
Copy link
Member

@david-allison david-allison left a 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

@Giyutomioka-SS Giyutomioka-SS marked this pull request as ready for review April 29, 2024 18:22
Copy link
Member

@david-allison david-allison left a 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"

Copy link
Contributor

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

@david-allison david-allison added Needs Review squash-merge The pull request currently requires maintainers to "Squash Merge" and removed Needs Author Reply Waiting for a reply from the original author labels May 19, 2024
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if tested, LGTM

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge Needs Review and removed Needs Review Needs Second Approval Has one approval, one more approval to merge labels May 19, 2024
Copy link
Member

@david-allison david-allison left a 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

@Giyutomioka-SS Giyutomioka-SS marked this pull request as draft May 19, 2024 16:43
@Giyutomioka-SS Giyutomioka-SS marked this pull request as ready for review May 23, 2024 07:57
Copy link
Member

@david-allison david-allison left a 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
         }
     }

@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels May 23, 2024
Copy link
Member

@david-allison david-allison left a 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

Copy link
Member

@david-allison david-allison left a 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!

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Author Reply Waiting for a reply from the original author labels May 23, 2024
@criticalAY criticalAY removed the squash-merge The pull request currently requires maintainers to "Squash Merge" label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Second Approval Has one approval, one more approval to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check Pronunciation: "Hold to record"
3 participants