New file |
| | |
| | | package com.hdl.photovoltaic.ui.adapter; |
| | | |
| | | import android.content.Context; |
| | | 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.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceBean; |
| | | import com.hdl.photovoltaic.widget.SwipeLayout; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class DeviceInfoAdapter extends RecyclerView.Adapter<DeviceInfoAdapter.MyViewHolder> { |
| | | |
| | | List<DeviceBean> mList; |
| | | |
| | | Context mContext; |
| | | |
| | | OnClickListener mOnclickListener; |
| | | |
| | | public DeviceInfoAdapter(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_device_details, parent, false); |
| | | return new MyViewHolder(contentItem); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { |
| | | DeviceBean deviceBean = this.mList.get(position); |
| | | holder.itemView.setTag(position); |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | try { |
| | | if (mOnclickListener != null) { |
| | | mOnclickListener.onClick((int) holder.itemView.getTag(), deviceBean); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int getItemCount() { |
| | | return this.mList == null ? 0 : this.mList.size(); |
| | | } |
| | | |
| | | public void setOnclickListener(OnClickListener onClickListener) { |
| | | this.mOnclickListener = onClickListener; |
| | | } |
| | | |
| | | public void setList(List<DeviceBean> newData) { |
| | | if (this.mList == null) { |
| | | this.mList = new ArrayList<>(); |
| | | } else { |
| | | this.mList.clear(); |
| | | } |
| | | |
| | | this.mList.addAll(newData); |
| | | notifyDataSetChanged(); |
| | | } |
| | | |
| | | /** |
| | | * 一行布局容器 |
| | | */ |
| | | static class MyViewHolder extends RecyclerView.ViewHolder { |
| | | |
| | | public ImageView homeIconIv;//住宅图片 |
| | | public TextView homeNameTv;//住宅名称 |
| | | 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.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, DeviceBean deviceBean); |
| | | |
| | | } |
| | | } |