New file |
| | |
| | | package com.hdl.photovoltaic.ui.adapter; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.ImageView; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.enums.UnitType; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class DeviceInfoAdapter extends RecyclerView.Adapter<DeviceInfoAdapter.MyViewHolder> { |
| | | |
| | | List<CloudInverterDeviceBean> mList; |
| | | |
| | | Context mContext; |
| | | |
| | | OnClickListener mOnclickListener; |
| | | |
| | | public DeviceInfoAdapter(Context context) { |
| | | |
| | | this.mContext = context; |
| | | } |
| | | |
| | | @NonNull |
| | | @Override |
| | | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
| | | View contentItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_device_details, parent, false); |
| | | return new MyViewHolder(contentItem); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { |
| | | CloudInverterDeviceBean deviceBean = this.mList.get(position); |
| | | |
| | | holder.homeNameTv.setText(deviceBean.getHomeNameAndDeviceName()); |
| | | holder.device_details_sn_tv.setText("SN:"+deviceBean.getOsn()); |
| | | holder.device_label_run_state_value_tv.setText(deviceBean.getSystemStatusDesc()); |
| | | holder.device_label_power_value_tv.setText(HdlCommonLogic.getConvertDoubleUnit(deviceBean.getPowerPvNow(), UnitType.kW)); |
| | | holder.device_label_day_value_tv.setText(HdlCommonLogic.getConvertDoubleUnit(deviceBean.getPowerPvNow(), UnitType.kWh)); |
| | | holder.device_label_location_tv.setText(deviceBean.getHomeAddress()); |
| | | setTextViewStyle(holder.device_label_state_tv, deviceBean.getDeviceStatus()); |
| | | holder.itemView.setTag(position); |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (mOnclickListener != null) { |
| | | mOnclickListener.onClick((int) holder.itemView.getTag(), deviceBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int getItemCount() { |
| | | return this.mList == null ? 0 : this.mList.size(); |
| | | } |
| | | |
| | | public void setOnclickListener(OnClickListener onClickListener) { |
| | | this.mOnclickListener = onClickListener; |
| | | } |
| | | |
| | | public void setList(List<CloudInverterDeviceBean> newData) { |
| | | if (this.mList == null) { |
| | | this.mList = new ArrayList<>(); |
| | | } else { |
| | | this.mList.clear(); |
| | | } |
| | | |
| | | this.mList.addAll(newData); |
| | | notifyDataSetChanged(); |
| | | } |
| | | |
| | | /** |
| | | * 改变组件样式 |
| | | * |
| | | * @param textView 显示组件 |
| | | * @param state_value 设备状态(1:连接中,2:故障,3:正常(运行),4:离线) |
| | | */ |
| | | private void setTextViewStyle(TextView textView, int state_value) { |
| | | String text = mContext.getString(R.string.my_power_station_operation); |
| | | Drawable drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_06b92a); |
| | | switch (state_value) { |
| | | case 1: { |
| | | text = mContext.getString(R.string.my_power_station_connecting); |
| | | drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_ffb300); |
| | | } |
| | | break; |
| | | case 2: { |
| | | text = mContext.getString(R.string.my_power_station_malfunction); |
| | | drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_e34343); |
| | | } |
| | | break; |
| | | case 3: { |
| | | text = mContext.getString(R.string.my_power_station_operation); |
| | | } |
| | | break; |
| | | case 4: { |
| | | text = mContext.getString(R.string.my_power_station_off_line); |
| | | drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_b9b9b9); |
| | | } |
| | | break; |
| | | |
| | | |
| | | } |
| | | textView.setText(text); |
| | | textView.setBackground(drawable); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 一行布局容器 |
| | | */ |
| | | static class MyViewHolder extends RecyclerView.ViewHolder { |
| | | |
| | | public ImageView device_icon_iv;//设备图片 |
| | | public TextView homeNameTv;//住宅名称 |
| | | public TextView device_details_sn_tv;//mac |
| | | public TextView device_label_run_state_value_tv;//设备运行状态 |
| | | public TextView device_label_power_value_tv;//有功功率 |
| | | public TextView device_label_day_value_tv;//当日发电量 |
| | | public TextView device_label_location_tv;//电站地址 |
| | | public TextView device_label_state_tv;//设备状态(1:连接中,2:故障,3:正常(运行),4:离线) |
| | | |
| | | |
| | | public MyViewHolder(@NonNull View itemView) { |
| | | super(itemView); |
| | | device_icon_iv = itemView.findViewById(R.id.device_details_image_iv); |
| | | homeNameTv = itemView.findViewById(R.id.device_details_name_tv); |
| | | device_details_sn_tv = itemView.findViewById(R.id.device_details_sn_tv); |
| | | device_label_run_state_value_tv = itemView.findViewById(R.id.device_label_run_state_value_tv); |
| | | device_label_power_value_tv = itemView.findViewById(R.id.device_label_power_value_tv); |
| | | device_label_day_value_tv = itemView.findViewById(R.id.device_label_day_value_tv); |
| | | device_label_location_tv = itemView.findViewById(R.id.device_label_location_tv); |
| | | |
| | | device_label_state_tv = itemView.findViewById(R.id.device_label_state_tv); |
| | | |
| | | } |
| | | } |
| | | |
| | | public interface OnClickListener { |
| | | void onClick(int position, CloudInverterDeviceBean deviceBean); |
| | | |
| | | } |
| | | } |