From 2c38c8fd91fe1587abff857cfbeef4f167fdd49e Mon Sep 17 00:00:00 2001 From: lyr <15622190878@163.com> Date: Tue, 28 Sep 2021 17:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=93=E9=A2=98=E5=90=88?= =?UTF-8?q?=E9=9B=86-=E6=8E=92=E8=A1=8C=E6=A6=9C=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gh/gamecenter/game/rank/RankAdapter.kt | 66 +++++++++++++------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/gh/gamecenter/game/rank/RankAdapter.kt b/app/src/main/java/com/gh/gamecenter/game/rank/RankAdapter.kt index 3eed0069f8..497771b43e 100644 --- a/app/src/main/java/com/gh/gamecenter/game/rank/RankAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/game/rank/RankAdapter.kt @@ -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