wjc
2025-04-25 a17869744eeea710c9ee15eadb3837cd4ed0bcd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
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.LinearLayout;
import android.widget.RelativeLayout;
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.DebugStatus;
import com.hdl.photovoltaic.enums.DeliverStatus;
import com.hdl.photovoltaic.enums.PowerStationStatus;
import com.hdl.photovoltaic.enums.UnitType;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.utils.GlideUtils;
import com.hdl.photovoltaic.widget.SwipeLayout;
 
import java.util.ArrayList;
import java.util.List;
 
 
public class HouseInfoAdapter extends RecyclerView.Adapter<HouseInfoAdapter.MyViewHolder> {
 
    private List<HouseIdBean> mList;
    private final Context mContext;
    private OnclickListener noOnclickListener;//点击了的监听器
 
    String mPowerStationStatus;
 
    /**
     * 收集SwipeLayout数组,要一键全部打开;
     */
    private List<SwipeLayout> swipeLayoutList = new ArrayList<>();
 
    public HouseInfoAdapter(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_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());
 
        //组串容量(创建电站时输入的组串容量)
        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);
//        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);
                    }
                } 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);
                    }
                } 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.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) {
                }
            }
        });
 
    }
 
    @Override
    public int getItemCount() {
        return this.mList == null ? 0 : this.mList.size();
    }
 
 
    public void setList(List<HouseIdBean> newData, String powerStationStatus) {
        mPowerStationStatus = powerStationStatus;
        if (this.mList == null) {
            this.mList = new ArrayList<>();
        } else {
            this.mList.clear();
        }
 
        this.mList.addAll(newData);
        notifyDataSetChanged();
    }
 
 
    public void setNoOnclickListener(OnclickListener onclickListener) {
        this.noOnclickListener = onclickListener;
    }
 
    public List<SwipeLayout> getSwipeLayoutList() {
        if (this.swipeLayoutList == null) {
            this.swipeLayoutList = new ArrayList<>();
        }
        return this.swipeLayoutList;
    }
 
    /**
     * 设置【电站调试状态】组件样式
     *
     * @param textView   显示住宅状态文本组件
     * @param imageView  显示住宅状态图标组件
     * @param stateValue 电站状态(1:正常(运行),2:离线,3:连接中,4:故障,5:离线有故障)
     */
    private void setHomeDebugStateTextViewStyle(TextView textView, ImageView imageView, String stateValue) {
 
        String text = mContext.getString(R.string.be_debugging);
        Drawable drawable = AppCompatResources.getDrawable(mContext, R.drawable.debugging);
        switch (stateValue) {
            case DebugStatus.Debugging: {
                text = mContext.getString(R.string.be_debugging);
                drawable = AppCompatResources.getDrawable(mContext, R.drawable.debugging);
            }
            break;
 
            case DebugStatus.WAIT_DELIVERED: {
                text = mContext.getString(R.string.debugging_completed);
                drawable = AppCompatResources.getDrawable(mContext, R.drawable.done);
            }
            break;
            case DebugStatus.Delivered: {
                text = mContext.getString(R.string.delivered);
                drawable = AppCompatResources.getDrawable(mContext, R.drawable.delivered);
            }
            break;
            case DebugStatus.SECONDARY_DEBUGGIN: {
                text = mContext.getString(R.string.authorization_debugging);
                drawable = AppCompatResources.getDrawable(mContext, R.drawable.authorization_debugging);
            }
            break;
        }
        textView.setText(text);
        imageView.setBackground(drawable);
 
 
    }
 
    /**
     * 设置【电站状态】组件样式
     *
     * @param textView    显示组件
     *                    如果设备从来没上报过数据数据 状态:连接中
     *                    设备在线 但是当前处于故障 状态:故障
     *                    设备在线(有上报过数据,没有故障)  状态:在线
     *                    设备离线 状态:离线
     * @param state_value 电站状态(1:正常(运行),2:离线,3:连接中,4:故障,5:离线有故障)
     */
    private void setHomeStateTextViewStyle(TextView textView, int state_value) {
 
        String text = mContext.getString(R.string.my_power_station_operation);
        Drawable drawable = AppCompatResources.getDrawable(mContext, R.drawable.device_state_ff38c494);
        if (mPowerStationStatus.equals(PowerStationStatus.All)) {
            switch (state_value) {
                case 1: {
                    text = mContext.getString(R.string.my_power_station_operation);
                }
                break;
 
                case 2: {
                    text = mContext.getString(R.string.my_power_station_off_line);
                    drawable = AppCompatResources.getDrawable(mContext, R.drawable.device_state_ffb9b9b9);
                }
                break;
                case 3: {
                    text = mContext.getString(R.string.my_power_station_connecting);
                    drawable = AppCompatResources.getDrawable(mContext, R.drawable.device_satte_ffb300);
                }
                break;
                case 4:
                case 5: {
                    text = mContext.getString(R.string.my_power_station_malfunction);
                    drawable = AppCompatResources.getDrawable(mContext, R.drawable.device_state_fff55252);
                }
                //5:离线有故障Offline_fault
                break;
//            case 5: {
//                text = mContext.getString(R.string.Offline_fault);
//                drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_e34343);
//            }
//            break;
            }
        } else if (mPowerStationStatus.equals(PowerStationStatus.malfunction)) {
            text = mContext.getString(R.string.my_power_station_malfunction);
            drawable = AppCompatResources.getDrawable(mContext, R.drawable.device_state_fff55252);
        } else if (mPowerStationStatus.equals(PowerStationStatus.off)) {
            text = mContext.getString(R.string.my_power_station_off_line);
            drawable = AppCompatResources.getDrawable(mContext, R.drawable.device_state_ffb9b9b9);
        } else if (mPowerStationStatus.equals(PowerStationStatus.connecting)) {
            text = mContext.getString(R.string.my_power_station_connecting);
            drawable = AppCompatResources.getDrawable(mContext, R.drawable.device_satte_ffb300);
        }
//        textView.setText(text);
        textView.setBackground(drawable);
 
 
    }
 
    /**
     * 一行布局容器
     */
    static class MyViewHolder extends RecyclerView.ViewHolder {
 
        public ImageView homeIconIv;//住宅图片
        public TextView homeNameTv;//住宅名称
 
        public ImageView home_debug_state_iv;//住宅调试状态图标
        public TextView home_debug_state_tv;//住宅调试状态
 
        public TextView pv_value_tv;//组串容量
        public TextView pv_kw_unit;//发电功率单位
        public TextView generation_today_value_tv;//当日发电
        public TextView generation_today_kw_unit;//当日发电单位
        public TextView output_value_tv;//额定功率
        public TextView output_kw_unit;//额定功率单位
        public TextView battery_storage_value_tv;//电池能量
        public TextView battery_storage_kw_unit;//电池能量单位
        public TextView home_state_tv;//电站状态(连接中,运行,离线,故障);
        public RelativeLayout item_parent_rl;//条目父容器
        public LinearLayout home_move_ll;//移动电站位置
        public LinearLayout home_del_ll;//删除电站
        public TextView home_location_tv;//电站地址
        public SwipeLayout item_parent_swipeLayout;//父容器
 
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            homeIconIv = itemView.findViewById(R.id.home_image_iv);
            homeNameTv = itemView.findViewById(R.id.home_name_tv);
            home_debug_state_iv = itemView.findViewById(R.id.home_debug_state_iv);
            home_debug_state_tv = itemView.findViewById(R.id.home_debug_state_tv);
            pv_value_tv = itemView.findViewById(R.id.pv_value_tv);
            pv_kw_unit = itemView.findViewById(R.id.pv_kw_unit);
            generation_today_value_tv = itemView.findViewById(R.id.generation_today_value_tv);
            generation_today_kw_unit = itemView.findViewById(R.id.generation_today_kw_unit);
            output_value_tv = itemView.findViewById(R.id.output_value_tv);
            output_kw_unit = itemView.findViewById(R.id.output_kw_unit);
            battery_storage_value_tv = itemView.findViewById(R.id.battery_storage_value_tv);
            battery_storage_kw_unit = itemView.findViewById(R.id.battery_storage_kw_unit);
            home_state_tv = itemView.findViewById(R.id.home_state_tv);
            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);
            home_location_tv = itemView.findViewById(R.id.home_location_tv);
            item_parent_swipeLayout = itemView.findViewById(R.id.item_parent_swipeLayout);
        }
    }
 
    public interface OnclickListener {
        void onClick(int position, HouseIdBean houseIdBean);
 
        void onMoveClick(int position, HouseIdBean houseIdBean);
 
        void onDelClick(int position, HouseIdBean houseIdBean);
 
    }
 
}