优化专题合集-排行榜样式标签加载

This commit is contained in:
lyr
2021-09-28 17:10:36 +08:00
parent 15385cf78c
commit 2c38c8fd91

View File

@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.setPadding
import com.gh.common.AppExecutor
import com.gh.common.exposure.ExposureEvent
import com.gh.common.util.*
import com.gh.gamecenter.GameDetailActivity
@ -68,30 +69,47 @@ class RankAdapter(
holder.initServerType(gameEntity)
executePendingBindings()
val tagContainer = LinearLayout(mContext).apply {
orientation = LinearLayout.HORIZONTAL
layoutParams = LinearLayout.LayoutParams(
92F.dip2px(),
LinearLayout.LayoutParams.WRAP_CONTENT
).apply { topMargin = 8F.dip2px() }
}
tagContainer.run {
tag = "tagContainer"
removeAllViews()
run outside@ {
gameEntity.tagStyle.forEach {
addView(getGameTagView(it))
if (childCount >= 3) return@outside
val isNeedAddView: Boolean
val tagContainer: LinearLayout
contentContainer.run {
if (childCount > 0 && getChildAt(childCount - 1).tag == "tagContainer") {
isNeedAddView = false
tagContainer = getChildAt(childCount - 1) as LinearLayout
} else {
isNeedAddView = true
tagContainer = LinearLayout(mContext).apply {
tag = "tagContainer"
orientation = LinearLayout.HORIZONTAL
layoutParams = LinearLayout.LayoutParams(
92F.dip2px(),
LinearLayout.LayoutParams.WRAP_CONTENT
).apply { topMargin = 8F.dip2px() }
}
}
}
contentContainer.run {
if (childCount > 0 && getChildAt(childCount - 1).tag == "tagContainer") {
removeViewAt(childCount - 1)
tagContainer.run {
for (i in 0 until childCount) {
getChildAt(i).visibility = View.GONE
}
run outside@ {
gameEntity.tagStyle.forEachIndexed { index, tagStyleEntity ->
if (index < childCount) {
updateGameTagView(getChildAt(index) as TextView, tagStyleEntity)
} else {
AppExecutor.lightWeightIoExecutor.execute {
val tagView = getGameTagView(tagStyleEntity)
AppExecutor.uiExecutor.execute { addView(tagView) }
}
}
if (index >= 2) return@outside
}
}
addView(tagContainer)
}
if (isNeedAddView) contentContainer.addView(tagContainer)
gameIconView.layoutParams = gameIconView.layoutParams.apply {
width = 40F.dip2px()
height = 40F.dip2px()
@ -203,8 +221,18 @@ class RankAdapter(
}
}
fun getGameTagView(tagEntity: TagStyleEntity): TextView {
private fun getGameTagView(tagEntity: TagStyleEntity): TextView {
return TextView(mContext).apply {
updateGameTagView(this, tagEntity)
}
}
private fun updateGameTagView(textView: TextView, tagEntity: TagStyleEntity) {
textView.run {
visibility = View.VISIBLE
if (text == tagEntity.name) return
isSingleLine = true
ellipsize = TextUtils.TruncateAt.END
includeFontPadding = false