From 162ca0f6633f3aa246a40e8ba3d3e9a54f3a4cb5 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期六, 11 五月 2024 14:45:21 +0800
Subject: [PATCH] 依赖1.0.21 sdk,解决数据乱的问题
---
app/src/main/java/com/hdl/photovoltaic/ui/adapter/HouseInfoAdapter.java | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 154 insertions(+), 12 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/adapter/HouseInfoAdapter.java b/app/src/main/java/com/hdl/photovoltaic/ui/adapter/HouseInfoAdapter.java
index 262e524..f8fa28e 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/adapter/HouseInfoAdapter.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/adapter/HouseInfoAdapter.java
@@ -1,26 +1,42 @@
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.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
+import androidx.appcompat.content.res.AppCompatResources;
import androidx.recyclerview.widget.RecyclerView;
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.hdl.photovoltaic.R;
-import com.hdl.photovoltaic.ui.bean.HouseListBean;
+import com.hdl.photovoltaic.other.HdlLogLogic;
+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<HouseListBean> mList;
+ private List<HouseIdBean> mList;
+ private final Context mContext;
private OnclickListener noOnclickListener;//鐐瑰嚮浜嗙殑鐩戝惉鍣�
- public HouseInfoAdapter(List<HouseListBean> list) {
- this.mList = list;
+ /**
+ * 鏀堕泦SwipeLayout鏁扮粍,瑕佷竴閿叏閮ㄦ墦寮�;
+ */
+ private List<SwipeLayout> swipeLayoutList = new ArrayList<>();
+
+ public HouseInfoAdapter(Context context) {
+
+ this.mContext = context;
}
@NonNull
@@ -32,13 +48,66 @@
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
- HouseListBean houseListBean = this.mList.get(position);
- holder.homeNameTv.setText(houseListBean.getHomeName());
- holder.itemView.setOnClickListener(new View.OnClickListener() {
+
+
+ HouseIdBean houseIdBean = this.mList.get(position);
+ holder.homeNameTv.setText(houseIdBean.getHomeName().trim());
+ //瑁呮満瀹归噺
+ String capacity = mContext.getString(R.string.my_power_station_installed_capacity) + houseIdBean.getInstalledCapacity() + "kW";
+ holder.capacityTv.setText(capacity);
+ String kw = "0";
+ try {
+ if (houseIdBean.getPower().contains(".")) {
+ int indexOf = houseIdBean.getPower().indexOf(".");
+ houseIdBean.setPower(houseIdBean.getPower().substring(0, indexOf));
+ }
+ int intValue = Integer.parseInt(houseIdBean.getPower());
+ int k = intValue / 1000;
+ int w = intValue % 1000;
+ kw = k + "." + w;
+ } catch (Exception ignored) {
+ kw = "0.0";
+ }
+ //鍙戠數鍔熺巼
+ String power = mContext.getString(R.string.power_station_generated_power) + kw + "kW";
+ holder.powerTv.setText(power);
+ holder.item_parent_rl.setTag(position);
+ setTextViewStyle(holder.stateTv, houseIdBean.getPowerStationStatus());
+ GlideUtils.getRoundedCornersImage(mContext, houseIdBean.getPowerStationImage(), holder.homeIconIv, new RoundedCorners(4), false);
+
+ HdlLogLogic.print("--->鐢电珯鍚嶇О:" + houseIdBean.getHomeName() + "--->鍥剧墖url:" + houseIdBean.getPowerStationImage(), false);
+ holder.item_parent_rl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (noOnclickListener != null) {
- noOnclickListener.onClick(holder.getAdapterPosition());
+ try {
+ if (noOnclickListener != null) {
+ noOnclickListener.onClick((int) holder.item_parent_rl.getTag(), houseIdBean);
+ }
+ } catch (Exception ignored) {
+ }
+ }
+ });
+ //绉诲姩鐢电珯浣嶇疆
+ holder.move_home_iv.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.del_home_iv.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) {
}
}
});
@@ -51,14 +120,73 @@
}
- public void setList(List<HouseListBean> list) {
- this.mList = list;
+ public void setList(List<HouseIdBean> newData) {
+ 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 state_value 鐢电珯鐘舵��(1:姝e父(杩愯),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_operation);
+
+ }
+ break;
+ case 2: {
+ text = mContext.getString(R.string.my_power_station_off_line);
+ drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_b9b9b9);
+ }
+ break;
+ case 3: {
+ text = mContext.getString(R.string.my_power_station_connecting);
+ drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_ffb300);
+ }
+ break;
+ case 4: {
+ text = mContext.getString(R.string.my_power_station_malfunction);
+ drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_e34343);
+ }
+ break;
+ }
+ textView.setText(text);
+ textView.setBackground(drawable);
+
+
+ }
+
+ /**
+ * 涓�琛屽竷灞�瀹瑰櫒
+ */
static class MyViewHolder extends RecyclerView.ViewHolder {
public ImageView homeIconIv;//浣忓畢鍥剧墖
@@ -66,6 +194,10 @@
public TextView capacityTv;//瑁呮満瀹归噺
public TextView powerTv;//鍙戠數鍔熺巼
public TextView stateTv;//鐢电珯鐘舵��(杩炴帴涓�,杩愯,绂荤嚎,鏁呴殰);
+ public RelativeLayout item_parent_rl;//鏉$洰鐖跺鍣�
+ public ImageView move_home_iv;//绉诲姩鐢电珯浣嶇疆
+ public ImageView del_home_iv;//鍒犻櫎鐢电珯
+ public SwipeLayout item_parent_swipeLayout;//鐖跺鍣�
public MyViewHolder(@NonNull View itemView) {
super(itemView);
@@ -74,10 +206,20 @@
capacityTv = itemView.findViewById(R.id.fragment_house_list_line_capacity_tv);
powerTv = itemView.findViewById(R.id.fragment_house_list_line_power_tv);
stateTv = itemView.findViewById(R.id.fragment_house_list_line_state_tv);
+ item_parent_rl = itemView.findViewById(R.id.item_parent_rl);
+ move_home_iv = itemView.findViewById(R.id.move_home_iv);
+ del_home_iv = itemView.findViewById(R.id.del_home_iv);
+ item_parent_swipeLayout = itemView.findViewById(R.id.item_parent_swipeLayout);
}
}
public interface OnclickListener {
- void onClick(int position);
+ void onClick(int position, HouseIdBean houseIdBean);
+
+ void onMoveClick(int position, HouseIdBean houseIdBean);
+
+ void onDelClick(int position, HouseIdBean houseIdBean);
+
}
+
}
--
Gitblit v1.8.0