|
|
|
@ -354,12 +354,16 @@ class MainActivity : AppCompatActivity() { |
|
|
|
return when (event.action) { |
|
|
|
MotionEvent.ACTION_DOWN -> { |
|
|
|
if (checkAudioPermission()) { |
|
|
|
// Fast sync: ensure socket is connected immediately |
|
|
|
streamDictationClient?.connectWebSocket() |
|
|
|
|
|
|
|
val selStart = binding.etTranscript.selectionStart |
|
|
|
val selEnd = binding.etTranscript.selectionEnd |
|
|
|
val totalLen = binding.etTranscript.text?.length ?: 0 |
|
|
|
val currentText = binding.etTranscript.text?.toString() ?: "" |
|
|
|
val totalLen = currentText.length |
|
|
|
|
|
|
|
voiceInsertionCursorStart = if (selStart >= 0) selStart else totalLen |
|
|
|
voiceInsertionCursorEnd = if (selEnd >= 0) selEnd else totalLen |
|
|
|
voiceInsertionCursorStart = if (selStart in 0..totalLen) selStart else totalLen |
|
|
|
voiceInsertionCursorEnd = if (selEnd in 0..totalLen) selEnd else totalLen |
|
|
|
|
|
|
|
startRecording() |
|
|
|
} |
|
|
|
@ -367,6 +371,16 @@ class MainActivity : AppCompatActivity() { |
|
|
|
} |
|
|
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { |
|
|
|
if (isCurrentlyRecording) { |
|
|
|
// Update insertion point to where cursor was right before processing |
|
|
|
val selStart = binding.etTranscript.selectionStart |
|
|
|
val selEnd = binding.etTranscript.selectionEnd |
|
|
|
val currentText = binding.etTranscript.text?.toString() ?: "" |
|
|
|
val totalLen = currentText.length |
|
|
|
|
|
|
|
if (selStart in 0..totalLen && selEnd in 0..totalLen) { |
|
|
|
voiceInsertionCursorStart = selStart |
|
|
|
voiceInsertionCursorEnd = selEnd |
|
|
|
} |
|
|
|
stopRecordingAndProcess() |
|
|
|
} |
|
|
|
true |
|
|
|
|