| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 改变组件样式 |
| | | * |
| | | * @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 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;//电站状态(连接中,运行,离线,故障); |
| | | public TextView device_label_state_tv;//设备状态(1:连接中,2:故障,3:正常(运行),4:离线) |
| | | |
| | | |
| | | public MyViewHolder(@NonNull View itemView) { |