| | |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.view.Gravity; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.enums.DebugStatus; |
| | | import com.hdl.photovoltaic.enums.DeliverStatus; |
| | | import com.hdl.photovoltaic.enums.PowerStationStatus; |
| | | import com.hdl.photovoltaic.enums.PowerStationType; |
| | | import com.hdl.photovoltaic.enums.UnitType; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | |
| | | |
| | | |
| | | public class HouseInfoAdapter extends RecyclerView.Adapter<HouseInfoAdapter.MyViewHolder> { |
| | | |
| | | // 定义不同的 viewType 常量 |
| | | public static final int VIEW_TYPE_NORMAL = 1; // 普通电站详情 |
| | | public static final int VIEW_TYPE_BMS = 2; // BMS数据卡片 |
| | | private List<HouseIdBean> mList; |
| | | private final Context mContext; |
| | | private OnclickListener noOnclickListener;//点击了的监听器 |
| | |
| | | this.mContext = context; |
| | | } |
| | | |
| | | @Override |
| | | public int getItemViewType(int position) { |
| | | HouseIdBean item = this.mList.get(position); |
| | | if (item.getPowerStationType().equals(PowerStationType.BMS)) { |
| | | return VIEW_TYPE_BMS; |
| | | } else { |
| | | return VIEW_TYPE_NORMAL; |
| | | } |
| | | } |
| | | |
| | | @NonNull |
| | | @Override |
| | | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
| | | View contentItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_plant_details, parent, false); |
| | | View contentItem; |
| | | // 根据 viewType 加载不同的布局文件 |
| | | if (viewType == VIEW_TYPE_BMS) { |
| | | contentItem = LayoutInflater.from(parent.getContext()) |
| | | .inflate(R.layout.item_plant_bms_details, parent, false); |
| | | } else { |
| | | contentItem = LayoutInflater.from(parent.getContext()) |
| | | .inflate(R.layout.item_plant_details, parent, false); |
| | | } |
| | | return new MyViewHolder(contentItem); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { |
| | | |
| | | |
| | | HouseIdBean houseIdBean = this.mList.get(position); |
| | | holder.homeNameTv.setText(houseIdBean.getHomeName().trim()); |
| | | int viewType = getItemViewType(position); |
| | | if (viewType == VIEW_TYPE_BMS) { |
| | | holder.setText(R.id.bms_home_name_tv, houseIdBean.getHomeName().trim()); |
| | | //电池能量(容量*电池数量) |
| | | holder.setText(R.id.bms_battery_storage_value_tv, HdlCommonLogic.convertDoubleValue(houseIdBean.getBatteryCapacity(), UnitType.kWh)); |
| | | holder.setText(R.id.bms_battery_storage_kw_unit, HdlCommonLogic.convertKWHUnit(houseIdBean.getBatteryCapacity())); |
| | | holder.setText(R.id.bms_home_location_tv, houseIdBean.getHomeAddress()); |
| | | holder.getView(R.id.bms_item_parent_rl).setTag(position); |
| | | setHomeStateTextViewStyle(holder.getView(R.id.bms_home_state_tv), houseIdBean.getPowerStationStatus()); |
| | | setHomeDebugStateTextViewStyle(holder.getView(R.id.bms_home_debug_state_tv), holder.getView(R.id.bms_home_debug_state_iv), houseIdBean.getDebugStatus()); |
| | | GlideUtils.getRoundedCornersImage(mContext, houseIdBean.getPowerStationImage(), holder.getView(R.id.bms_home_image_iv), 6); |
| | | holder.getView(R.id.bms_item_parent_rl).setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onClick((int) holder.getView(R.id.bms_item_parent_rl).getTag(), houseIdBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | //移动电站位置 |
| | | holder.getView(R.id.bms_move_ll).setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onMoveClick((int) holder.getView(R.id.bms_item_parent_rl).getTag(), houseIdBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | holder.getView(R.id.bms_del_ll).setVisibility(View.GONE); |
| | | if (houseIdBean.getDebugStatus().equals(DebugStatus.Debugging)) { |
| | | //未交付完要显示删除按钮 |
| | | holder.getView(R.id.bms_del_ll).setVisibility(View.VISIBLE); |
| | | holder.setImageResource(R.id.bms_del_home_iv, R.drawable.del_home); |
| | | } |
| | | if (houseIdBean.getDebugStatus().equals(DebugStatus.WAIT_DELIVERED)) { |
| | | //更改成回滚图标 |
| | | holder.getView(R.id.bms_del_ll).setVisibility(View.VISIBLE); |
| | | holder.setImageResource(R.id.bms_del_home_iv, R.drawable.roll_back); |
| | | } |
| | | |
| | | //组串容量(创建电站时输入的组串容量) |
| | | holder.pv_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getInstalledCapacity(), UnitType.kWp)); |
| | | holder.pv_kw_unit.setText(HdlCommonLogic.convertKWPUnit(houseIdBean.getInstalledCapacity())); |
| | | //当日发电 |
| | | holder.generation_today_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getTodayElectricity(), UnitType.kWh)); |
| | | holder.generation_today_kw_unit.setText(HdlCommonLogic.convertKWHUnit(houseIdBean.getTodayElectricity())); |
| | | //逆变器额定功率(单个逆变器额定功率*逆变器数量) |
| | | holder.output_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getInvPower(), UnitType.kW)); |
| | | holder.output_kw_unit.setText(HdlCommonLogic.convertKWUnit(houseIdBean.getInvPower())); |
| | | //电池能量(容量*电池数量) |
| | | holder.battery_storage_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getBatteryCapacity(), UnitType.kWh)); |
| | | holder.battery_storage_kw_unit.setText(HdlCommonLogic.convertKWHUnit(houseIdBean.getBatteryCapacity())); |
| | | //删除电站 |
| | | holder.getView(R.id.bms_del_ll).setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onDelClick((int) holder.item_parent_rl.getTag(), houseIdBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | if (UserConfigManage.getInstance().isTourist_mode()) { |
| | | holder.getView(R.id.bms_del_ll).setVisibility(View.GONE); |
| | | } |
| | | } else { |
| | | holder.homeNameTv.setText(houseIdBean.getHomeName().trim()); |
| | | //组串容量(创建电站时输入的组串容量) |
| | | holder.pv_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getInstalledCapacity(), UnitType.kWp)); |
| | | holder.pv_kw_unit.setText(HdlCommonLogic.convertKWPUnit(houseIdBean.getInstalledCapacity())); |
| | | //当日发电 |
| | | holder.generation_today_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getTodayElectricity(), UnitType.kWh)); |
| | | holder.generation_today_kw_unit.setText(HdlCommonLogic.convertKWHUnit(houseIdBean.getTodayElectricity())); |
| | | //逆变器额定功率(单个逆变器额定功率*逆变器数量) |
| | | holder.output_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getInvPower(), UnitType.kW)); |
| | | holder.output_kw_unit.setText(HdlCommonLogic.convertKWUnit(houseIdBean.getInvPower())); |
| | | //电池能量(容量*电池数量) |
| | | holder.battery_storage_value_tv.setText(HdlCommonLogic.convertDoubleValue(houseIdBean.getBatteryCapacity(), UnitType.kWh)); |
| | | holder.battery_storage_kw_unit.setText(HdlCommonLogic.convertKWHUnit(houseIdBean.getBatteryCapacity())); |
| | | |
| | | holder.home_location_tv.setText(houseIdBean.getHomeAddress()); |
| | | holder.item_parent_rl.setTag(position); |
| | | setHomeStateTextViewStyle(holder.home_state_tv, houseIdBean.getPowerStationStatus()); |
| | | setHomeDebugStateTextViewStyle(holder.home_debug_state_tv, holder.home_debug_state_iv, houseIdBean.getDebugStatus()); |
| | | GlideUtils.getRoundedCornersImage(mContext, houseIdBean.getPowerStationImage(), holder.homeIconIv, 6); |
| | | holder.home_location_tv.setText(houseIdBean.getHomeAddress()); |
| | | holder.item_parent_rl.setTag(position); |
| | | setHomeStateTextViewStyle(holder.home_state_tv, houseIdBean.getPowerStationStatus()); |
| | | setHomeDebugStateTextViewStyle(holder.home_debug_state_tv, holder.home_debug_state_iv, houseIdBean.getDebugStatus()); |
| | | GlideUtils.getRoundedCornersImage(mContext, houseIdBean.getPowerStationImage(), holder.homeIconIv, 6); |
| | | // HdlLogLogic.print("---电站名称:" + houseIdBean.getHomeName() + "---图片url:" + houseIdBean.getPowerStationImage(), false); |
| | | holder.item_parent_rl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onClick((int) holder.item_parent_rl.getTag(), houseIdBean); |
| | | holder.item_parent_rl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onClick((int) holder.item_parent_rl.getTag(), houseIdBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | //移动电站位置 |
| | | holder.home_move_ll.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onMoveClick((int) holder.item_parent_rl.getTag(), houseIdBean); |
| | | }); |
| | | //移动电站位置 |
| | | holder.home_move_ll.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onMoveClick((int) holder.item_parent_rl.getTag(), houseIdBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | holder.home_del_ll.setVisibility(View.GONE); |
| | | if (houseIdBean.getDeliverStatus().equals(DeliverStatus.UNDELIVERED)) { |
| | | //未交付完要显示删除按钮 |
| | | holder.home_del_ll.setVisibility(View.VISIBLE); |
| | | } |
| | | }); |
| | | holder.home_del_ll.setVisibility(View.GONE); |
| | | |
| | | //删除电站 |
| | | holder.home_del_ll.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onDelClick((int) holder.item_parent_rl.getTag(), houseIdBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | if (houseIdBean.getDebugStatus().equals(DebugStatus.Debugging)) { |
| | | //未交付完要显示删除按钮 |
| | | holder.home_del_ll.setVisibility(View.VISIBLE); |
| | | holder.del_home_iv.setImageResource(R.drawable.del_home); |
| | | } |
| | | }); |
| | | if (houseIdBean.getDebugStatus().equals(DebugStatus.WAIT_DELIVERED)) { |
| | | //更改成回滚图标 |
| | | holder.home_del_ll.setVisibility(View.VISIBLE); |
| | | holder.del_home_iv.setImageResource(R.drawable.roll_back); |
| | | } |
| | | |
| | | //删除电站 |
| | | holder.home_del_ll.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onDelClick((int) holder.item_parent_rl.getTag(), houseIdBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | |
| | | if (UserConfigManage.getInstance().isTourist_mode()) { |
| | | holder.home_del_ll.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | public RelativeLayout item_parent_rl;//条目父容器 |
| | | public LinearLayout home_move_ll;//移动电站位置 |
| | | public LinearLayout home_del_ll;//删除电站 |
| | | public ImageView del_home_iv; |
| | | public TextView home_location_tv;//电站地址 |
| | | public SwipeLayout item_parent_swipeLayout;//父容器 |
| | | |
| | |
| | | item_parent_rl = itemView.findViewById(R.id.item_parent_rl); |
| | | home_move_ll = itemView.findViewById(R.id.move_ll); |
| | | home_del_ll = itemView.findViewById(R.id.del_ll); |
| | | del_home_iv = itemView.findViewById(R.id.del_home_iv); |
| | | home_location_tv = itemView.findViewById(R.id.home_location_tv); |
| | | item_parent_swipeLayout = itemView.findViewById(R.id.item_parent_swipeLayout); |
| | | } |
| | | |
| | | /** |
| | | * 设置文本 |
| | | */ |
| | | public void setText(int viewId, String text) { |
| | | TextView textView = getView(viewId); |
| | | if (textView != null) { |
| | | textView.setText(text); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置图片资源 |
| | | */ |
| | | public void setImageResource(int viewId, int resId) { |
| | | ImageView imageView = getView(viewId); |
| | | if (imageView != null) { |
| | | imageView.setImageResource(resId); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置文本颜色 |
| | | */ |
| | | public void setTextColor(int viewId, int color) { |
| | | TextView textView = getView(viewId); |
| | | if (textView != null) { |
| | | textView.setTextColor(color); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置点击事件 |
| | | */ |
| | | public void setOnClickListener(int viewId, View.OnClickListener listener) { |
| | | View view = getView(viewId); |
| | | if (view != null) { |
| | | view.setOnClickListener(listener); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取 View |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public <T extends View> T getView(int viewId) { |
| | | return (T) itemView.findViewById(viewId); |
| | | } |
| | | } |
| | | |
| | | public interface OnclickListener { |