| | |
| | | package com.hdl.photovoltaic.ui.adapter; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | 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 com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | 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<HouseIdBean> mList; |
| | | private final Context mContext; |
| | | private OnclickListener noOnclickListener;//点击了的监听器 |
| | | |
| | | /** |
| | | * 收集SwipeLayout数组,要一键全部打开; |
| | | */ |
| | | private List<SwipeLayout> swipeLayoutList = new ArrayList<>(); |
| | | |
| | | public HouseInfoAdapter(Context context) { |
| | | |
| | |
| | | @NonNull |
| | | @Override |
| | | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
| | | View contentItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.frgment_house_list_line, parent, false); |
| | | 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()); |
| | | //装机容量 |
| | | String capacity = mContext.getString(R.string.my_power_station_installed_capacity) + houseIdBean.getInstalledCapacity() + "kW"; |
| | | String capacity = mContext.getString(R.string.my_power_station_installed_capacity) + houseIdBean.getInstalledCapacity() + HdlDeviceLogic.kW; |
| | | holder.capacityTv.setText(capacity); |
| | | String kw = "0"; |
| | | try { |
| | |
| | | kw = "0.0"; |
| | | } |
| | | //发电功率 |
| | | String power = mContext.getString(R.string.power_station_generated_power) + kw + "kW"; |
| | | String power = mContext.getString(R.string.power_station_generated_power) + kw + HdlDeviceLogic.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)); |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | GlideUtils.getRoundedCornersImage(mContext, houseIdBean.getPowerStationImage(), holder.homeIconIv, new RoundedCorners(6), 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(), houseIdBean); |
| | | 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) { |
| | | } |
| | | } |
| | | }); |
| | |
| | | notifyDataSetChanged(); |
| | | } |
| | | |
| | | |
| | | public void setNoOnclickListener(OnclickListener onclickListener) { |
| | | this.noOnclickListener = onclickListener; |
| | | } |
| | | |
| | | public List<SwipeLayout> getSwipeLayoutList() { |
| | | if (this.swipeLayoutList == null) { |
| | | this.swipeLayoutList = new ArrayList<>(); |
| | | } |
| | | return this.swipeLayoutList; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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); |
| | | homeIconIv = itemView.findViewById(R.id.fragment_house_list_line_left_iv); |
| | | homeNameTv = itemView.findViewById(R.id.fragment_house_list_line_name_tv); |
| | | capacityTv = itemView.findViewById(R.id.fragment_house_list_line_capacity_tv); |
| | | powerTv = itemView.findViewById(R.id.fragment_house_list_line_power_tv); |
| | | homeIconIv = itemView.findViewById(R.id.device_details_image_iv); |
| | | homeNameTv = itemView.findViewById(R.id.device_details_name_tv); |
| | | capacityTv = itemView.findViewById(R.id.device_details_sn_tv); |
| | | powerTv = itemView.findViewById(R.id.power_type_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, HouseIdBean houseIdBean); |
| | | |
| | | void onMoveClick(int position, HouseIdBean houseIdBean); |
| | | |
| | | void onDelClick(int position, HouseIdBean houseIdBean); |
| | | |
| | | } |
| | | |
| | | } |