|
@@ -37,7 +37,7 @@ class Preference(context: Context, attrs: AttributeSet) :
|
|
|
|
|
|
|
|
fun <T : View> bindView(
|
|
fun <T : View> bindView(
|
|
|
context: Context,
|
|
context: Context,
|
|
|
- it: PreferenceViewHolder?,
|
|
|
|
|
|
|
+ viewHolder: PreferenceViewHolder?,
|
|
|
icon: Drawable?,
|
|
icon: Drawable?,
|
|
|
title: CharSequence?,
|
|
title: CharSequence?,
|
|
|
summary: CharSequence?,
|
|
summary: CharSequence?,
|
|
@@ -47,23 +47,25 @@ class Preference(context: Context, attrs: AttributeSet) :
|
|
|
weightHeight: Int = 0,
|
|
weightHeight: Int = 0,
|
|
|
isBottomBackground: Boolean = false
|
|
isBottomBackground: Boolean = false
|
|
|
): T? {
|
|
): T? {
|
|
|
- if (it == null) return null
|
|
|
|
|
- val tvTitle = it.findViewById(R.id.preference_title) as TextView
|
|
|
|
|
- tvTitle.text = title
|
|
|
|
|
- tvTitle.isVisible = title != null && title.isNotEmpty()
|
|
|
|
|
- val tvSummary = it.findViewById(R.id.preference_desc) as? TextView
|
|
|
|
|
|
|
+ if (viewHolder == null) return null
|
|
|
|
|
+ val tvTitle = viewHolder.findViewById(R.id.preference_title) as? TextView
|
|
|
|
|
+ tvTitle?.let {
|
|
|
|
|
+ tvTitle.text = title
|
|
|
|
|
+ tvTitle.isVisible = title != null && title.isNotEmpty()
|
|
|
|
|
+ }
|
|
|
|
|
+ val tvSummary = viewHolder.findViewById(R.id.preference_desc) as? TextView
|
|
|
tvSummary?.let {
|
|
tvSummary?.let {
|
|
|
tvSummary.text = summary
|
|
tvSummary.text = summary
|
|
|
tvSummary.isGone = summary.isNullOrEmpty()
|
|
tvSummary.isGone = summary.isNullOrEmpty()
|
|
|
}
|
|
}
|
|
|
- if (isBottomBackground && !tvTitle.isInEditMode) {
|
|
|
|
|
|
|
+ if (isBottomBackground && !viewHolder.itemView.isInEditMode) {
|
|
|
val isLight = ColorUtils.isColorLight(context.bottomBackground)
|
|
val isLight = ColorUtils.isColorLight(context.bottomBackground)
|
|
|
val pTextColor = context.getPrimaryTextColor(isLight)
|
|
val pTextColor = context.getPrimaryTextColor(isLight)
|
|
|
- tvTitle.setTextColor(pTextColor)
|
|
|
|
|
|
|
+ tvTitle?.setTextColor(pTextColor)
|
|
|
val sTextColor = context.getSecondaryTextColor(isLight)
|
|
val sTextColor = context.getSecondaryTextColor(isLight)
|
|
|
tvSummary?.setTextColor(sTextColor)
|
|
tvSummary?.setTextColor(sTextColor)
|
|
|
}
|
|
}
|
|
|
- val iconView = it.findViewById(R.id.preference_icon)
|
|
|
|
|
|
|
+ val iconView = viewHolder.findViewById(R.id.preference_icon)
|
|
|
if (iconView is ImageView) {
|
|
if (iconView is ImageView) {
|
|
|
iconView.isVisible = icon != null
|
|
iconView.isVisible = icon != null
|
|
|
iconView.setImageDrawable(icon)
|
|
iconView.setImageDrawable(icon)
|
|
@@ -71,10 +73,10 @@ class Preference(context: Context, attrs: AttributeSet) :
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) {
|
|
if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) {
|
|
|
- val lay = it.findViewById(R.id.preference_widget)
|
|
|
|
|
|
|
+ val lay = viewHolder.findViewById(R.id.preference_widget)
|
|
|
if (lay is FrameLayout) {
|
|
if (lay is FrameLayout) {
|
|
|
var needRequestLayout = false
|
|
var needRequestLayout = false
|
|
|
- var v = it.itemView.findViewById<T>(viewId)
|
|
|
|
|
|
|
+ var v = viewHolder.itemView.findViewById<T>(viewId)
|
|
|
if (v == null) {
|
|
if (v == null) {
|
|
|
val inflater: LayoutInflater = LayoutInflater.from(context)
|
|
val inflater: LayoutInflater = LayoutInflater.from(context)
|
|
|
val childView = inflater.inflate(weightLayoutRes, null)
|
|
val childView = inflater.inflate(weightLayoutRes, null)
|