From 7b9945b0c94bb397708a27b221a6ba02be714452 Mon Sep 17 00:00:00 2001 From: liujing Date: Wed, 13 Oct 2021 20:02:09 +0800 Subject: [PATCH] =?UTF-8?q?[add]=20=E5=B0=9D=E8=AF=95=E6=B7=BB=E5=8A=A0foo?= =?UTF-8?q?ter=E5=AE=9E=E7=8E=B0=E8=92=99=E5=B1=82+=E6=BB=91=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../function/check/view/CheckInfoAdapter.java | 61 +++++++++++++------ .../check/view/CheckRecyclerFooter.java | 28 +++++++++ .../main/res/layout/check_recycler_footer.xml | 8 +++ 3 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckRecyclerFooter.java create mode 100644 core/function-impl/mogo-core-function-check/src/main/res/layout/check_recycler_footer.xml diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java index afad70b474..158bcaba3d 100644 --- a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckInfoAdapter.java @@ -5,6 +5,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.ScrollView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -25,6 +26,11 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { private Context mContext; private String mStyle; private List showData; + //item类型 + public static final int ITEM_TYPE_CONTENT = 0;//内容 + public static final int ITEM_TYPE_BOTTOM = 1;//footer类型 + //底部View个数 + private int mBottomCount = 1; public CheckInfoAdapter(Context context, String style, List checkResultData) { mContext = context; @@ -36,6 +42,12 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + if (viewType == ITEM_TYPE_BOTTOM) { + View v = mLayoutInflater.inflate(R.layout.check_recycler_footer, parent, + false); + CheckInfoAdapter.CheckInfoFooter holder = new CheckInfoAdapter.CheckInfoFooter(v); + return holder; + } View v = mLayoutInflater.inflate(R.layout.check_info_adapter, parent, false); CheckInfoAdapter.CheckInfoViewHolder holder = new CheckInfoAdapter.CheckInfoViewHolder(v); @@ -46,23 +58,25 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { try { - if (position < showData.size() * 2) { - int index = position / 2; - CheckResultData.CheckListItem positionItem = showData.get(index); - if (isEven(position) == true) {//偶数隐藏图片显示检测指标 - ((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.GONE); - ((CheckInfoViewHolder) holder).mTextView.setText(positionItem.getName()); - } else {//奇数显示图片和检测指标结果 - ((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.VISIBLE); - String state = (String) positionItem.getStateValue(); - if (state.equals("1")) { - ((CheckInfoViewHolder) holder).mTextView.setText("正常"); - ((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_right); - } else if ((state.equals("0"))) { - ((CheckInfoViewHolder) holder).mTextView.setText("异常"); - ((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_wrong); - } else { - ((CheckInfoViewHolder) holder).mTextView.setText(state); + if (holder instanceof CheckInfoAdapter.CheckInfoViewHolder) { + if (position < showData.size() * 2) { + int index = position / 2; + CheckResultData.CheckListItem positionItem = showData.get(index); + if (isEven(position) == true) {//偶数隐藏图片显示检测指标 + ((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.GONE); + ((CheckInfoViewHolder) holder).mTextView.setText(positionItem.getName()); + } else {//奇数显示图片和检测指标结果 + ((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.VISIBLE); + String state = (String) positionItem.getStateValue(); + if (state.equals("1")) { + ((CheckInfoViewHolder) holder).mTextView.setText("正常"); + ((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_right); + } else if ((state.equals("0"))) { + ((CheckInfoViewHolder) holder).mTextView.setText("异常"); + ((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_wrong); + } else { + ((CheckInfoViewHolder) holder).mTextView.setText(state); + } } } } @@ -83,7 +97,7 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { @Override public int getItemCount() { - return showData.size() * 2; + return showData.size() * 2 + mBottomCount; } public class CheckInfoViewHolder extends RecyclerView.ViewHolder { @@ -97,8 +111,17 @@ public class CheckInfoAdapter extends RecyclerView.Adapter { } } + public class CheckInfoFooter extends RecyclerView.ViewHolder { + public CheckInfoFooter(View v) { + super(v); + } + } + @Override public int getItemViewType(int position) { - return position; + if (position > showData.size() * 2) { + return ITEM_TYPE_BOTTOM; + } + return ITEM_TYPE_CONTENT; } } diff --git a/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckRecyclerFooter.java b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckRecyclerFooter.java new file mode 100644 index 0000000000..f072f65a03 --- /dev/null +++ b/core/function-impl/mogo-core-function-check/src/main/java/com/mogo/eagle/core/function/check/view/CheckRecyclerFooter.java @@ -0,0 +1,28 @@ +package com.mogo.eagle.core.function.check.view; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; + +import com.mogo.eagle.core.function.check.R; + +import java.util.jar.Attributes; + +/** + * @author liujing + * @description 描述 + * @since: 10/13/21 + */ +public class CheckRecyclerFooter extends View { + + public CheckRecyclerFooter(Context context, AttributeSet attributes) { + super(context, attributes); + LayoutInflater.from(context).inflate(R.layout.check_recycler_footer, null); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } +} diff --git a/core/function-impl/mogo-core-function-check/src/main/res/layout/check_recycler_footer.xml b/core/function-impl/mogo-core-function-check/src/main/res/layout/check_recycler_footer.xml new file mode 100644 index 0000000000..3ee8f46ef4 --- /dev/null +++ b/core/function-impl/mogo-core-function-check/src/main/res/layout/check_recycler_footer.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file