diff --git a/app/src/main/java/es/eoinrul/ecwt/SounderActivity.kt b/app/src/main/java/es/eoinrul/ecwt/SounderActivity.kt index 8888592..0fe3e37 100644 --- a/app/src/main/java/es/eoinrul/ecwt/SounderActivity.kt +++ b/app/src/main/java/es/eoinrul/ecwt/SounderActivity.kt @@ -3,6 +3,11 @@ package es.eoinrul.ecwt import android.os.Bundle import android.text.Editable import android.text.TextWatcher +import android.view.KeyEvent +import android.view.View +import android.view.inputmethod.EditorInfo +import android.widget.Button +import android.widget.CheckBox import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity @@ -24,6 +29,21 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio mKeyboardInput = findViewById(R.id.sounderInput) mKeyboardInput?.addTextChangedListener(mInputHandler) mKeyboardInput?.requestFocus() + mKeyboardInput?.setOnEditorActionListener { textView, actionId, keyEvent -> + if(!mAutoSend && (actionId == EditorInfo.IME_ACTION_SEND || + (actionId == EditorInfo.IME_NULL && keyEvent.keyCode == KeyEvent.KEYCODE_ENTER) ) ) { + mUserTriggeredSend = true + mKeyboardInput!!.isEnabled = false + ensurePlaying() + } + mAutoSend + } + + var autoSendCheck = findViewById(R.id.autoSendCheck); + autoSendCheck.setOnCheckedChangeListener { compoundButton, _ -> + mAutoSend = compoundButton.isChecked + } + autoSendCheck.isChecked = mAutoSend initSoundPlayer() } @@ -47,6 +67,8 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio mSpaceDurationMs = (mSoundPlayer!!.durationOf(listOf(SoundTypes.LETTER_SPACE)) * 1000).toLong() } + private var mAutoSend : Boolean = true + private var mUserTriggeredSend : Boolean = false private var mPreviouslySentText : TextView? = null private var mCurrentlySendingText : TextView? = null private var mKeyboardInput : EditText? = null @@ -87,7 +109,8 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio mSoundAwaitingText = true runOnUiThread { - if( mKeyboardInput?.text!!.isNotEmpty() && mSoundAwaitingText ) { + if( (mAutoSend || mUserTriggeredSend) && + mKeyboardInput?.text!!.isNotEmpty() && mSoundAwaitingText ) { mSoundAwaitingText = false // Extract and remove the first character val firstInput = mKeyboardInput!!.text!!.subSequence(0, 1).toString() @@ -112,6 +135,13 @@ class SounderActivity : AppCompatActivity(), DitDahSoundStream.StreamNotificatio mPreviouslySentText?.text = mPreviouslySentText?.text!!.substring(trimFrom, mPreviouslySentText?.text!!.length) + extraSpace + firstInput + // Re-enable the send button if this was the last character to go + if (mUserTriggeredSend && mKeyboardInput!!.text.isEmpty()) { + mKeyboardInput!!.isEnabled = true + mKeyboardInput!!.requestFocus() + mUserTriggeredSend = false + } + // Then play the sound: mSoundPlayer?.enqueue(sequence) } diff --git a/app/src/main/res/layout/activity_sounder.xml b/app/src/main/res/layout/activity_sounder.xml index b926221..a23509b 100644 --- a/app/src/main/res/layout/activity_sounder.xml +++ b/app/src/main/res/layout/activity_sounder.xml @@ -32,18 +32,34 @@ app:layout_constraintTop_toBottomOf="@+id/sentText" /> + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b72cbb..30310dd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,6 +55,7 @@ to move on to the next character. Be sure to add spaces between the words! + Auto send 400Hz diff --git a/fastlane/metadata/android/en-US/changelogs/44.txt b/fastlane/metadata/android/en-US/changelogs/44.txt index ed0417f..a22668c 100644 --- a/fastlane/metadata/android/en-US/changelogs/44.txt +++ b/fastlane/metadata/android/en-US/changelogs/44.txt @@ -1,3 +1,6 @@ Fixed bug where duration of lessons was too long Added tip if users didn't add spaces to lesson input -Improved "Sounder" UI. Now shows some history and upcoming text. +Improved "Sounder" UI. + Shows user the progress and upcoming text. + Add an "auto-send" checkbox, allowing writing a message + and sending all in one go.