Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Optimize bindingAdapter functions for invocation of bindings #114

Merged
merged 2 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ internal interface IMutableRvAdapter<M : IVhModelType> : IRvAdapter<M> {
}

@BindingAdapter(value = ["binding_rv_dataList"], requireAll = true)
fun <M : IVhModelType> RecyclerView.setList(list: List<M>?) {
internal fun <M : IVhModelType> RecyclerView.bindingSetList(list: List<M>?) {
@Suppress("UNCHECKED_CAST")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only can be invocated by bindings, you can use it in other Kotlin functions.

(adapter as? IMutableRvAdapter<M>)?.list = list.orEmpty()
}

@BindingAdapter(value = ["binding_rv_refreshItems"], requireAll = true)
fun <M : IVhModelType> RecyclerView.refreshItems(items: List<M>?) {
internal fun <M : IVhModelType> RecyclerView.bindingRefreshItems(items: List<M>?) {
@Suppress("UNCHECKED_CAST")
(adapter as? IMutableRvAdapter<M>)?.refreshItems(items.orEmpty())
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ import androidx.databinding.BindingAdapter
// ------------------------View --------------------------//

@BindingAdapter("binding_isGone")
fun View.bindingIsGone(gone: Boolean) {
internal fun View.bindingIsGone(gone: Boolean) {
visibility = if (gone) View.GONE else View.VISIBLE
}

@BindingAdapter("binding_isVisible")
fun View.bindingIsVisible(show: Boolean) {
internal fun View.bindingIsVisible(show: Boolean) {
visibility = if (show) View.VISIBLE else View.INVISIBLE
}

@BindingAdapter("binding_isSelected")
fun View.bindingIsSelect(select: Boolean) {
internal fun View.bindingIsSelect(select: Boolean) {
isSelected = select
}

@BindingAdapter("binding_rect_radius")
fun View.bindingRectCornerRadius(@Px radius: Float) {
internal 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)
Expand All @@ -43,41 +43,41 @@ fun View.bindingRectCornerRadius(@Px radius: Float) {
}

@BindingAdapter("binding_width", "binding_height")
fun View.bindingWidthAndHeight(@Px width: Float, @Px height: Float) {
internal 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) {
internal fun View.bindingWidth(@Px width: Float) {
layoutParams.width = width.toInt()
requestLayout()
}

@BindingAdapter("binding_height")
fun View.bindingHeight(@Px height: Float) {
internal fun View.bindingHeight(@Px height: Float) {
layoutParams.height = height.toInt()
requestLayout()
}

@BindingAdapter("binding_marginTop")
fun View.bindingMarginTop(@Px margin: Float) {
internal fun View.bindingMarginTop(@Px margin: Float) {
marginDirection(1, margin)
}

@BindingAdapter("binding_marginBottom")
fun View.bindingMarginBottom(@Px margin: Float) {
internal fun View.bindingMarginBottom(@Px margin: Float) {
marginDirection(3, margin)
}

@BindingAdapter("binding_marginStart")
fun View.bindingMarginStart(@Px margin: Float) {
internal fun View.bindingMarginStart(@Px margin: Float) {
marginDirection(0, margin)
}

@BindingAdapter("binding_marginEnd")
fun View.bindingMarginEnd(@Px margin: Float) {
internal fun View.bindingMarginEnd(@Px margin: Float) {
marginDirection(2, margin)
}

Expand All @@ -89,7 +89,7 @@ fun View.bindingMarginEnd(@Px margin: Float) {
"binding_bg_angle",
"binding_bg_radius"
)
fun View.bindingBgShapeGradual(
internal fun View.bindingBgShapeGradual(
@ColorInt startColor: Int,
@ColorInt endColor: Int,
angle: Int,
Expand All @@ -110,7 +110,7 @@ fun View.bindingBgShapeGradual(
"binding_bg_strokeColor",
"binding_bg_radius"
)
fun View.bindingBgShapeGradual(
internal fun View.bindingBgShapeGradual(
@ColorInt startColor: Int,
@ColorInt endColor: Int,
angle: Int,
Expand All @@ -134,7 +134,7 @@ fun View.bindingBgShapeGradual(
"binding_bg_angle",
"binding_bg_radius"
)
fun View.bindingBgShapeGradual(
internal fun View.bindingBgShapeGradual(
@ColorInt startColor: Int,
@ColorInt centerColor: Int,
@ColorInt endColor: Int,
Expand All @@ -161,7 +161,7 @@ fun View.bindingBgShapeGradual(
],
requireAll = false
)
fun View.bindingBgShapeCorners(
internal fun View.bindingBgShapeCorners(
@ColorInt solidColor: Int,
@Px topLeft: Float,
@Px topRight: Float,
Expand All @@ -176,7 +176,7 @@ fun View.bindingBgShapeCorners(
"binding_bg_endColor",
"binding_bg_angle"
)
fun View.bindingBgShapeGradual(
internal fun View.bindingBgShapeGradual(
@ColorInt startColor: Int,
@ColorInt endColor: Int,
angle: Int
Expand All @@ -190,7 +190,7 @@ fun View.bindingBgShapeGradual(
"binding_bg_endColor",
"binding_bg_angle"
)
fun View.bindingBgShapeGradual(
internal fun View.bindingBgShapeGradual(
@ColorInt startColor: Int,
@ColorInt centerColor: Int,
@ColorInt endColor: Int,
Expand All @@ -205,7 +205,7 @@ fun View.bindingBgShapeGradual(
"binding_bg_solidColor",
"binding_bg_radius"
)
fun View.bindingBgShapeStroke(
internal fun View.bindingBgShapeStroke(
@Px stroke: Float,
@ColorInt strokeColor: Int,
@ColorInt solidColor: Int,
Expand All @@ -223,7 +223,7 @@ fun View.bindingBgShapeStroke(
"binding_bg_solidColor",
"binding_bg_radius"
)
fun View.bindingBgShape(
internal fun View.bindingBgShape(
@ColorInt solidColor: Int,
@Px radius: Float
) {
Expand All @@ -235,7 +235,7 @@ fun View.bindingBgShape(
"binding_bg_strokeColor",
"binding_bg_solidOvalColor"
)
fun View.bindingBgShapeOvalStroke(
internal fun View.bindingBgShapeOvalStroke(
@Px stroke: Float,
@ColorInt strokeColor: Int,
@ColorInt solidOvalColor: Int
Expand All @@ -249,25 +249,25 @@ fun View.bindingBgShapeOvalStroke(
}

@BindingAdapter("binding_bg_solidOvalColor")
fun View.bindingBgShapeOval(@ColorInt solidOvalColor: Int) {
internal fun View.bindingBgShapeOval(@ColorInt solidOvalColor: Int) {
setBgShapeGradual(shapeType = GradientDrawable.OVAL, solidColor = solidOvalColor)
}

// ------------------------TextView--------------------------//

@BindingAdapter("binding_font_type")
fun TextView.bindingImpactTypeface(path: String) {
internal fun TextView.bindingImpactTypeface(path: String) {
typeface = Typeface.createFromAsset(context.assets, path)
}

@BindingAdapter("binding_paint_flag")
fun TextView.bindingPaintFlag(flag: Int) {
internal fun TextView.bindingPaintFlag(flag: Int) {
paint.flags = flag
paint.isAntiAlias = true
}

@BindingAdapter("binding_paint_flag_is_thru")
fun TextView.bindingPaintFlagThru(flag: Boolean) {
internal fun TextView.bindingPaintFlagThru(flag: Boolean) {
if (flag) {
paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
paint.isAntiAlias = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,64 @@ import com.scwang.smart.refresh.layout.SmartRefreshLayout
// ------------------------SmartRefreshLayout--------------------------//

@BindingAdapter("binding_srl_refreshFinish")
fun SmartRefreshLayout.bindingFinishRefresh(isFinish: Boolean) {
internal fun SmartRefreshLayout.bindingFinishRefresh(isFinish: Boolean) {
if (isFinish) finishRefresh()
}

@BindingAdapter("binding_srl_loadMoreFinish")
fun SmartRefreshLayout.bindingFinishLoadMore(isFinish: Boolean) {
internal fun SmartRefreshLayout.bindingFinishLoadMore(isFinish: Boolean) {
if (isFinish) finishLoadMore()
}

@BindingAdapter("binding_srl_enableLoadMore")
fun SmartRefreshLayout.bindingEnableLoadMore(enable: Boolean) {
internal fun SmartRefreshLayout.bindingEnableLoadMore(enable: Boolean) {
setEnableLoadMore(enable)
}

@BindingAdapter("binding_srl_enableRefresh")
fun SmartRefreshLayout.bindingEnableRefresh(enable: Boolean) {
internal fun SmartRefreshLayout.bindingEnableRefresh(enable: Boolean) {
setEnableRefresh(enable)
}

@BindingAdapter("binding_srl_noMore")
fun SmartRefreshLayout.bindingNoMoreData(haveNoMore: Boolean) {
internal fun SmartRefreshLayout.bindingNoMoreData(haveNoMore: Boolean) {
setNoMoreData(haveNoMore)
}

@BindingAdapter("binding_srl_headerEmpty")
fun SmartRefreshLayout.bindingHeaderEmpty(isEmpty: Boolean) {
internal 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) {
internal 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) {
internal 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) {
internal 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) {
internal 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) {
internal fun SmartRefreshLayout.bindingFooterAccentColor(@ColorInt color: Int) {
(refreshFooter as? ClassicsAbstract<*>)?.setAccentColor(color)
?: setRefreshFooter(ClassicsFooter(context).apply { setAccentColor(color) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ object ImageLoader {
// ------------------------BindingAdapter--------------------------//

@BindingAdapter("binding_iv_data")
fun ImageView.load(data: Any?) {
internal fun ImageView.bindingLoad(data: Any?) {
ImageLoader.load(this, data)
}

@BindingAdapter(
"binding_iv_data",
"binding_iv_cornerRadius"
)
fun ImageView.load(
internal fun ImageView.bindingLoad(
data: Any?,
@Px @FloatRange(from = 0.0) cornerRadius: Float
) {
Expand All @@ -123,7 +123,7 @@ fun ImageView.load(
"binding_iv_data",
"binding_iv_placeholder"
)
fun ImageView.load(
internal fun ImageView.bindingLoad(
data: Any?,
placeholderDrawable: Drawable?
) {
Expand All @@ -135,7 +135,7 @@ fun ImageView.load(
"binding_iv_placeholder",
"binding_iv_error"
)
fun ImageView.load(
internal fun ImageView.bindingLoad(
data: Any?,
placeholderDrawable: Drawable?,
errorDrawable: Drawable?
Expand All @@ -149,7 +149,7 @@ fun ImageView.load(
"binding_iv_error",
"binding_iv_cornerRadius"
)
fun ImageView.load(
internal fun ImageView.bindingLoad(
data: Any?,
placeholderDrawable: Drawable?,
errorDrawable: Drawable?,
Expand All @@ -165,7 +165,7 @@ fun ImageView.load(
"binding_iv_cornerRadius",
"binding_iv_useCache"
)
fun ImageView.load(
internal fun ImageView.bindingLoad(
data: Any?,
placeholderDrawable: Drawable?,
errorDrawable: Drawable?,
Expand All @@ -176,15 +176,15 @@ fun ImageView.load(
}

@BindingAdapter("binding_iv_data_circle")
fun ImageView.loadCircleCrop(data: Any?) {
internal fun ImageView.bindingLoadCircleCrop(data: Any?) {
ImageLoader.loadCircleCrop(this, data)
}

@BindingAdapter(
"binding_iv_data_circle",
"binding_iv_placeholder"
)
fun ImageView.loadCircleCrop(
internal fun ImageView.bindingLoadCircleCrop(
data: Any?,
placeholderDrawable: Drawable?
) {
Expand All @@ -196,7 +196,7 @@ fun ImageView.loadCircleCrop(
"binding_iv_placeholder",
"binding_iv_error"
)
fun ImageView.loadCircleCrop(
internal fun ImageView.bindingLoadCircleCrop(
data: Any?,
placeholderDrawable: Drawable?,
errorDrawable: Drawable?
Expand All @@ -210,7 +210,7 @@ fun ImageView.loadCircleCrop(
"binding_iv_error",
"binding_iv_useCache"
)
fun ImageView.loadCircleCrop(
internal fun ImageView.bindingLoadCircleCrop(
data: Any?,
placeholderDrawable: Drawable?,
errorDrawable: Drawable?,
Expand Down