From 989d790626a5389c70568a6a384687ef652ef667 Mon Sep 17 00:00:00 2001 From: gavine99 Date: Sat, 15 Feb 2025 11:01:47 +1100 Subject: [PATCH] changes to make the speed-to-text button drag-and-dropable --- .../java/com/moez/QKSMS/util/Preferences.kt | 2 + .../QKSMS/feature/compose/ComposeActivity.kt | 59 ++++++++++++++++--- .../feature/settings/SettingsPresenter.kt | 6 +- .../QKSMS/feature/settings/SettingsState.kt | 2 + presentation/src/main/res/values/strings.xml | 4 +- 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt b/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt index eb102d3b..df81490f 100644 --- a/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +++ b/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt @@ -109,6 +109,8 @@ class Preferences @Inject constructor( val autoColor = rxPrefs.getBoolean("autoColor", true) val systemFont = rxPrefs.getBoolean("systemFont", false) val showStt = rxPrefs.getBoolean("showStt", true) + val showSttOffsetX = rxPrefs.getFloat("showSttOffsetX", Float.MIN_VALUE) + val showSttOffsetY = rxPrefs.getFloat("showSttOffsetY", Float.MIN_VALUE) val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL) val blockingManager = rxPrefs.getInteger("blockingManager", BLOCKING_MANAGER_QKSMS) val drop = rxPrefs.getBoolean("drop", false) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt index ba82b7dd..5790e473 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt @@ -32,14 +32,13 @@ import android.provider.MediaStore import android.speech.RecognizerIntent import android.text.format.DateFormat import android.view.ContextMenu -import android.view.GestureDetector -import android.view.GestureDetector.SimpleOnGestureListener +import android.view.DragEvent.ACTION_DRAG_ENDED +import android.view.DragEvent.ACTION_DRAG_EXITED +import android.view.DragEvent.ACTION_DROP import android.view.Menu import android.view.MenuItem -import android.view.MotionEvent import android.view.View -import android.view.View.OnTouchListener -import androidx.activity.result.contract.ActivityResultContracts +import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet @@ -62,6 +61,7 @@ import dev.octoshrimpy.quik.common.base.QkThemedActivity import dev.octoshrimpy.quik.common.util.DateFormatter import dev.octoshrimpy.quik.common.util.extensions.autoScrollToStart import dev.octoshrimpy.quik.common.util.extensions.hideKeyboard +import dev.octoshrimpy.quik.common.util.extensions.makeToast import dev.octoshrimpy.quik.common.util.extensions.scrapViews import dev.octoshrimpy.quik.common.util.extensions.setBackgroundTint import dev.octoshrimpy.quik.common.util.extensions.setTint @@ -163,7 +163,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView { override val backPressedIntent: Subject = PublishSubject.create() override val confirmDeleteIntent: Subject> = PublishSubject.create() override val messageLinkAskIntent: Subject by lazy { messageAdapter.messageLinkClicks } - override val speechRecogniserIntent by lazy { speechToTextIconBorder.clicks() } + override val speechRecogniserIntent by lazy { speechToTextIcon.clicks() } private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] } @@ -212,12 +212,46 @@ class ComposeActivity : QkThemedActivity(), ComposeView { .autoDisposable(scope()) .subscribe { registerForContextMenu(it) } + // drag drop handlers for speech-to-text icon + speechToTextIcon.setOnLongClickListener { + it.startDragAndDrop(null, View.DragShadowBuilder(speechToTextFrame), null, 0) + speechToTextFrame.isVisible = false + + contentView.setOnDragListener { _, event -> + when (event.action) { + ACTION_DROP -> { + speechToTextFrame.x = (event.x - (speechToTextFrame.width / 2)) + speechToTextFrame.y =(event.y - (speechToTextFrame.height / 2)) + + // get offset from root view as a percentage of root view for saving + prefs.showSttOffsetX.set((speechToTextFrame.x - contentView.x) / contentView.width) + prefs.showSttOffsetY.set((speechToTextFrame.y - contentView.y) / contentView.height) + } + ACTION_DRAG_ENDED, ACTION_DRAG_EXITED -> { + speechToTextFrame.isVisible = true + } + } + true + } + true + } + window.callback = ComposeWindowCallback(window.callback, this) } override fun onStart() { super.onStart() activityVisibleIntent.onNext(true) + + // if first time stt icon is shown (since setting reset), pop up an instruction toast + if (prefs.showStt.get() && + (prefs.showSttOffsetX.get() == Float.MIN_VALUE) && + (prefs.showSttOffsetX.get() == Float.MIN_VALUE)) { + makeToast(R.string.compose_toast_drag_stt, Toast.LENGTH_LONG) + // reset to new flag value that indicates 'not first time through, but not customised' + prefs.showSttOffsetX.set(Float.MAX_VALUE) + prefs.showSttOffsetY.set(Float.MAX_VALUE) + } } override fun onPause() { @@ -327,7 +361,18 @@ class ComposeActivity : QkThemedActivity(), ComposeView { if (state.scheduling) scheduleAction.onNext(true) - speechToTextFrame.isVisible = (prefs.showStt.get()) + if (prefs.showStt.get()) { + speechToTextFrame.isVisible = true + + var xPercent = prefs.showSttOffsetX.get() + var yPercent = prefs.showSttOffsetY.get() + + // if the stt icon has a custom position, move it + if ((xPercent != Float.MAX_VALUE) && (yPercent != Float.MAX_VALUE)) { + speechToTextFrame.x = (contentView.x + (xPercent * contentView.width)) + speechToTextFrame.y = (contentView.y + (yPercent * contentView.height)) + } + } } override fun clearSelection() = messageAdapter.clearSelection() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsPresenter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsPresenter.kt index daf8a8b7..15e0f580 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsPresenter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsPresenter.kt @@ -210,7 +210,11 @@ class SettingsPresenter @Inject constructor( R.id.systemFont -> prefs.systemFont.set(!prefs.systemFont.get()) - R.id.showStt -> prefs.showStt.set(!prefs.showStt.get()) + R.id.showStt -> { + prefs.showStt.set(!prefs.showStt.get()) + prefs.showSttOffsetX.set(Float.MIN_VALUE) + prefs.showSttOffsetY.set(Float.MIN_VALUE) + } R.id.unicode -> prefs.unicode.set(!prefs.unicode.get()) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt index 7e766ca0..0b8b270d 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt @@ -40,6 +40,8 @@ data class SettingsState( val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL, val systemFontEnabled: Boolean = false, val showStt: Boolean = true, + val showSttOffsetX: Float = Float.MIN_VALUE, + val showSttOffsetY: Float = Float.MAX_VALUE, val splitSmsEnabled: Boolean = false, val stripUnicodeEnabled: Boolean = false, val mobileOnly: Boolean = false, diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index a482146e..d7371aaa 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -161,6 +161,8 @@ Message item Attachment + Move the speech-to-text button anywhere you like + Sending… Delivered %s Failed to send. Tap to try again @@ -240,7 +242,7 @@ Automatic contact colors Font size Use system font - Show the speech to text button + Show the speech-to-text button Automatic emoji Notifications Tap to customize