diff --git a/adapter/src/main/kotlin/io/goooler/demoapp/adapter/rv/core/BindingAdapters.java b/adapter/src/main/kotlin/io/goooler/demoapp/adapter/rv/core/BindingAdapters.java new file mode 100644 index 000000000..cc0185cac --- /dev/null +++ b/adapter/src/main/kotlin/io/goooler/demoapp/adapter/rv/core/BindingAdapters.java @@ -0,0 +1,40 @@ +package io.goooler.demoapp.adapter.rv.core; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.databinding.BindingAdapter; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.Collections; +import java.util.List; + +public interface BindingAdapters { + + @BindingAdapter("binding_rv_dataList") + static void bindingSetList( + @NonNull RecyclerView recyclerView, + @Nullable List list + ) { + if (recyclerView.getAdapter() instanceof IMutableRvAdapter) { + if (list == null) { + list = Collections.emptyList(); + } + //noinspection unchecked + ((IMutableRvAdapter) recyclerView.getAdapter()).setList(list); + } + } + + @BindingAdapter("binding_rv_refreshItems") + static void bindingRefreshItems( + @NonNull RecyclerView recyclerView, + @Nullable List list + ) { + if (recyclerView.getAdapter() instanceof IMutableRvAdapter) { + if (list == null) { + list = Collections.emptyList(); + } + //noinspection unchecked + ((IMutableRvAdapter) recyclerView.getAdapter()).refreshItems(list); + } + } +} diff --git a/adapter/src/main/kotlin/io/goooler/demoapp/adapter/rv/core/IRvAdapter.kt b/adapter/src/main/kotlin/io/goooler/demoapp/adapter/rv/core/IRvAdapter.kt index e0ce43a8b..2d246553e 100644 --- a/adapter/src/main/kotlin/io/goooler/demoapp/adapter/rv/core/IRvAdapter.kt +++ b/adapter/src/main/kotlin/io/goooler/demoapp/adapter/rv/core/IRvAdapter.kt @@ -4,7 +4,6 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.annotation.IntRange import androidx.annotation.LayoutRes -import androidx.databinding.BindingAdapter import androidx.databinding.DataBindingUtil import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.RecyclerView @@ -67,15 +66,3 @@ internal interface IMutableRvAdapter : IRvAdapter { fun removeItem(item: M) } - -@BindingAdapter(value = ["binding_rv_dataList"], requireAll = true) -fun RecyclerView.setList(list: List?) { - @Suppress("UNCHECKED_CAST") - (adapter as? IMutableRvAdapter)?.list = list.orEmpty() -} - -@BindingAdapter(value = ["binding_rv_refreshItems"], requireAll = true) -fun RecyclerView.refreshItems(items: List?) { - @Suppress("UNCHECKED_CAST") - (adapter as? IMutableRvAdapter)?.refreshItems(items.orEmpty()) -} diff --git a/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseBindingAdapters.java b/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseBindingAdapters.java new file mode 100644 index 000000000..b69c675e2 --- /dev/null +++ b/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseBindingAdapters.java @@ -0,0 +1,337 @@ +package io.goooler.demoapp.base.util; + +import android.graphics.Color; +import android.graphics.Outline; +import android.graphics.Paint; +import android.graphics.Typeface; +import android.graphics.drawable.GradientDrawable; +import android.view.View; +import android.view.ViewOutlineProvider; +import android.widget.TextView; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Px; +import androidx.databinding.BindingAdapter; + +public interface BaseBindingAdapters { + + // ------------------------View --------------------------// + + @BindingAdapter("binding_isGone") + static void bindingIsGone(@NonNull View view, boolean gone) { + view.setVisibility(gone ? View.GONE : View.VISIBLE); + } + + @BindingAdapter("binding_isVisible") + static void bindingIsVisible(@NonNull View view, boolean show) { + view.setVisibility(show ? View.VISIBLE : View.INVISIBLE); + } + + @BindingAdapter("binding_isSelected") + static void bindingIsSelect(@NonNull View view, boolean select) { + view.setSelected(select); + } + + @BindingAdapter("binding_rect_radius") + static void bindingRectCornerRadius(@NonNull View view, @Px float radius) { + view.setOutlineProvider(new ViewOutlineProvider() { + @Override + public void getOutline(@NonNull View view, @NonNull Outline outline) { + outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius); + } + }); + view.setClipToOutline(true); + } + + @BindingAdapter({"binding_width", "binding_height"}) + static void bindingWidthAndHeight(@NonNull View view, @Px float width, @Px float height) { + view.getLayoutParams().width = (int) width; + view.getLayoutParams().height = (int) height; + view.requestLayout(); + } + + @BindingAdapter("binding_width") + static void bindingWidth(@NonNull View view, @Px float width) { + view.getLayoutParams().width = (int) width; + view.requestLayout(); + } + + @BindingAdapter("binding_height") + static void bindingHeight(@NonNull View view, @Px float height) { + view.getLayoutParams().height = (int) height; + view.requestLayout(); + } + + @BindingAdapter("binding_marginTop") + static void bindingMarginTop(@NonNull View view, @Px float margin) { + BaseExtensionUtil.marginDirection(view, 1, margin); + } + + @BindingAdapter("binding_marginBottom") + static void bindingMarginBottom(@NonNull View view, @Px float margin) { + BaseExtensionUtil.marginDirection(view, 3, margin); + } + + @BindingAdapter("binding_marginStart") + static void bindingMarginStart(@NonNull View view, @Px float margin) { + BaseExtensionUtil.marginDirection(view, 0, margin); + } + + @BindingAdapter("binding_marginEnd") + static void bindingMarginEnd(@NonNull View view, @Px float margin) { + BaseExtensionUtil.marginDirection(view, 2, margin); + } + +// ------------------------View Bg Shape---------------------// + + @BindingAdapter({ + "binding_bg_startColor", + "binding_bg_endColor", + "binding_bg_angle", + "binding_bg_radius" + }) + static void bindingBgShapeGradual( + @NonNull View view, + @ColorInt int startColor, + @ColorInt int endColor, + int angle, + @Px float radius + ) { + BaseExtensionUtil.setBgShapeGradual( + view, + GradientDrawable.RECTANGLE, + new int[]{startColor, endColor}, + angle, + null, + Color.TRANSPARENT, + 0f, + radius + ); + } + + @BindingAdapter({ + "binding_bg_startColor", + "binding_bg_endColor", + "binding_bg_angle", + "binding_bg_stroke", + "binding_bg_strokeColor", + "binding_bg_radius" + }) + static void bindingBgShapeGradual( + @NonNull View view, @ColorInt int startColor, + @ColorInt int endColor, + int angle, + @Px float stroke, + @ColorInt int strokeColor, + @Px float radius + ) { + BaseExtensionUtil.setBgShapeGradual( + view, + GradientDrawable.RECTANGLE, + new int[]{startColor, endColor}, + angle, + null, + strokeColor, + stroke, + radius + ); + } + + @BindingAdapter({ + "binding_bg_startColor", + "binding_bg_centerColor", + "binding_bg_endColor", + "binding_bg_angle", + "binding_bg_radius" + }) + static void bindingBgShapeGradual( + @NonNull View view, + @ColorInt int startColor, + @ColorInt int centerColor, + @ColorInt int endColor, + int angle, + @Px float radius + ) { + BaseExtensionUtil.setBgShapeGradual( + view, + GradientDrawable.RECTANGLE, + new int[]{startColor, centerColor, endColor}, + angle, + null, + Color.TRANSPARENT, + 0f, + radius + ); + } + + /** + * 这个比较特殊,requireAll = false + */ + @BindingAdapter( + value = { + "binding_bg_solidColor", + "binding_bg_topLeftRadius", + "binding_bg_topRightRadius", + "binding_bg_bottomLeftRadius", + "binding_bg_bottomRightRadius" + }, + requireAll = false + ) + static void bindingBgShapeCorners( + @NonNull View view, + @ColorInt int solidColor, + @Px float topLeft, + @Px float topRight, + @Px float bottomLeft, + @Px float bottomRight + ) { + BaseExtensionUtil.setBgShapeCorners(view, solidColor, topLeft, topRight, bottomLeft, bottomRight); + } + + @BindingAdapter({ + "binding_bg_startColor", + "binding_bg_endColor", + "binding_bg_angle" + }) + static void bindingBgShapeGradual( + @NonNull View view, + @ColorInt int startColor, + @ColorInt int endColor, + int angle + ) { + BaseExtensionUtil.setBgShapeGradual( + view, + GradientDrawable.RECTANGLE, + new int[]{startColor, endColor}, + angle, + null, + Color.TRANSPARENT, + 0f, + 0f + ); + } + + @BindingAdapter({ + "binding_bg_startColor", + "binding_bg_centerColor", + "binding_bg_endColor", + "binding_bg_angle" + }) + static void bindingBgShapeGradual( + @NonNull View view, + @ColorInt int startColor, + @ColorInt int centerColor, + @ColorInt int endColor, + int angle + ) { + BaseExtensionUtil.setBgShapeGradual( + view, + GradientDrawable.RECTANGLE, + new int[]{startColor, centerColor, endColor}, + angle, + null, + Color.TRANSPARENT, + 0f, + 0f + ); + } + + @BindingAdapter({ + "binding_bg_stroke", + "binding_bg_strokeColor", + "binding_bg_solidColor", + "binding_bg_radius" + }) + static void bindingBgShapeStroke( + @NonNull View view, + @Px float stroke, + @ColorInt int strokeColor, + @ColorInt int solidColor, + @Px float radius + ) { + BaseExtensionUtil.setBgShapeGradual( + view, + GradientDrawable.RECTANGLE, + null, + 0, + solidColor, + strokeColor, + stroke, radius + ); + } + + @BindingAdapter({ + "binding_bg_solidColor", + "binding_bg_radius" + }) + static void bindingBgShape(@NonNull View view, @ColorInt int solidColor, @Px float radius) { + BaseExtensionUtil.setBgShapeGradual( + view, + GradientDrawable.RECTANGLE, + null, + 0, + solidColor, + Color.TRANSPARENT, + 0f, + radius + ); + } + + @BindingAdapter({ + "binding_bg_stroke", + "binding_bg_strokeColor", + "binding_bg_solidOvalColor" + }) + static void bindingBgShapeOvalStroke( + @NonNull View view, + @Px float stroke, + @ColorInt int strokeColor, + @ColorInt int solidOvalColor + ) { + BaseExtensionUtil.setBgShapeGradual( + view, GradientDrawable.OVAL, + null, + 0, + solidOvalColor, + strokeColor, + stroke, + 0f + ); + } + + @BindingAdapter("binding_bg_solidOvalColor") + static void bindingBgShapeOval(@NonNull View view, @ColorInt int solidOvalColor) { + BaseExtensionUtil.setBgShapeGradual( + view, GradientDrawable.OVAL, + null, + 0, + solidOvalColor, + Color.TRANSPARENT, + 0f, + 0f + ); + } + +// ------------------------TextView--------------------------// + + @BindingAdapter("binding_font_type") + static void bindingImpactTypeface(@NonNull TextView textView, String path) { + textView.setTypeface(Typeface.createFromAsset(textView.getContext().getAssets(), path)); + } + + @BindingAdapter("binding_paint_flag") + static void bindingPaintFlag(@NonNull TextView textView, int flag) { + textView.getPaint().setFlags(flag); + textView.getPaint().setAntiAlias(true); + } + + @BindingAdapter("binding_paint_flag_is_thru") + static void bindingPaintFlagThru(@NonNull TextView textView, boolean flag) { + if (flag) { + textView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); + textView.getPaint().setAntiAlias(true); + } else { + textView.getPaint().setFlags(0); + } + } +} diff --git a/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseBindingAdapters.kt b/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseBindingAdapters.kt deleted file mode 100644 index 94d9209d0..000000000 --- a/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseBindingAdapters.kt +++ /dev/null @@ -1,374 +0,0 @@ -@file:Suppress("unused") - -package io.goooler.demoapp.base.util - -import android.graphics.Color -import android.graphics.Outline -import android.graphics.Paint -import android.graphics.Typeface -import android.graphics.drawable.GradientDrawable -import android.view.View -import android.view.ViewGroup -import android.view.ViewOutlineProvider -import android.widget.TextView -import androidx.annotation.ColorInt -import androidx.annotation.Px -import androidx.databinding.BindingAdapter - -// ------------------------View --------------------------// - -@BindingAdapter("binding_isGone") -fun View.bindingIsGone(gone: Boolean) { - visibility = if (gone) View.GONE else View.VISIBLE -} - -@BindingAdapter("binding_isVisible") -fun View.bindingIsVisible(show: Boolean) { - visibility = if (show) View.VISIBLE else View.INVISIBLE -} - -@BindingAdapter("binding_isSelected") -fun View.bindingIsSelect(select: Boolean) { - isSelected = select -} - -@BindingAdapter("binding_rect_radius") -fun View.bindingRectCornerRadius(@Px radius: Float) { - outlineProvider = object : ViewOutlineProvider() { - override fun getOutline(view: View, outline: Outline) { - outline.setRoundRect(0, 0, view.width, view.height, radius) - } - } - clipToOutline = true -} - -@BindingAdapter("binding_width", "binding_height") -fun View.bindingWidthAndHeight(@Px width: Float, @Px height: Float) { - layoutParams.width = width.toInt() - layoutParams.height = height.toInt() - requestLayout() -} - -@BindingAdapter("binding_width") -fun View.bindingWidth(@Px width: Float) { - layoutParams.width = width.toInt() - requestLayout() -} - -@BindingAdapter("binding_height") -fun View.bindingHeight(@Px height: Float) { - layoutParams.height = height.toInt() - requestLayout() -} - -@BindingAdapter("binding_marginTop") -fun View.bindingMarginTop(@Px margin: Float) { - marginDirection(1, margin) -} - -@BindingAdapter("binding_marginBottom") -fun View.bindingMarginBottom(@Px margin: Float) { - marginDirection(3, margin) -} - -@BindingAdapter("binding_marginStart") -fun View.bindingMarginStart(@Px margin: Float) { - marginDirection(0, margin) -} - -@BindingAdapter("binding_marginEnd") -fun View.bindingMarginEnd(@Px margin: Float) { - marginDirection(2, margin) -} - -// ------------------------View Bg Shape---------------------// - -@BindingAdapter( - "binding_bg_startColor", - "binding_bg_endColor", - "binding_bg_angle", - "binding_bg_radius" -) -fun View.bindingBgShapeGradual( - @ColorInt startColor: Int, - @ColorInt endColor: Int, - angle: Int, - @Px radius: Float -) { - setBgShapeGradual( - gradualColors = intArrayOf(startColor, endColor), - angle = angle, - radius = radius - ) -} - -@BindingAdapter( - "binding_bg_startColor", - "binding_bg_endColor", - "binding_bg_angle", - "binding_bg_stroke", - "binding_bg_strokeColor", - "binding_bg_radius" -) -fun View.bindingBgShapeGradual( - @ColorInt startColor: Int, - @ColorInt endColor: Int, - angle: Int, - @Px stroke: Float, - @ColorInt strokeColor: Int, - @Px radius: Float -) { - setBgShapeGradual( - gradualColors = intArrayOf(startColor, endColor), - angle = angle, - radius = radius, - strokeColor = strokeColor, - stroke = stroke - ) -} - -@BindingAdapter( - "binding_bg_startColor", - "binding_bg_centerColor", - "binding_bg_endColor", - "binding_bg_angle", - "binding_bg_radius" -) -fun View.bindingBgShapeGradual( - @ColorInt startColor: Int, - @ColorInt centerColor: Int, - @ColorInt endColor: Int, - angle: Int, - @Px radius: Float -) { - setBgShapeGradual( - gradualColors = intArrayOf(startColor, centerColor, endColor), - angle = angle, - radius = radius - ) -} - -/** - * 这个比较特殊,requireAll = false - */ -@BindingAdapter( - value = [ - "binding_bg_solidColor", - "binding_bg_topLeftRadius", - "binding_bg_topRightRadius", - "binding_bg_bottomLeftRadius", - "binding_bg_bottomRightRadius" - ], - requireAll = false -) -fun View.bindingBgShapeCorners( - @ColorInt solidColor: Int, - @Px topLeft: Float, - @Px topRight: Float, - @Px bottomLeft: Float, - @Px bottomRight: Float -) { - setBgShapeCorners(solidColor, topLeft, topRight, bottomLeft, bottomRight) -} - -@BindingAdapter( - "binding_bg_startColor", - "binding_bg_endColor", - "binding_bg_angle" -) -fun View.bindingBgShapeGradual( - @ColorInt startColor: Int, - @ColorInt endColor: Int, - angle: Int -) { - setBgShapeGradual(gradualColors = intArrayOf(startColor, endColor), angle = angle) -} - -@BindingAdapter( - "binding_bg_startColor", - "binding_bg_centerColor", - "binding_bg_endColor", - "binding_bg_angle" -) -fun View.bindingBgShapeGradual( - @ColorInt startColor: Int, - @ColorInt centerColor: Int, - @ColorInt endColor: Int, - angle: Int -) { - setBgShapeGradual(gradualColors = intArrayOf(startColor, centerColor, endColor), angle = angle) -} - -@BindingAdapter( - "binding_bg_stroke", - "binding_bg_strokeColor", - "binding_bg_solidColor", - "binding_bg_radius" -) -fun View.bindingBgShapeStroke( - @Px stroke: Float, - @ColorInt strokeColor: Int, - @ColorInt solidColor: Int, - @Px radius: Float -) { - setBgShapeGradual( - stroke = stroke, - strokeColor = strokeColor, - solidColor = solidColor, - radius = radius - ) -} - -@BindingAdapter( - "binding_bg_solidColor", - "binding_bg_radius" -) -fun View.bindingBgShape( - @ColorInt solidColor: Int, - @Px radius: Float -) { - setBgShapeGradual(solidColor = solidColor, radius = radius) -} - -@BindingAdapter( - "binding_bg_stroke", - "binding_bg_strokeColor", - "binding_bg_solidOvalColor" -) -fun View.bindingBgShapeOvalStroke( - @Px stroke: Float, - @ColorInt strokeColor: Int, - @ColorInt solidOvalColor: Int -) { - setBgShapeGradual( - shapeType = GradientDrawable.OVAL, - strokeColor = strokeColor, - stroke = stroke, - solidColor = solidOvalColor - ) -} - -@BindingAdapter("binding_bg_solidOvalColor") -fun View.bindingBgShapeOval(@ColorInt solidOvalColor: Int) { - setBgShapeGradual(shapeType = GradientDrawable.OVAL, solidColor = solidOvalColor) -} - -// ------------------------TextView--------------------------// - -@BindingAdapter("binding_font_type") -fun TextView.bindingImpactTypeface(path: String) { - typeface = Typeface.createFromAsset(context.assets, path) -} - -@BindingAdapter("binding_paint_flag") -fun TextView.bindingPaintFlag(flag: Int) { - paint.flags = flag - paint.isAntiAlias = true -} - -@BindingAdapter("binding_paint_flag_is_thru") -fun TextView.bindingPaintFlagThru(flag: Boolean) { - if (flag) { - paint.flags = Paint.STRIKE_THRU_TEXT_FLAG - paint.isAntiAlias = true - } else { - paint.flags = 0 - } -} - -// ---------------------Private-------------------------------// - -/** - * 设置 view 的背景,支持圆形和矩形,渐变色和描边圆角等 - * - * @param shapeType 背景形状,圆、矩形等 - * @param gradualColors 渐变色数组,和填充色互斥 - * @param angle 渐变色角度 - * @param solidColor 填充色,和渐变色数组互斥 - * @param strokeColor 描边色 - * @param stroke 描边粗细 - * @param radius 圆角大小 - */ -private fun View.setBgShapeGradual( - shapeType: Int = GradientDrawable.RECTANGLE, - @ColorInt gradualColors: IntArray? = null, - angle: Int = 0, - @ColorInt solidColor: Int? = null, - @ColorInt strokeColor: Int = Color.TRANSPARENT, - @Px stroke: Float = 0f, - @Px radius: Float = 0f -) { - background = GradientDrawable().apply { - shape = shapeType - useLevel = false - gradientType = GradientDrawable.LINEAR_GRADIENT - val remainder = angle % 45 - val validAngle = if (remainder >= 22.5) { - angle % 360 + 45 - remainder - } else { - angle % 360 - remainder - } - orientation = when (validAngle) { - 45 -> GradientDrawable.Orientation.BL_TR - 90 -> GradientDrawable.Orientation.BOTTOM_TOP - 135 -> GradientDrawable.Orientation.BR_TL - 180 -> GradientDrawable.Orientation.RIGHT_LEFT - 225 -> GradientDrawable.Orientation.TR_BL - 270 -> GradientDrawable.Orientation.TOP_BOTTOM - 315 -> GradientDrawable.Orientation.TL_BR - else -> GradientDrawable.Orientation.LEFT_RIGHT - } - if (gradualColors != null && solidColor == null) { - colors = gradualColors - } else if (gradualColors == null && solidColor != null) { - setColor(solidColor) - } - setStroke(stroke.toInt(), strokeColor) - cornerRadius = radius - } -} - -/** - * 设置 view 在矩形某几个角上需要圆角的背景 - * - * @param solidColor 填充色 - * @param topLeft 左上圆角大小 - * @param topRight 右上圆角大小 - * @param bottomLeft 左下圆角大小 - * @param bottomRight 左下圆角大小 - */ -private fun View.setBgShapeCorners( - @ColorInt solidColor: Int = Color.WHITE, - @Px topLeft: Float = 0f, - @Px topRight: Float = 0f, - @Px bottomLeft: Float = 0f, - @Px bottomRight: Float = 0f -) { - background = GradientDrawable().apply { - shape = GradientDrawable.RECTANGLE - setColor(solidColor) - cornerRadii = floatArrayOf( - topLeft, - topLeft, - topRight, - topRight, - bottomRight, - bottomRight, - bottomLeft, - bottomLeft - ) - } -} - -private fun View.marginDirection(direction: Int, @Px margin: Float) { - if (layoutParams is ViewGroup.MarginLayoutParams) { - val p = layoutParams as ViewGroup.MarginLayoutParams - when (direction) { - 0 -> p.marginStart = margin.toInt() - 1 -> p.topMargin = margin.toInt() - 2 -> p.marginEnd = margin.toInt() - else -> p.bottomMargin = margin.toInt() - } - layoutParams = p - } -} diff --git a/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt b/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt index d0c4b8298..4cf357544 100644 --- a/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt +++ b/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt @@ -9,6 +9,7 @@ import android.content.Context import android.content.ContextWrapper import android.content.Intent import android.graphics.Color +import android.graphics.drawable.GradientDrawable import android.os.Build import android.os.Bundle import android.os.Looper @@ -19,6 +20,7 @@ import android.text.style.ClickableSpan import android.text.style.ForegroundColorSpan import android.view.KeyEvent import android.view.View +import android.view.ViewGroup import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import android.webkit.URLUtil @@ -28,6 +30,7 @@ import androidx.annotation.IdRes import androidx.annotation.IntRange import androidx.annotation.LayoutRes import androidx.annotation.MainThread +import androidx.annotation.Px import androidx.core.content.getSystemService import androidx.core.content.pm.ShortcutInfoCompat import androidx.core.content.pm.ShortcutManagerCompat @@ -490,6 +493,103 @@ fun TextView.setOnEditorConfirmActionListener(listener: (TextView) -> Unit) { } } +/** + * 设置 view 的背景,支持圆形和矩形,渐变色和描边圆角等 + * + * @param shapeType 背景形状,圆、矩形等 + * @param gradualColors 渐变色数组,和填充色互斥 + * @param angle 渐变色角度 + * @param solidColor 填充色,和渐变色数组互斥 + * @param strokeColor 描边色 + * @param stroke 描边粗细 + * @param radius 圆角大小 + */ +@JvmOverloads +fun View.setBgShapeGradual( + shapeType: Int = GradientDrawable.RECTANGLE, + @ColorInt gradualColors: IntArray? = null, + angle: Int = 0, + @ColorInt solidColor: Int? = null, + @ColorInt strokeColor: Int = Color.TRANSPARENT, + @Px stroke: Float = 0f, + @Px radius: Float = 0f +) { + background = GradientDrawable().apply { + shape = shapeType + useLevel = false + gradientType = GradientDrawable.LINEAR_GRADIENT + val remainder = angle % 45 + val validAngle = if (remainder >= 22.5) { + angle % 360 + 45 - remainder + } else { + angle % 360 - remainder + } + orientation = when (validAngle) { + 45 -> GradientDrawable.Orientation.BL_TR + 90 -> GradientDrawable.Orientation.BOTTOM_TOP + 135 -> GradientDrawable.Orientation.BR_TL + 180 -> GradientDrawable.Orientation.RIGHT_LEFT + 225 -> GradientDrawable.Orientation.TR_BL + 270 -> GradientDrawable.Orientation.TOP_BOTTOM + 315 -> GradientDrawable.Orientation.TL_BR + else -> GradientDrawable.Orientation.LEFT_RIGHT + } + if (gradualColors != null && solidColor == null) { + colors = gradualColors + } else if (gradualColors == null && solidColor != null) { + setColor(solidColor) + } + setStroke(stroke.toInt(), strokeColor) + cornerRadius = radius + } +} + +/** + * 设置 view 在矩形某几个角上需要圆角的背景 + * + * @param solidColor 填充色 + * @param topLeft 左上圆角大小 + * @param topRight 右上圆角大小 + * @param bottomLeft 左下圆角大小 + * @param bottomRight 左下圆角大小 + */ +@JvmOverloads +fun View.setBgShapeCorners( + @ColorInt solidColor: Int = Color.WHITE, + @Px topLeft: Float = 0f, + @Px topRight: Float = 0f, + @Px bottomLeft: Float = 0f, + @Px bottomRight: Float = 0f +) { + background = GradientDrawable().apply { + shape = GradientDrawable.RECTANGLE + setColor(solidColor) + cornerRadii = floatArrayOf( + topLeft, + topLeft, + topRight, + topRight, + bottomRight, + bottomRight, + bottomLeft, + bottomLeft + ) + } +} + +fun View.marginDirection(direction: Int, @Px margin: Float) { + if (layoutParams is ViewGroup.MarginLayoutParams) { + val p = layoutParams as ViewGroup.MarginLayoutParams + when (direction) { + 0 -> p.marginStart = margin.toInt() + 1 -> p.topMargin = margin.toInt() + 2 -> p.marginEnd = margin.toInt() + else -> p.bottomMargin = margin.toInt() + } + layoutParams = p + } +} + // ---------------------Context-------------------------------// fun Context.addDynamicShortcutCompat(id: String, shortcut: ShortcutInfoCompat) { diff --git a/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonBindingAdapters.java b/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonBindingAdapters.java new file mode 100644 index 000000000..3af57a81e --- /dev/null +++ b/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonBindingAdapters.java @@ -0,0 +1,107 @@ +package io.goooler.demoapp.common.util; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.databinding.BindingAdapter; +import com.scwang.smart.refresh.classics.ClassicsAbstract; +import com.scwang.smart.refresh.footer.ClassicsFooter; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; +import com.scwang.smart.refresh.layout.api.RefreshFooter; +import com.scwang.smart.refresh.layout.api.RefreshHeader; + +public class CommonBindingAdapters { + + @BindingAdapter("binding_srl_refreshFinish") + public static void bindingFinishRefresh(@NonNull SmartRefreshLayout refreshLayout, boolean isFinish) { + if (isFinish) refreshLayout.finishRefresh(); + } + + @BindingAdapter("binding_srl_loadMoreFinish") + public static void bindingFinishLoadMore(@NonNull SmartRefreshLayout refreshLayout, boolean isFinish) { + if (isFinish) refreshLayout.finishLoadMore(); + } + + @BindingAdapter("binding_srl_enableLoadMore") + public static void bindingEnableLoadMore(@NonNull SmartRefreshLayout refreshLayout, boolean enable) { + refreshLayout.setEnableLoadMore(enable); + } + + @BindingAdapter("binding_srl_enableRefresh") + public static void bindingEnableRefresh(@NonNull SmartRefreshLayout refreshLayout, boolean enable) { + refreshLayout.setEnableRefresh(enable); + } + + @BindingAdapter("binding_srl_noMore") + public static void bindingNoMoreData(@NonNull SmartRefreshLayout refreshLayout, boolean haveNoMore) { + refreshLayout.setNoMoreData(haveNoMore); + } + + @BindingAdapter("binding_srl_headerEmpty") + public static void bindingHeaderEmpty(@NonNull SmartRefreshLayout refreshLayout, boolean isEmpty) { + RefreshHeader refreshHeader = refreshLayout.getRefreshHeader(); + if (refreshHeader instanceof ClassicsAbstract) { + ClassicsAbstract classicsAbstract = (ClassicsAbstract) refreshHeader; + int childCount = classicsAbstract.getChildCount(); + for (int i = 0; i < childCount; i++) { + classicsAbstract.getChildAt(i).setAlpha(isEmpty ? 0f : 1f); + } + } + } + + @BindingAdapter("binding_srl_footerEmpty") + public static void bindingFooterEmpty(@NonNull SmartRefreshLayout refreshLayout, boolean isEmpty) { + RefreshFooter refreshFooter = refreshLayout.getRefreshFooter(); + if (refreshFooter instanceof ClassicsAbstract) { + ClassicsAbstract classicsAbstract = (ClassicsAbstract) refreshFooter; + int childCount = classicsAbstract.getChildCount(); + for (int i = 0; i < childCount; i++) { + classicsAbstract.getChildAt(i).setAlpha(isEmpty ? 0f : 1f); + } + } + } + + @BindingAdapter("binding_srl_headerPrimaryColor") + public static void bindingHeaderPrimaryColor(@NonNull SmartRefreshLayout refreshLayout, @ColorInt int color) { + if (refreshLayout.getRefreshHeader() instanceof ClassicsAbstract) { + ((ClassicsAbstract) refreshLayout.getRefreshHeader()).setPrimaryColor(color); + } else { + ClassicsHeader classicsHeader = new ClassicsHeader(refreshLayout.getContext()); + classicsHeader.setPrimaryColor(color); + refreshLayout.setRefreshHeader(classicsHeader); + } + } + + @BindingAdapter("binding_srl_footerPrimaryColor") + public static void bindingFooterPrimaryColor(@NonNull SmartRefreshLayout refreshLayout, @ColorInt int color) { + if (refreshLayout.getRefreshFooter() instanceof ClassicsAbstract) { + ((ClassicsAbstract) refreshLayout.getRefreshFooter()).setPrimaryColor(color); + } else { + ClassicsFooter classicsHeader = new ClassicsFooter(refreshLayout.getContext()); + classicsHeader.setPrimaryColor(color); + refreshLayout.setRefreshFooter(classicsHeader); + } + } + + @BindingAdapter("binding_srl_headerAccentColor") + public static void bindingHeaderAccentColor(@NonNull SmartRefreshLayout refreshLayout, @ColorInt int color) { + if (refreshLayout.getRefreshHeader() instanceof ClassicsAbstract) { + ((ClassicsAbstract) refreshLayout.getRefreshHeader()).setAccentColor(color); + } else { + ClassicsHeader classicsHeader = new ClassicsHeader(refreshLayout.getContext()); + classicsHeader.setAccentColor(color); + refreshLayout.setRefreshHeader(classicsHeader); + } + } + + @BindingAdapter("binding_srl_footerAccentColor") + public static void bindingFooterAccentColor(@NonNull SmartRefreshLayout refreshLayout, @ColorInt int color) { + if (refreshLayout.getRefreshFooter() instanceof ClassicsAbstract) { + ((ClassicsAbstract) refreshLayout.getRefreshFooter()).setAccentColor(color); + } else { + ClassicsFooter classicsHeader = new ClassicsFooter(refreshLayout.getContext()); + classicsHeader.setAccentColor(color); + refreshLayout.setRefreshFooter(classicsHeader); + } + } +} diff --git a/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonBindingAdapters.kt b/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonBindingAdapters.kt deleted file mode 100644 index 28c200457..000000000 --- a/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonBindingAdapters.kt +++ /dev/null @@ -1,76 +0,0 @@ -@file:Suppress("unused") - -package io.goooler.demoapp.common.util - -import androidx.annotation.ColorInt -import androidx.core.view.forEach -import androidx.databinding.BindingAdapter -import com.scwang.smart.refresh.classics.ClassicsAbstract -import com.scwang.smart.refresh.footer.ClassicsFooter -import com.scwang.smart.refresh.header.ClassicsHeader -import com.scwang.smart.refresh.layout.SmartRefreshLayout - -// ------------------------SmartRefreshLayout--------------------------// - -@BindingAdapter("binding_srl_refreshFinish") -fun SmartRefreshLayout.bindingFinishRefresh(isFinish: Boolean) { - if (isFinish) finishRefresh() -} - -@BindingAdapter("binding_srl_loadMoreFinish") -fun SmartRefreshLayout.bindingFinishLoadMore(isFinish: Boolean) { - if (isFinish) finishLoadMore() -} - -@BindingAdapter("binding_srl_enableLoadMore") -fun SmartRefreshLayout.bindingEnableLoadMore(enable: Boolean) { - setEnableLoadMore(enable) -} - -@BindingAdapter("binding_srl_enableRefresh") -fun SmartRefreshLayout.bindingEnableRefresh(enable: Boolean) { - setEnableRefresh(enable) -} - -@BindingAdapter("binding_srl_noMore") -fun SmartRefreshLayout.bindingNoMoreData(haveNoMore: Boolean) { - setNoMoreData(haveNoMore) -} - -@BindingAdapter("binding_srl_headerEmpty") -fun SmartRefreshLayout.bindingHeaderEmpty(isEmpty: Boolean) { - (refreshHeader as? ClassicsAbstract<*>)?.forEach { - it.alpha = if (isEmpty) 0f else 1f - } -} - -@BindingAdapter("binding_srl_footerEmpty") -fun SmartRefreshLayout.bindingFooterEmpty(isEmpty: Boolean) { - (refreshFooter as? ClassicsAbstract<*>)?.forEach { - it.alpha = if (isEmpty) 0f else 1f - } -} - -@BindingAdapter("binding_srl_headerPrimaryColor") -fun SmartRefreshLayout.bindingHeaderPrimaryColor(@ColorInt color: Int) { - (refreshHeader as? ClassicsAbstract<*>)?.setPrimaryColor(color) - ?: setRefreshHeader(ClassicsHeader(context).apply { setPrimaryColor(color) }) -} - -@BindingAdapter("binding_srl_footerPrimaryColor") -fun SmartRefreshLayout.bindingFooterPrimaryColor(@ColorInt color: Int) { - (refreshFooter as? ClassicsAbstract<*>)?.setPrimaryColor(color) - ?: setRefreshFooter(ClassicsFooter(context).apply { setPrimaryColor(color) }) -} - -@BindingAdapter("binding_srl_headerAccentColor") -fun SmartRefreshLayout.bindingHeaderAccentColor(@ColorInt color: Int) { - (refreshHeader as? ClassicsAbstract<*>)?.setAccentColor(color) - ?: setRefreshHeader(ClassicsHeader(context).apply { setAccentColor(color) }) -} - -@BindingAdapter("binding_srl_footerAccentColor") -fun SmartRefreshLayout.bindingFooterAccentColor(@ColorInt color: Int) { - (refreshFooter as? ClassicsAbstract<*>)?.setAccentColor(color) - ?: setRefreshFooter(ClassicsFooter(context).apply { setAccentColor(color) }) -} diff --git a/common/src/main/kotlin/io/goooler/demoapp/common/util/ImageLoader.kt b/common/src/main/kotlin/io/goooler/demoapp/common/util/ImageLoader.kt index f6dddd688..2274f718c 100644 --- a/common/src/main/kotlin/io/goooler/demoapp/common/util/ImageLoader.kt +++ b/common/src/main/kotlin/io/goooler/demoapp/common/util/ImageLoader.kt @@ -8,7 +8,6 @@ import android.os.Build import android.widget.ImageView import androidx.annotation.FloatRange import androidx.annotation.Px -import androidx.databinding.BindingAdapter import coil.Coil import coil.decode.GifDecoder import coil.decode.ImageDecoderDecoder @@ -38,6 +37,7 @@ object ImageLoader { Coil.setImageLoader(imageLoader) } + @JvmOverloads fun load( imageView: ImageView, data: Any?, @@ -51,6 +51,7 @@ object ImageLoader { } } + @JvmOverloads fun loadCircleCrop( imageView: ImageView, data: Any?, @@ -101,17 +102,12 @@ object ImageLoader { } } -// ------------------------BindingAdapter--------------------------// +// ------------------------Extensions--------------------------// -@BindingAdapter("binding_iv_data") fun ImageView.load(data: Any?) { ImageLoader.load(this, data) } -@BindingAdapter( - "binding_iv_data", - "binding_iv_cornerRadius" -) fun ImageView.load( data: Any?, @Px @FloatRange(from = 0.0) cornerRadius: Float @@ -119,10 +115,6 @@ fun ImageView.load( ImageLoader.load(this, data, cornerRadius = cornerRadius) } -@BindingAdapter( - "binding_iv_data", - "binding_iv_placeholder" -) fun ImageView.load( data: Any?, placeholderDrawable: Drawable? @@ -130,11 +122,6 @@ fun ImageView.load( ImageLoader.load(this, data, placeholderDrawable) } -@BindingAdapter( - "binding_iv_data", - "binding_iv_placeholder", - "binding_iv_error" -) fun ImageView.load( data: Any?, placeholderDrawable: Drawable?, @@ -143,12 +130,6 @@ fun ImageView.load( ImageLoader.load(this, data, placeholderDrawable, errorDrawable) } -@BindingAdapter( - "binding_iv_data", - "binding_iv_placeholder", - "binding_iv_error", - "binding_iv_cornerRadius" -) fun ImageView.load( data: Any?, placeholderDrawable: Drawable?, @@ -158,13 +139,6 @@ fun ImageView.load( ImageLoader.load(this, data, placeholderDrawable, errorDrawable, cornerRadius) } -@BindingAdapter( - "binding_iv_data", - "binding_iv_placeholder", - "binding_iv_error", - "binding_iv_cornerRadius", - "binding_iv_useCache" -) fun ImageView.load( data: Any?, placeholderDrawable: Drawable?, @@ -175,15 +149,10 @@ fun ImageView.load( ImageLoader.load(this, data, placeholderDrawable, errorDrawable, cornerRadius, useCache) } -@BindingAdapter("binding_iv_data_circle") fun ImageView.loadCircleCrop(data: Any?) { ImageLoader.loadCircleCrop(this, data) } -@BindingAdapter( - "binding_iv_data_circle", - "binding_iv_placeholder" -) fun ImageView.loadCircleCrop( data: Any?, placeholderDrawable: Drawable? @@ -191,11 +160,6 @@ fun ImageView.loadCircleCrop( ImageLoader.loadCircleCrop(this, data, placeholderDrawable) } -@BindingAdapter( - "binding_iv_data_circle", - "binding_iv_placeholder", - "binding_iv_error" -) fun ImageView.loadCircleCrop( data: Any?, placeholderDrawable: Drawable?, @@ -204,12 +168,6 @@ fun ImageView.loadCircleCrop( ImageLoader.loadCircleCrop(this, data, placeholderDrawable, errorDrawable) } -@BindingAdapter( - "binding_iv_data_circle", - "binding_iv_placeholder", - "binding_iv_error", - "binding_iv_useCache" -) fun ImageView.loadCircleCrop( data: Any?, placeholderDrawable: Drawable?, diff --git a/common/src/main/kotlin/io/goooler/demoapp/common/util/ImageLoaderBindingAdapters.java b/common/src/main/kotlin/io/goooler/demoapp/common/util/ImageLoaderBindingAdapters.java new file mode 100644 index 000000000..90ab00136 --- /dev/null +++ b/common/src/main/kotlin/io/goooler/demoapp/common/util/ImageLoaderBindingAdapters.java @@ -0,0 +1,109 @@ +package io.goooler.demoapp.common.util; + +import android.graphics.drawable.Drawable; +import android.widget.ImageView; +import androidx.annotation.FloatRange; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.Px; +import androidx.databinding.BindingAdapter; + +public interface ImageLoaderBindingAdapters { + + @BindingAdapter("binding_iv_data") + static void bindingLoad( + @NonNull ImageView imageView, + @Nullable Object object + ) { + ImageLoader.INSTANCE.load(imageView, object); + } + + @BindingAdapter({"binding_iv_data", "binding_iv_cornerRadius"}) + static void bindingLoad( + @NonNull ImageView imageView, + @Nullable Object object, + @Px @FloatRange(from = 0.0) float cornerRadius + ) { + ImageLoader.INSTANCE.load(imageView, object, null, null, cornerRadius); + } + + @BindingAdapter({"binding_iv_data", "binding_iv_placeholder"}) + static void bindingLoad( + @NonNull ImageView imageView, + @Nullable Object object, + @Nullable Drawable placeholderDrawable + ) { + ImageLoader.INSTANCE.load(imageView, object, placeholderDrawable); + } + + @BindingAdapter({"binding_iv_data", "binding_iv_placeholder", "binding_iv_error"}) + static void bindingLoad( + @NonNull ImageView imageView, + @Nullable Object object, + @Nullable Drawable placeholderDrawable, + @Nullable Drawable errorDrawable + ) { + ImageLoader.INSTANCE.load(imageView, object, placeholderDrawable, errorDrawable); + } + + @BindingAdapter({"binding_iv_data", "binding_iv_placeholder", "binding_iv_error", "binding_iv_cornerRadius"}) + static void bindingLoad( + @NonNull ImageView imageView, + @Nullable Object object, + @Nullable Drawable placeholderDrawable, + @Nullable Drawable errorDrawable, + @Px @FloatRange(from = 0.0) float cornerRadius + ) { + ImageLoader.INSTANCE.load(imageView, object, placeholderDrawable, errorDrawable, cornerRadius); + } + + @BindingAdapter({"binding_iv_data", "binding_iv_placeholder", "binding_iv_error", "binding_iv_cornerRadius", "binding_iv_useCache"}) + static void bindingLoad( + @NonNull ImageView imageView, + @Nullable Object object, + @Nullable Drawable placeholderDrawable, + @Nullable Drawable errorDrawable, + @Px @FloatRange(from = 0.0) float cornerRadius, + boolean useCache + ) { + ImageLoader.INSTANCE.load(imageView, object, placeholderDrawable, errorDrawable, cornerRadius, useCache); + } + + @BindingAdapter("binding_iv_data_circle") + static void bindingLoadCircleCrop( + @NonNull ImageView imageView, + @Nullable Object object + ) { + ImageLoader.INSTANCE.loadCircleCrop(imageView, object); + } + + @BindingAdapter({"binding_iv_data_circle", "binding_iv_placeholder"}) + static void bindingLoadCircleCrop( + @NonNull ImageView imageView, + @Nullable Object object, + @Nullable Drawable placeholderDrawable + ) { + ImageLoader.INSTANCE.loadCircleCrop(imageView, object, placeholderDrawable); + } + + @BindingAdapter({"binding_iv_data_circle", "binding_iv_placeholder", "binding_iv_error"}) + static void bindingLoadCircleCrop( + @NonNull ImageView imageView, + @Nullable Object object, + @Nullable Drawable placeholderDrawable, + @Nullable Drawable errorDrawable + ) { + ImageLoader.INSTANCE.loadCircleCrop(imageView, object, placeholderDrawable, errorDrawable); + } + + @BindingAdapter({"binding_iv_data_circle", "binding_iv_placeholder", "binding_iv_error", "binding_iv_useCache"}) + static void bindingLoadCircleCrop( + @NonNull ImageView imageView, + @Nullable Object object, + @Nullable Drawable placeholderDrawable, + @Nullable Drawable errorDrawable, + boolean useCache + ) { + ImageLoader.INSTANCE.loadCircleCrop(imageView, object, placeholderDrawable, errorDrawable, useCache); + } +} diff --git a/obsolete/src/main/kotlin/io/goooler/demoapp/obsolete/util/GlideImageLoader.kt b/obsolete/src/main/kotlin/io/goooler/demoapp/obsolete/util/GlideImageLoader.kt index 87932c5e2..987632e07 100644 --- a/obsolete/src/main/kotlin/io/goooler/demoapp/obsolete/util/GlideImageLoader.kt +++ b/obsolete/src/main/kotlin/io/goooler/demoapp/obsolete/util/GlideImageLoader.kt @@ -5,9 +5,7 @@ package io.goooler.demoapp.obsolete.util import android.content.Context import android.graphics.drawable.Drawable import android.widget.ImageView -import androidx.annotation.FloatRange import androidx.annotation.IntRange -import androidx.databinding.BindingAdapter import com.bumptech.glide.Glide import com.bumptech.glide.RequestBuilder import com.bumptech.glide.load.engine.DiskCacheStrategy @@ -77,221 +75,3 @@ object GlideImageLoader { Glide.get(context).clearMemory() } } - -// ------------------------BindingAdapter--------------------------// - -@BindingAdapter("binding_src_url") -fun ImageView.load(url: String?) { - GlideImageLoader.load(this, url) -} - -@BindingAdapter( - "binding_src_url", - "binding_src_cornerRadius" -) -fun ImageView.load( - url: String?, - @FloatRange(from = 0.0) cornerRadius: Float -) { - GlideImageLoader.load(this, url, cornerRadius = cornerRadius.toInt()) -} - -@BindingAdapter( - "binding_src_url", - "binding_src_placeholder" -) -fun ImageView.load( - url: String?, - placeholderDrawable: Drawable? -) { - GlideImageLoader.load(this, url, placeholderDrawable) -} - -@BindingAdapter( - "binding_src_url", - "binding_src_placeholder", - "binding_src_error" -) -fun ImageView.load( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable? -) { - GlideImageLoader.load(this, url, placeholderDrawable, errorDrawable) -} - -@BindingAdapter( - "binding_src_url", - "binding_src_placeholder", - "binding_src_error", - "binding_src_cornerRadius" -) -fun ImageView.load( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable?, - @FloatRange(from = 0.0) cornerRadius: Float -) { - GlideImageLoader.load(this, url, placeholderDrawable, errorDrawable, cornerRadius.toInt()) -} - -@BindingAdapter( - "binding_src_url", - "binding_src_placeholder", - "binding_src_error", - "binding_src_cornerRadius", - "binding_src_useCache" -) -fun ImageView.load( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable?, - @FloatRange(from = 0.0) cornerRadius: Float, - useCache: Boolean -) { - GlideImageLoader.load( - this, - url, - placeholderDrawable, - errorDrawable, - cornerRadius.toInt(), - useCache - ) -} - -@BindingAdapter("binding_src_url_circle") -fun ImageView.loadCircleCrop(url: String?) { - GlideImageLoader.loadCircleCrop(this, url) -} - -@BindingAdapter( - "binding_src_url_circle", - "binding_src_placeholder" -) -fun ImageView.loadCircleCrop( - url: String?, - placeholderDrawable: Drawable?, -) { - GlideImageLoader.loadCircleCrop(this, url, placeholderDrawable) -} - -@BindingAdapter( - "binding_src_url_circle", - "binding_src_placeholder", - "binding_src_error" -) -fun ImageView.loadCircleCrop( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable? -) { - GlideImageLoader.loadCircleCrop(this, url, placeholderDrawable, errorDrawable) -} - -@BindingAdapter( - "binding_src_url_circle", - "binding_src_placeholder", - "binding_src_error", - "binding_src_useCache" -) -fun ImageView.loadCircleCrop( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable?, - useCache: Boolean -) { - GlideImageLoader.loadCircleCrop(this, url, placeholderDrawable, errorDrawable, useCache) -} - -@BindingAdapter( - "binding_src_url_centerCrop" -) -fun ImageView.loadCenterCrop( - url: String? -) { - GlideImageLoader.loadCenterCrop(this, url) -} - -@BindingAdapter( - "binding_src_url_centerCrop", - "binding_src_cornerRadius" -) -fun ImageView.loadCenterCrop( - url: String?, - @FloatRange(from = 0.0) cornerRadius: Float -) { - GlideImageLoader.loadCenterCrop( - this, - url, - cornerRadius = cornerRadius.toInt() - ) -} - -@BindingAdapter( - "binding_src_url_centerCrop", - "binding_src_placeholder" -) -fun ImageView.loadCenterCrop( - url: String?, - placeholderDrawable: Drawable? -) { - GlideImageLoader.loadCenterCrop(this, url, placeholderDrawable) -} - -@BindingAdapter( - "binding_src_url_centerCrop", - "binding_src_placeholder", - "binding_src_error" -) -fun ImageView.loadCenterCrop( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable? -) { - GlideImageLoader.loadCenterCrop(this, url, placeholderDrawable, errorDrawable) -} - -@BindingAdapter( - "binding_src_url_centerCrop", - "binding_src_placeholder", - "binding_src_error", - "binding_src_cornerRadius" -) -fun ImageView.loadCenterCrop( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable?, - @FloatRange(from = 0.0) cornerRadius: Float -) { - GlideImageLoader.loadCenterCrop( - this, - url, - placeholderDrawable, - errorDrawable, - cornerRadius.toInt() - ) -} - -@BindingAdapter( - "binding_src_url_centerCrop", - "binding_src_placeholder", - "binding_src_error", - "binding_src_cornerRadius", - "binding_src_useCache" -) -fun ImageView.loadCenterCrop( - url: String?, - placeholderDrawable: Drawable?, - errorDrawable: Drawable?, - @FloatRange(from = 0.0) cornerRadius: Float, - useCache: Boolean -) { - GlideImageLoader.loadCenterCrop( - this, - url, - placeholderDrawable, - errorDrawable, - cornerRadius.toInt(), - useCache - ) -}