From d63591e7699126731d17d0a32c0df9a0f4464ecc Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Mon, 16 Dec 2024 14:56:05 +0100 Subject: [PATCH] Make it possible to override drag and drop handler --- .../kotlin/org/wordpress/aztec/AztecText.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index a326e684a..5e7e6e314 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -46,6 +46,7 @@ import android.text.style.SuggestionSpan import android.util.AttributeSet import android.util.DisplayMetrics import android.util.TypedValue +import android.view.DragEvent import android.view.KeyEvent import android.view.LayoutInflater import android.view.MotionEvent @@ -254,6 +255,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown private var onVideoInfoRequestedListener: OnVideoInfoRequestedListener? = null private var onAztecKeyListener: OnAztecKeyListener? = null private var onVisibilityChangeListener: OnVisibilityChangeListener? = null + private var dragEventManager: DragEventManager? = null var externalLogger: AztecLog.ExternalLogger? = null private var isViewInitialized = false @@ -356,6 +358,19 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown fun beforeMediaDeleted(attrs: AztecAttributes) {} } + interface DragEventManager { + fun shouldProcessDragEvent(event: DragEvent?): Boolean + } + + override fun onDragEvent(event: DragEvent?): Boolean { + val shouldProcessDragEvent = dragEventManager?.shouldProcessDragEvent(event) + if (shouldProcessDragEvent == true) { + return super.onDragEvent(event) + } else { + return false + } + } + /** * Listens to keyboard events and calls the `shouldOverrideBackSpace` before each backspace event. */ @@ -1209,6 +1224,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown this.onVisibilityChangeListener = listener } + fun setDragEventManager(listener: DragEventManager) { + this.dragEventManager = listener + } + override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean { if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) { onImeBackListener?.onImeBack()