pull/2410/head
kunfei 3 years ago
parent 5302f210b4
commit 9ecc48b310
  1. 24
      app/src/main/java/io/legado/app/lib/prefs/Preference.kt
  2. 2
      app/src/main/res/layout/activity_book_search.xml
  3. 1
      app/src/main/res/layout/dialog_search_scope.xml

@ -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 if (viewHolder == null) return null
val tvTitle = it.findViewById(R.id.preference_title) as TextView val tvTitle = viewHolder.findViewById(R.id.preference_title) as? TextView
tvTitle.text = title tvTitle?.let {
tvTitle.isVisible = title != null && title.isNotEmpty() tvTitle.text = title
val tvSummary = it.findViewById(R.id.preference_desc) as? TextView 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)

@ -63,6 +63,7 @@
android:id="@+id/tv_toggle_search_scope" android:id="@+id/tv_toggle_search_scope"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="6dp" android:padding="6dp"
android:text="@string/toggle_search_scope" /> android:text="@string/toggle_search_scope" />
@ -104,6 +105,7 @@
android:id="@+id/tv_clear_history" android:id="@+id/tv_clear_history"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="6dp" android:padding="6dp"
android:text="@string/clear" /> android:text="@string/clear" />

@ -3,4 +3,5 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save