fix: 修复历史记录 Header 背景透明

This commit is contained in:
HuanChengFly 2021-06-17 17:10:57 +08:00
parent 7dfd4976d6
commit 7991a1bec9
7 changed files with 53 additions and 24 deletions

View File

@ -158,8 +158,8 @@ class NewSearchActivity : BaseActivity(), TabLayout.OnTabSelectedListener {
R.drawable.ic_round_keyboard, R.drawable.ic_round_keyboard,
if (histories.size > 0) R.drawable.ic_round_delete else NO_ICON if (histories.size > 0) R.drawable.ic_round_delete else NO_ICON
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
backgroundTintList = R.color.default_color_card headerBackgroundTintList = R.color.default_color_card
iconTintList = R.color.default_color_primary iconTintList = R.color.default_color_primary
titleTextColor = R.color.default_color_primary titleTextColor = R.color.default_color_primary
topMargin = resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = resources.getDimensionPixelSize(R.dimen.card_margin)
@ -207,8 +207,8 @@ class NewSearchActivity : BaseActivity(), TabLayout.OnTabSelectedListener {
R.drawable.ic_round_polymer, R.drawable.ic_round_polymer,
R.drawable.ic_round_chevron_right R.drawable.ic_round_chevron_right
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
backgroundTintList = R.color.default_color_card headerBackgroundTintList = R.color.default_color_card
iconTintList = R.color.default_color_primary iconTintList = R.color.default_color_primary
titleTextColor = R.color.default_color_primary titleTextColor = R.color.default_color_primary
topMargin = resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = resources.getDimensionPixelSize(R.dimen.card_margin)

View File

@ -1,11 +1,15 @@
package com.huanchengfly.tieba.post.adapters package com.huanchengfly.tieba.post.adapters
import android.content.Context import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.alibaba.android.vlayout.DelegateAdapter import com.alibaba.android.vlayout.DelegateAdapter
@ -68,12 +72,23 @@ class HeaderDelegateAdapter @JvmOverloads constructor(
notifyDataSetChanged() notifyDataSetChanged()
} }
var background: Drawable? = null var viewBackground: Drawable? = null
set(value) { set(value) {
field = value field = value
notifyDataSetChanged() notifyDataSetChanged()
} }
var backgroundTintList: Int = R.color.default_color_card var viewBackgroundTintList: Int = 0
set(value) {
field = value
notifyDataSetChanged()
}
var headerBackground: Drawable? = null
set(value) {
field = value
notifyDataSetChanged()
}
var headerBackgroundTintList: Int = R.color.default_color_card
set(value) { set(value) {
field = value field = value
notifyDataSetChanged() notifyDataSetChanged()
@ -150,8 +165,18 @@ class HeaderDelegateAdapter @JvmOverloads constructor(
}) })
} }
fun setBackgroundResource(@DrawableRes resId: Int) { fun setHeaderBackgroundResource(@DrawableRes resId: Int) {
background = ContextCompat.getDrawable(context, resId) headerBackground = ContextCompat.getDrawable(context, resId)
}
fun setViewBackgroundColor(@ColorInt color: Int) {
viewBackground = ColorDrawable(color)
viewBackgroundTintList = 0
}
fun setViewBackgroundColorResource(@ColorRes resId: Int) {
viewBackground = ColorDrawable(Color.WHITE)
viewBackgroundTintList = resId
} }
constructor( constructor(
@ -188,8 +213,10 @@ class HeaderDelegateAdapter @JvmOverloads constructor(
this.marginEnd = this@HeaderDelegateAdapter.endMargin this.marginEnd = this@HeaderDelegateAdapter.endMargin
this.bottomMargin = this@HeaderDelegateAdapter.bottomMargin this.bottomMargin = this@HeaderDelegateAdapter.bottomMargin
} }
rootView.background = background rootView.background = headerBackground
rootView.backgroundTintList = ColorStateListUtils.createColorStateList(context, backgroundTintList) rootView.backgroundTintList = if (headerBackgroundTintList == 0) null else ColorStateListUtils.createColorStateList(context, headerBackgroundTintList)
holder.itemView.background = viewBackground
holder.itemView.backgroundTintList = if (viewBackgroundTintList == 0) null else ColorStateListUtils.createColorStateList(context, viewBackgroundTintList)
holder.getView<TintImageView>(R.id.icon).setTintListResId(iconTintList) holder.getView<TintImageView>(R.id.icon).setTintListResId(iconTintList)
holder.getView<TintImageView>(R.id.end_icon).setTintListResId(iconTintList) holder.getView<TintImageView>(R.id.end_icon).setTintListResId(iconTintList)
holder.getView<TintTextView>(R.id.title).tintResId = titleTextColor holder.getView<TintTextView>(R.id.title).tintResId = titleTextColor

View File

@ -80,10 +80,11 @@ class HistoryFragment : BaseFragment(), OnItemClickListener<History>, Refreshabl
startIconResId = R.drawable.ic_date_range, startIconResId = R.drawable.ic_date_range,
sticky = HeaderDelegateAdapter.STICKY_START sticky = HeaderDelegateAdapter.STICKY_START
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
iconTintList = R.color.default_color_primary iconTintList = R.color.default_color_primary
titleTextColor = R.color.default_color_primary titleTextColor = R.color.default_color_primary
backgroundTintList = R.color.default_color_card headerBackgroundTintList = R.color.default_color_card
setViewBackgroundColorResource(R.color.default_color_window_background)
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
startPadding = 12.dpToPx() startPadding = 12.dpToPx()
endPadding = 12.dpToPx() endPadding = 12.dpToPx()
@ -97,10 +98,11 @@ class HistoryFragment : BaseFragment(), OnItemClickListener<History>, Refreshabl
startIconResId = R.drawable.ic_date_range, startIconResId = R.drawable.ic_date_range,
sticky = HeaderDelegateAdapter.STICKY_START sticky = HeaderDelegateAdapter.STICKY_START
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
iconTintList = R.color.default_color_primary iconTintList = R.color.default_color_primary
titleTextColor = R.color.default_color_primary titleTextColor = R.color.default_color_primary
backgroundTintList = R.color.default_color_card headerBackgroundTintList = R.color.default_color_card
setViewBackgroundColorResource(R.color.default_color_window_background)
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
startPadding = 12.dpToPx() startPadding = 12.dpToPx()
endPadding = 12.dpToPx() endPadding = 12.dpToPx()

View File

@ -220,8 +220,8 @@ class MainForumListFragment : BaseFragment(), Refreshable, Toolbar.OnMenuItemCli
R.string.title_top_forum, R.string.title_top_forum,
R.drawable.ic_round_graphic_eq R.drawable.ic_round_graphic_eq
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
backgroundTintList = R.color.default_color_card headerBackgroundTintList = R.color.default_color_card
iconTintList = R.color.default_color_primary iconTintList = R.color.default_color_primary
titleTextColor = R.color.default_color_primary titleTextColor = R.color.default_color_primary
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
@ -236,8 +236,8 @@ class MainForumListFragment : BaseFragment(), Refreshable, Toolbar.OnMenuItemCli
R.string.forum_list_title, R.string.forum_list_title,
R.drawable.ic_infinite R.drawable.ic_infinite
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
backgroundTintList = R.color.default_color_card headerBackgroundTintList = R.color.default_color_card
iconTintList = R.color.default_color_primary iconTintList = R.color.default_color_primary
titleTextColor = R.color.default_color_primary titleTextColor = R.color.default_color_primary
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)

View File

@ -112,7 +112,7 @@ class SearchForumFragment : BaseFragment(), ISearchFragment, OnItemClickListener
R.string.title_exact_match, R.string.title_exact_match,
R.drawable.ic_round_graphic_eq R.drawable.ic_round_graphic_eq
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
startPadding = 16.dpToPx() startPadding = 16.dpToPx()
endPadding = 16.dpToPx() endPadding = 16.dpToPx()
@ -126,7 +126,7 @@ class SearchForumFragment : BaseFragment(), ISearchFragment, OnItemClickListener
R.string.title_fuzzy_match, R.string.title_fuzzy_match,
R.drawable.ic_infinite R.drawable.ic_infinite
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
startPadding = 16.dpToPx() startPadding = 16.dpToPx()
endPadding = 16.dpToPx() endPadding = 16.dpToPx()

View File

@ -110,8 +110,8 @@ class SearchThreadFragment : BaseFragment(), ISearchFragment, NewSearchActivity.
attachContext, attachContext,
titleResId = getSearchFilterTitleResId(filter) titleResId = getSearchFilterTitleResId(filter)
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
backgroundTintList = R.color.default_color_card headerBackgroundTintList = R.color.default_color_card
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
}) })
delegateAdapter.addAdapter(searchThreadAdapter!!.apply { delegateAdapter.addAdapter(searchThreadAdapter!!.apply {

View File

@ -99,7 +99,7 @@ class SearchUserFragment : BaseFragment(), ISearchFragment, OnItemClickListener<
R.string.title_exact_match, R.string.title_exact_match,
R.drawable.ic_round_graphic_eq R.drawable.ic_round_graphic_eq
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
startPadding = 16.dpToPx() startPadding = 16.dpToPx()
endPadding = 16.dpToPx() endPadding = 16.dpToPx()
@ -113,7 +113,7 @@ class SearchUserFragment : BaseFragment(), ISearchFragment, OnItemClickListener<
R.string.title_fuzzy_match, R.string.title_fuzzy_match,
R.drawable.ic_infinite R.drawable.ic_infinite
).apply { ).apply {
setBackgroundResource(R.drawable.bg_top_radius_8dp) setHeaderBackgroundResource(R.drawable.bg_top_radius_8dp)
topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin) topMargin = attachContext.resources.getDimensionPixelSize(R.dimen.card_margin)
startPadding = 16.dpToPx() startPadding = 16.dpToPx()
endPadding = 16.dpToPx() endPadding = 16.dpToPx()