Skip to content

Commit

Permalink
Make it possible to override drag and drop handler
Browse files Browse the repository at this point in the history
  • Loading branch information
planarvoid committed Dec 16, 2024
1 parent 71f2112 commit d63591e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d63591e

Please sign in to comment.