11package com.swmansion.enriched.markdown.utils.text.view
22
3- import android.graphics.drawable.Drawable
43import android.os.Build
54import android.util.Log
65import android.widget.TextView
@@ -9,9 +8,6 @@ import androidx.core.graphics.drawable.DrawableCompat
98
109private const val TAG = " TextSelectionColors"
1110
12- private typealias HandleGetter = (TextView ) -> Drawable ?
13- private typealias HandleSetter = (TextView , Drawable ) -> Unit
14-
1511/* *
1612 * Applies selection highlight and (where supported) handle tinting to a [TextView].
1713 *
@@ -29,22 +25,19 @@ fun TextView.applySelectionColors(
2925private fun TextView.applySelectionHandleTint (
3026 @ColorInt color : Int ,
3127) {
32- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .Q ) {
33- return
34- }
28+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .Q ) return
3529
36- val handles: List < Pair < HandleGetter , HandleSetter >> =
30+ val handles =
3731 listOf (
38- TextView ::getTextSelectHandleLeft to { tv, d -> tv. setTextSelectHandleLeft(d) } ,
39- TextView ::getTextSelectHandle to { tv, d -> tv. setTextSelectHandle(d) } ,
40- TextView ::getTextSelectHandleRight to { tv, d -> tv. setTextSelectHandleRight(d) } ,
32+ TextView ::getTextSelectHandleLeft to TextView :: setTextSelectHandleLeft,
33+ TextView ::getTextSelectHandle to TextView :: setTextSelectHandle,
34+ TextView ::getTextSelectHandleRight to TextView :: setTextSelectHandleRight,
4135 )
4236
4337 handles.forEach { (getter, setter) ->
4438 try {
4539 getter(this )?.mutate()?.also { DrawableCompat .setTint(it, color) }?.let { setter(this , it) }
4640 } catch (e: LinkageError ) {
47- // Defensive: OEM TextView variants may strip individual handle accessors.
4841 Log .w(TAG , " Selection handle tint skipped: ${e.message} " )
4942 }
5043 }
0 commit comments