| | |
| | | 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.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.ui.bean.DeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class SearchDeviceAdapter extends RecyclerView.Adapter<SearchDeviceAdapter.MyViewHolder> { |
| | | List<DeviceBean> mList; |
| | | public class SearchDeviceAdapter extends RecyclerView.Adapter<SearchDeviceAdapter.MyViewHolder> { |
| | | List<CloudInverterDeviceBean> mList; |
| | | |
| | | Context mContext; |
| | | |
| | |
| | | @NonNull |
| | | @Override |
| | | public SearchDeviceAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
| | | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_house, parent, false); |
| | | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_device, parent, false); |
| | | return new MyViewHolder(view); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindViewHolder(@NonNull SearchDeviceAdapter.MyViewHolder holder, int position) { |
| | | DeviceBean deviceBean = this.mList.get(position); |
| | | CloudInverterDeviceBean deviceBean = this.mList.get(position); |
| | | |
| | | holder.power_station_name_tv.setText(deviceBean.getHomeName()); |
| | | holder.power_station_location_tv.setText(deviceBean.getAddress()); |
| | | holder.device_search_name_tv.setText(deviceBean.getHomeNameAndDeviceName()); |
| | | holder.device_search_sn_tv.setText("SN:"+deviceBean.getOsn()); |
| | | holder.device_search_location_tv.setText(deviceBean.getHomeAddress()); |
| | | setTextViewStyle(holder.device_search_state_tv, deviceBean.getDeviceStatus()); |
| | | holder.itemView.setTag(position); |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | this.mOnclickListener = onClickListener; |
| | | } |
| | | |
| | | public void setList(List<DeviceBean> newData) { |
| | | public void setList(List<CloudInverterDeviceBean> newData) { |
| | | if (this.mList == null) { |
| | | this.mList = new ArrayList<>(); |
| | | } else { |
| | |
| | | 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); |
| | | |
| | | |
| | | } |
| | | |
| | | public interface OnClickListener { |
| | | void onClick(int position, DeviceBean deviceBean); |
| | | void onClick(int position, CloudInverterDeviceBean deviceBean); |
| | | |
| | | } |
| | | |
| | |
| | | static class MyViewHolder extends RecyclerView.ViewHolder { |
| | | |
| | | |
| | | public TextView power_station_name_tv; |
| | | public TextView power_station_location_tv; |
| | | public TextView device_search_name_tv;//名称(电站_设备名称) |
| | | public TextView device_search_sn_tv;//mac |
| | | public TextView device_search_location_tv;//地址 |
| | | public TextView device_search_state_tv;//状态 |
| | | |
| | | |
| | | public MyViewHolder(@NonNull View itemView) { |
| | | super(itemView); |
| | | power_station_name_tv = itemView.findViewById(R.id.power_station_name_tv); |
| | | power_station_location_tv = itemView.findViewById(R.id.power_station_location_tv); |
| | | device_search_name_tv = itemView.findViewById(R.id.device_search_name_tv); |
| | | device_search_sn_tv = itemView.findViewById(R.id.device_search_sn_tv); |
| | | device_search_location_tv = itemView.findViewById(R.id.device_search_location_tv); |
| | | device_search_state_tv = itemView.findViewById(R.id.device_search_state_tv); |
| | | } |
| | | } |
| | | } |