优化首页列表性能
This commit is contained in:
@ -12,6 +12,7 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.gh.common.AppExecutor;
|
||||
import com.gh.common.view.DrawableView;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.TagStyleEntity;
|
||||
@ -25,11 +26,7 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-14
|
||||
* @update 2015-8-14
|
||||
* @des 设置列表中game item视图上的工具类
|
||||
* 设置列表中game item视图上的工具类
|
||||
*/
|
||||
public class GameViewUtils {
|
||||
|
||||
@ -37,20 +34,34 @@ public class GameViewUtils {
|
||||
setLabelList(context, labelLayout, tagStyle, 8);
|
||||
}
|
||||
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout, List<TagStyleEntity> tagStyle, int margin) {
|
||||
labelLayout.removeAllViews();
|
||||
if (tagStyle == null || tagStyle.isEmpty()) {
|
||||
// 没有数据的话默认不显示
|
||||
// TagStyleEntity tagEntity = new TagStyleEntity();
|
||||
// tagEntity.setName("官方版");
|
||||
// labelLayout.addView(getNewGameTagView(context, tagEntity, 0));
|
||||
} else {
|
||||
for (int i = 0, size = tagStyle.size(); i < size; i++) {
|
||||
View view = getNewGameTagView(context, tagStyle.get(i), i == size - 1 ? 0 : DisplayUtils.dip2px(context, margin));
|
||||
labelLayout.addView(view);
|
||||
if (labelLayout.getChildCount() == 3) {
|
||||
break;
|
||||
}
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout, List<TagStyleEntity> tagEntityList, int margin) {
|
||||
int childTvCount = labelLayout.getChildCount();
|
||||
|
||||
for (int k = 0; k < childTvCount; k++) {
|
||||
labelLayout.getChildAt(k).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (tagEntityList == null || tagEntityList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0, size = tagEntityList.size(); i < size; i++) {
|
||||
TextView tagTv;
|
||||
TagStyleEntity tagEntity = tagEntityList.get(i);
|
||||
int marginRight = i == size - 1 ? 0 : DisplayUtils.dip2px(context, margin);
|
||||
|
||||
if (i < childTvCount) {
|
||||
tagTv = (TextView) labelLayout.getChildAt(i);
|
||||
updateTagStyle(context, tagTv, tagEntity, marginRight);
|
||||
} else {
|
||||
AppExecutor.getLightWeightIoExecutor().execute(() -> {
|
||||
TextView tv = getNewGameTagView(context, tagEntity, marginRight);
|
||||
AppExecutor.getUiExecutor().execute(() -> labelLayout.addView(tv));
|
||||
});
|
||||
}
|
||||
|
||||
if (i >= 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,23 +95,32 @@ public class GameViewUtils {
|
||||
return getGameTagView(context, tagEntity.getName(), rightMargin, "type", tagEntity);
|
||||
}
|
||||
|
||||
TextView tag = new TextView(context);
|
||||
updateTagStyle(context, tag, tagEntity, rightMargin);
|
||||
return tag;
|
||||
}
|
||||
|
||||
private static void updateTagStyle(Context context, TextView textView, TagStyleEntity tagEntity, int rightMargin) {
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
|
||||
// 同样的内容不用再更新
|
||||
if (textView.getText() == tagEntity.getName()) return;
|
||||
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
lparams.rightMargin = rightMargin;
|
||||
TextView tag = new TextView(context);
|
||||
tag.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
|
||||
tag.setSingleLine(true);
|
||||
tag.setText(tagEntity.getName());
|
||||
tag.setLayoutParams(lparams);
|
||||
tag.setPadding(
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
|
||||
textView.setSingleLine(true);
|
||||
textView.setText(tagEntity.getName());
|
||||
textView.setLayoutParams(lparams);
|
||||
textView.setPadding(
|
||||
DisplayUtils.dip2px(context, 4),
|
||||
0,
|
||||
DisplayUtils.dip2px(context, 4),
|
||||
DisplayUtils.dip2px(context, 1));
|
||||
|
||||
tag.setTextColor(Color.parseColor("#" + tagEntity.getColor()));
|
||||
tag.setBackground(DrawableView.getServerDrawable(Color.parseColor("#" + tagEntity.getBackground())));
|
||||
return tag;
|
||||
textView.setTextColor(Color.parseColor("#" + tagEntity.getColor()));
|
||||
textView.setBackground(DrawableView.getServerDrawable(Color.parseColor("#" + tagEntity.getBackground())));
|
||||
}
|
||||
|
||||
private static TextView getGameTagView(Context context, String tagStr, int rightMargin, String tagType, TagStyleEntity tagEntity) {
|
||||
|
||||
Reference in New Issue
Block a user