diff --git a/Quick/src/main/java/com/wpf/app/quick/helper/attribute/MultiFunctionAttributeHelper.kt b/Quick/src/main/java/com/wpf/app/quick/helper/attribute/MultiFunctionAttributeHelper.kt index 7f92d7ae..84d0e668 100644 --- a/Quick/src/main/java/com/wpf/app/quick/helper/attribute/MultiFunctionAttributeHelper.kt +++ b/Quick/src/main/java/com/wpf/app/quick/helper/attribute/MultiFunctionAttributeHelper.kt @@ -14,40 +14,50 @@ import com.wpf.app.quick.helper.attribute.base.AutoGetAttributeHelper * Created by 王朋飞 on 2022/5/7. * */ -class MultiFunctionAttributeHelper - (context: Context, - attributeSet: AttributeSet -): AutoGetAttributeHelper(context, attributeSet, R.styleable.MultiFunctionView) { +class MultiFunctionAttributeHelper( + context: Context, + attributeSet: AttributeSet +) : AutoGetAttributeHelper(context, attributeSet, R.styleable.MultiFunctionView) { var showCheckBox: Boolean? = null var isCheck: Boolean? = null + //CheckBox大小 var checkBoxWidth: Int? = null + //CheckBox背景 - @DrawableRes var checkboxBackground: Int? = null + @DrawableRes + var checkboxBackground: Int? = null var checkboxBackgroundColor: Color? = null + //CheckBox左右边距 var checkboxLeftMarge: Int? = 0 var checkboxRightMarge: Int? = 0 var title: String? = null - @DrawableRes var titleBackground: Int? = null + @DrawableRes + var titleBackground: Int? = null var titleSize: Int? = null - @ColorRes var titleColor: Int? = null + @ColorRes + var titleColor: Int? = null var titleWpfStyle: Int? = null var titleMaxLine: Int? = null var subTitle: String? = null - @DrawableRes var subTitleBackground: Int? = null + @DrawableRes + var subTitleBackground: Int? = null var subTitleSize: Int? = null - @ColorRes var subTitleColor: Int? = null + @ColorRes + var subTitleColor: Int? = null var subTitleWpfStyle: Int? = null var subTitleMarginTop: Int? = null var subTitleMaxLine: Int? = null var showLeftImage: Boolean? = null - @DrawableRes var leftImageBackground: Int? = null - @DrawableRes var leftImageSrc: Int? = null + @DrawableRes + var leftImageBackground: Int? = null + @DrawableRes + var leftImageSrc: Int? = null var leftImageWidth: Int? = null get() = field ?: ViewGroup.LayoutParams.WRAP_CONTENT var leftImageScaleType: Int = 3 @@ -55,8 +65,10 @@ class MultiFunctionAttributeHelper var leftImageRightMarge: Int? = 0 var showRightImage: Boolean? = null - @DrawableRes var rightImageBackground: Int? = null - @DrawableRes var rightImageSrc: Int? = null + @DrawableRes + var rightImageBackground: Int? = null + @DrawableRes + var rightImageSrc: Int? = null var rightImageWidth: Int? = null get() = field ?: ViewGroup.LayoutParams.WRAP_CONTENT var rightImageScaleType: Int = 3 @@ -64,17 +76,17 @@ class MultiFunctionAttributeHelper var rightImageRightMarge: Int? = 0 var clickView: Int? = null - get() { - return when(field) { - 0 -> ItemView - 1 -> CheckBox - 2 -> LeftImage - 3 -> Title - 4 -> SubTitle - 5 -> RightImage - else -> ItemView + get() { + return when (field) { + 0 -> ItemView + 1 -> CheckBox + 2 -> LeftImage + 3 -> Title + 4 -> SubTitle + 5 -> RightImage + else -> ItemView + } } - } var clickOnlyCheckBox: Boolean? = null } \ No newline at end of file diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/MultiFunctionView.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/MultiFunctionView.kt index f4d3365c..d16c1a4e 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/MultiFunctionView.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/MultiFunctionView.kt @@ -44,9 +44,10 @@ class MultiFunctionView @JvmOverloads constructor( override fun onAttachedToWindow() { super.onAttachedToWindow() - attributes?.let { - attributeHelper = MultiFunctionAttributeHelper(context, attributes) - } + //预览时会报错 +// attributes?.let { +// attributeHelper = MultiFunctionAttributeHelper(context, attributes) +// } mLifecycleRegistry.currentState = Lifecycle.State.RESUMED } @@ -99,9 +100,7 @@ class MultiFunctionView @JvmOverloads constructor( } private fun loadCheckBoxAttribute() { - attributeHelper.showCheckBox?.let { - showCheckBox(it) - } + showCheckBox(attributeHelper.showCheckBox ?: false) attributeHelper.checkboxBackground?.let { setCheckBoxBackground(it) } @@ -145,9 +144,7 @@ class MultiFunctionView @JvmOverloads constructor( } private fun loadTitleAttribute() { - attributeHelper.title?.let { - setTitle(it) - } + setTitle(attributeHelper.title ?: "") attributeHelper.titleBackground?.let { setTitleBackground(it) } @@ -166,9 +163,7 @@ class MultiFunctionView @JvmOverloads constructor( } private fun loadSubTitleAttribute() { - attributeHelper.subTitle?.let { - setSubTitle(it) - } + setSubTitle(attributeHelper.subTitle ?: "") attributeHelper.subTitleBackground?.let { setSubTitleBackground(it) } @@ -418,7 +413,7 @@ class MultiFunctionView @JvmOverloads constructor( } } -interface CheckView: Checkable { +interface CheckView : Checkable { fun setOnCheckedChangeListener(listener: CompoundButton.OnCheckedChangeListener?) }